How to create disk partitions in Linux

by time news

2023-06-29 08:30:16

In order to use storage devices like hard drives and USB drives on your computer effectively, you need to understand them and know how to structure them before using them on Linux. In most cases, large storage devices are divided into separate parts called partitions.

Partitioning allows you to divide your hard drive into multiple parts, where each part acts as its own hard drive, and this is useful when you are installing multiple operating systems on the same machine.

In this article, we will explain how to partition a storage disk on Linux systems like the distributions CentOS, RHEL, Fedora, Debian y Ubuntu.

Create a disk partition in Linux

In this section, we will explain how to partition a storage disk in Linux using the parted command.

The first step is to view the partition table or layout on all block devices. This helps you identify the storage device you want to partition. You can do this using the command parted or fdisk. We will use the first one for demonstration purposes, as follows, where “-l” means the partition layout list of all block devices.

# parted -l

List partitions in Linux

From the output of the above command, there are two hard drives attached to the test system, the first is “/dev/sda” and the second is “/dev/sdb”.

In this case, we want to partition the hard drive “/dev/sdb”. To manipulate disk partitions, open the hard drive to start working on it, as shown.

# parted /dev/sdb

at the gauge partitioncreate a partition table by running mklabel msdos o gptthen enter “Y/es” to accept it.

(parted) mklabel msdos

make disc label

Important : Make sure you specify the correct device for the partition in the command. If you run the parted command without a partition device name, it will randomly choose a storage device to modify.

Next, create a new primary partition on the hard drive and print the partition table as shown.

(parted) mkpart primary ext4 0 10024MB
(parted) print

Create partition in Linux

You can create another partition for the reaming space as shown.

(parted) mkpart primary ext4 10.0GB 17.24GB
(parted) print

Create another partition

To exit, issue the command quit and all changes will be saved automatically.

Then create the file system type on each partition, you can use the mkfs utility (replace ext4 with the type of file system you want to use).

# mkfs.ext4 /dev/sdb1
# mkfs.ext4 /dev/sdb2

Create file system type on partition

Last but not least, to access the storage space on the partitions, you need to mount them by creating the mount points and mount the partitions as follows.

# mkdir -p /mnt/sdb1
# mkdir -p /mnt/sdb2
# mount -t auto /dev/sdb1 /mnt/sdb1
# mount -t auto /dev/sdb2 /mnt/sdb2

To check if the partitions are actually mounted, run the df command to report the disk space usage of the file system.

# df -hT

Check disk space usage of partitions

Important : You may need to update the “/etc/fstab” file to mount the newly created partitions automatically at boot time.

That’s all! In this article, we have shown how to partition a storage disk, create a file system type on a partition, and mount it on Linux systems. You can ask questions or share your thoughts with us via the comment form below.

#create #disk #partitions #Linux

You may also like

Leave a Comment