The fdisk command is used for hard-disk partitions on Linux. It’s one of the most incredible assets you can use to oversee allotments, yet it’s befuddling to new clients.
Step One – List Partitions
The sudo fdisk -l commands lists the partitions on your system:
# sudo fdisk -l
Step Two – View Specific Disk Partition in Linux
To view all partitions of specific hard disk use the option ‘-l‘ with device name. For example, the following command will display all disk partitions of device /dev/sda. If you’ve different device names, simple write device name as /dev/sdb or /dev/sdc.
Type ‘m‘ to see the list of all available commands of fdisk which can be operated on /dev/sda hard disk. After, I enter ‘m‘ on the screen, you will see the all available options for fdisk that you can be used on the /dev/sda device.
Step Three – Print the Partition Table
From the command mode, enter ‘p‘ instead of ‘m‘ as we did earlier. As I enter ‘p‘, it will print the specific /dev/sda partition table.
Step Four – Create New Partition
After entering in command mode, now press “n” command to create a new partition under /dev/sda with specific size. This can be demonstrated with the help of following given output.
While creating a new partition, it will ask you two options ‘extended‘ or ‘primary‘ partition creation. Press ‘e‘ for extended partition and ‘p‘ for primary partition. Then it will ask you to enter following two inputs.
- First cylinder number of the partition to be create.
- Last cylinder number of the partition to be created (Last cylinder, +cylinders or +size).
You can enter the size of cylinder by adding “+5000M” in last cylinder. Here, ‘+‘ means addition and 5000M means size of new partition (i.e 5000MB). Please keep in mind that after creating a new partition, you should run ‘w‘ command to alter and save new changes to partition table and finally reboot your system to verify newly created partition.
After the new partition is created, don’t skip to format the newly created partition using ‘mkfs‘ command. Type the following command in the terminal to format a partition. Here /dev/sda4 is my newly created partition.
# mkfs.ext4 /dev/sda4
All the Best!