How to use Fdisk to manage partitions in Linux [Tip]

fdiskFdisk is a text facility which is used to view and manage the hard disk partition on Linux. It can be the most powerful tool for the which can be used for managing the hard disk partitions, but it is also confusing to the new users.

On some of the distributions of the Linux, there is a need of using a word sudo as prefix before the commands fdisk and mkfs, and those distributions which do not require using this word as a prefix are required to use the word “su” to get to the root shell, then you must type every other command without sudo.

List partitions:

To list the partitions, write…

sudo fdisk –l

You can also add the name of the disk devices name to list only partitions on it. For instance to list only the partitions  on the first disk device, you have to write:

sudo fdisk –l  /dev/sda

Entering command mode:

If you want to work on the partition of the disk, you just need to enter the command mode. You can get the name of the device from the fdisk –l command. If you want to enter the first disk device, following command is used.

sudo fdisk   /dev/sda

There is a warning that does not edit partitions when they are in use. If you desire to edit them boot it from the live CD first.

Using command mode:

In this mode, in this mode you just need to single letter to specify your command and tell the system what to do. Just type m and then press to see the list of the commands

Deleting the partition:

If there is a need to delete the partition use the button ‘d’. the screen will prompt you asking the number of partitions you want to delete, which you have got from the ‘p’ command.

After deleting the desired partition, type the command ‘p’ again if you want to view the current partition. At this type it appears that the partitions are deleted but these partitions are not written on the disk until you press the ‘w’ button.

Creating partition:

In order to create the new partition use the button ‘n’. you have the option to create the logical or primary partition. ‘l’ for the logical and ‘P‘ for the primary partition. A disk can only have 4 primary partitions. The next thing to do is to specify the sector of the partition which you want to start portioning at. To choose the default sector press Enter key.

The last thing to do is to specify the last sector of the partition. After selecting the initial sector if you want to select all available space, press Enter. You have the option that you can also specify the size +6G for the partition of 5 Gigabytes and +512M for the partition of 512 megabytes. If you will not specify the unit after pressing +, fdisk will utilize sectors as the unit.

Related Posts