And if you’re new to Linux, you’ll also benefit from spending some time using Terminal to input commands “old school”.

What Is fdisk?

A widely-used command line tool, fdisk (short for “format disk” or “fixed disk”) enables you to create, delete, resize, change, copy and move partitions on any hard disk drive connected to a Linux PC. Data can also be moved to other disks, and up to four primary partitions can be created (depending on the size of the HDD).

You can get started using the fdisk command by opening up a Terminal window and typing

fdisk

The resulting usage instructions will give you an idea of how to use fdisk. To help you further, we’ve compiled the following list of examples of how you can use fdisk to manage hard disk drives on your Linux PC.

Find Your Disk

To get started, you’ll need to list the devices attached to your PC, and the partitions setup on them already. In Terminal, enter:

Disk-Specific fdisk Commands

Not all commands are available to all disks. To see which commands you will be able to use with the disk you’re managing, begin by selecting the disk:

fdisk /dev/sda

Linux will display a brief instruction to tap m for help, which will result in the following command actions being listed:

These are the actions that can be used with the selected disk.

Print Partition Table Details

After selecting your disk, you can print to screen a complete list of the partition table. This gives you information about the selected device or partition’s capacity, the size and number of disk sectors and cylinders, and the identifier.

Create & Delete Disk Partitions

As per the table of commands that you uncovered earlier, you should be able to simply create and delete partitions as required. Again, if you haven’t already, begin by selecting the device:

fdisk /dev/sda

To create a new partition, enter

n

then either e for and extended partition, or p for a primary partition.

After this, you’ll be prompted to indicate the first and final cylinders of the new partition. This can be confusing, especially if you’re not sure about how many cylinders are required; fortunately, you can also enter the size of the partition you want, such as +2000M for a 2000 MB (2 GB) partition. In some versions of Linux, defaults are displayed; tap Enter to accept these and save time.

Troubleshooting Partition Table Order

It’s not unheard of to find a “partition out of order” message after deleting one or more Linux disk partitions. This might happen on a system with four partitions, where number 3 is deleted. You might expect to be able to create a new number 3, but what actually happens is that number 4 is automatically renamed to 3, with the free space moved to the end.

This causes the error message ‘Partition table entries are not in disk order’.

To fix this, select the disk and input x to use extra functionality (see the list above).

fdisk /dev/sda

x

With this done, enter the f command to fix the partition table order.

f

Again, finish this off by entering w to write the updated table to disk and exit.

Format Your Linux HDD

With a new partition setup, you can quickly the format it with the mkfs command:

mkfs.ext4 /dev/sda4

This is broken down into command.filesystem /device/device name. You can number the device yourself, but it needs to be in numerical order – that is, don’t add sda4 if you don’t have an sda3.

Once you’ve done this, it is worth just checking the size of the partition. You can do this with the -s flag:

"such as the Disk Utility in Ubuntu"
One can also use GParted, either bundled with many distributions or standalone. The advantage of the standalone is that it can be used for Linux, BSD, Windows and Mac filesystems.