Linux fdisk Command Tutorial

Linux provides the fdisk command in order to manage disks, partitions, and file systems. The fdisk command is created for Unix and Linux systems but also ported into different operating systems like DOS, IBM OS/2, Windows *BSD, etc. In this tutorial, we examine the fdisk usage in Linux distribution to create partitions, set sector sizes, list partitions, wipe partitions, etc.

fdisk Command Syntax

The fdisk command syntax is like below where the disk or partition is provided as the last parameter. Before the disk or partition name options are provided.

fdisk OPTIONS DISK
  • OPTIONS is used to set single or more options.
  • DISK is the disk or partition which will be used by fdisk.

fdisk Help

The fdisk command provides different options and features. These options can be listed in a short form line by line by using the -h option like below.

$ fdisk -h
fdisk Help

Alternatively, the manual page or long help information can be listed by using the man command like below.

$ man fdisk

List Partitions

Partitions of a disk can be listed by using the -l option. This lists all partitions with the following information about partitions.

  • Device lists the device name of the partition.
  • Start is the start sector of the partition.
  • End is the end sector of the partition.
  • Sectors is the count of the sectors in this partition.
  • Size is the human readable size for the partition.
  • Type is the partition type.
$ sudo fdisk -l /dev/sda
List Partitions

List Partitions with Details

The fdisk command can also be used to list technical details of the partitions. The -x option is used to list partition details which are like below.

  • Disk is the disk device path and size.
  • Disk model is the disk manufacturer with model information.
  • Disklabel type is the disk labeling type.
  • Device is the device name.
  • Start is the start sector number.
  • End is the end sector number.
  • Sectors are total sector count.
  • Type-UUID is the partition type ID.
  • UUID is the UUID of the partition which is unique for this partition.
  • Name is the partition name.
  • Attrs is the partition attribute.
$ sudo fdisk -x /dev/sda
List Partitions with Details

Create Partition Table

The interactive interface of the fdisk command is used to create a new partition. First we open the disk where we want to create a partition like below.

$ sudo fdisk /dev/sdb

The n command is used to create new partition .

n

The new partition type is asked where we select primary with the p.

p

The partition number is asked as the first partition we use the default value 1.

1

The first sector number is asked and we use the default start sector number pressing enter.

2048

The last sector number is asked which can be provided as sector number or partition size like +5G for 5Gigabyte size.

+5G

In order to make changes sync with the disk and make them permanent the write command w is used.

w
Create Partition Table

List Partitions Interactively

Partitions can be listed in the fdisk interactive screen. The print operation can be run with the p command like below. The output is the same -l option.

p

Make Partition Bootable

By default partitions are not bootable which means the installed operating systems can be booted unless the partition is made bootable. The fdisk command can be used to make a partition bootable via the interactive menu. The a command is used to make the specified partition bootable. First, we list existing partitions with the p command.

p

Then we use a command

Make Partition Bootable

Leave a Comment