1. Overview

In this tutorial, we’ll discuss the difference between the fdisk and parted commands. We use these commands to manipulate storage devices. The fdisk and parted commands perform the same function, but parted has more options. First, we’ll look at each command separately, and then later, we’ll discuss their differences.

2. The fdisk Command

fdisk is a menu-guided program for creating and manipulating partition tables. It understands MS-DOS-type partition tables and BSD- or SUN-type disk labels. Initially, fdisk wasn’t designed for large partitions because it couldn’t accept GUID partition tables. But, the recent version supports GPT, though using MBR (for drives less than 2TB) is recommended.

GPT support is currently new and, therefore, it’s deemed an experimental phase. Further, the latest versions of fdisk deprecated the use of cylinders as the default display unit and MS-DOS compatibility by default. fdisk has an interactive command-line menu that allows us to use letters to specify actions:

$ sudo fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
This disk is currently in use - repartitioning is probably a bad idea.
It's recommended to umount all file systems, and swapoff all swap
partitions on this disk.
Command (m for help): m
Help:
  GPT
   M   enter protective/hybrid MBR
  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

When using fdisk, the sectors must be specified in absolute terms using sector numbers. If we’re creating a sector, the size must be set in absolute terms to specify the beginning of that sector. For instance, using 80M as the first sector of a disk indicates that the sector is 80 MiB from the beginning of the disk.

When we’re using the absolute position in sector numbers or as positions, the measuring unit (its size) should be in kibibytes (K), mebibytes (M), gibibytes (G), and tebibytes (T). Also, it’s possible to express relative terms by preceding the size with either a +size or a -size. For example, a +1G indicates a point 1 GiB after the start sector, while a -100M indicates a point 100 MiB before the last available sector.

fdisk performs partition alignment automatically on the one-megabyte boundary if DOS compatibility mode has been disabled, making it compatible with various Advanced Format HDDs and SSDs. The default settings should give us accurate alignment.

3. The parted Command

parted is an alternative command to fdisk. It’s a utility we use to manipulate disk partitions and helps us to create space for new operating systems, reorganize disk usage, and copy data to new hard disks. parted comes with better functionality than fdisk, such as resizing (shrinking and extending partitions). In addition, it supports multiple partition table formats, including MS-DOS and GPT.

3.1. How to Use parted

We can install it by installing the parted package. It has two modes: command-line and interactive. The interactive mode makes partitioning simple as it reduces unnecessary repetition by automatically applying all partitioning commands to the selected device. If we’re using the interactive mode, the prompt changes from a dollar sign ($) to (parted):

$ sudo parted /dev/sda
Using /dev/sda
(parted) print
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 26.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  2097kB  1049kB                                     bios_grub
 2      2097kB  540MB   538MB   fat32        EFI System Partition  boot, esp
 3      540MB   26.8GB  26.3GB  ext4
(parted)

On the other hand, if we’re using the command-line mode, we run the parted command together with the right options. If the command is successful, it doesn’t throw an error and the cursor moves to a new line. We must specify the partition/drive we want to run the command on:

$ sudo parted /dev/sda print devices
/dev/sda (26.8GB)
$ sudo parted /dev/sda print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 26.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name                  Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  2097kB  1049kB                                     bios_grub
 2      2097kB  540MB   538MB   fat32        EFI System Partition  boot, esp
 3      540MB   26.8GB  26.3GB  ext4
 4      26.8GB  26.8GB  512B                 primary
        26.8GB  26.8GB  1031kB  Free Space

Let’s look at the syntax for creating a new partition:

$ sudo parted mkpart part-type name fs-type start end

The part-type refers to the primary, logical, or extended, and it’s only applicable if we use the MBR partition table. We replace the name option with a random partition name, and it’s mandatory for GPT partition tables. The fs-type parameter is optional. If we fill it, we replace it with fat16, fat32, xfs, ext2, ext3, ext4, Linux-swap, NTFS, or reiserfs.

To specify the beginning and end of a section, we replace the start and end options with the sizes that determine the starting and ending points of the partition, counting from the beginning of the disk. We can use express the sizes using size suffixes like MiB, GiB, or TiB. The default size is in megabytes. Also, if we don’t specify the size we want to partition, the default free space is used up.

Lastly, we must note that the parted command does not create the file system on the partition.

3.2. Creating a Partition Using parted

Let’s create a partition of size 512B:

$ sudo parted /dev/sda
Using /dev/sda
(parted) print free
Model: ATA VBOX HARDDISK (scsi)
Disk /dev/sda: 26.8GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number  Start   End     Size    File system  Name                  Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  2097kB  1049kB                                     bios_grub
 2      2097kB  540MB   538MB   fat32        EFI System Partition  boot, esp
 3      540MB   26.8GB  26.3GB  ext4
        26.8GB  26.8GB  1032kB  Free Space
(parted) mkpart primary ext4 26.8GB  26.8GB
(parted) quit
Information: You may need to update /etc/fstab.
$ sudo parted -l /dev/sda
Number  Start   End     Size    File system  Name                  Flags
 1      1049kB  2097kB  1049kB                                     bios_grub
 2      2097kB  540MB   538MB   fat32        EFI System Partition  boot, esp
 3      540MB   26.8GB  26.3GB  ext4
 4      26.8GB  26.8GB  512B                 primary

If the hard drive is larger than 2 TB, it’s recommended that we use parted to format it.

4. Differences Between fdisk and parted Commands

Now, let’s have a look at the significant differences between these commands:

fdisk

parted

When we run fdisk, the output is displayed using the partition type.

Uses the file system to display partitions available in a storage device.

Performs partition alignment automatically on the one-megabyte boundary, but MS-DOS compatibility mode has to be disabled.

When creating a partition, might warn about improper partition alignment but doesn’t alert when the alignment is proper, and it only aligns the partition start, not the size.

Doesn’t give us the option to shrink or extend the partition.

We can extend a partition to utilize the unused disk space or shrink a partition to use its capacity for other purposes.

Only has an interactive mode in which we use letters to specify actions.

Has both interactive and command-line modes. In both of these modes, we have to specify the right commands with the required options.

5. Conclusion

In this tutorial, we’ve looked at both fdisk and parted commands. We’ve mentioned the modes each of these commands has and the kind of file systems they can support. The interactive mode should be the most preferred when using parted as it simplifies the process of creating partitions.

fdisk supports automatic alignment only if DOS is turned off while parted only aligns the partition start. fdisk is present in most distros while parted is missing in some distributions and must be installed to be used. Lastly, we should be mindful when using either fdisk or parted as misuse can result in the loss of important data.