fdisk Command Examples in Linux

The fdisk utility is a menu-driven program that is used to create, modify, or delete partitions on a storage drive. Using fdisk, you can create a new partition table or modify existing entries on the partition table. The fdisk utility understands the DOS and Linux type partition tables. The fdisk utility also enables you to specify the size of partitions.

Syntax

The syntax of the fdisk utility is:

# fdisk [options] {device name}

fdisk Command Options

The fdisk utility supports a number of command-line options.

Option Used To
-b {sector size} Specify the number of drive sectors.
-H {heads} Specify the number of drive heads.
-S {sectors} Specify the number of sectors per track.
-s {partition} Print the partition size in blocks.
-l List partition tables for devices.

fdisk menu options

Aside from supplying command-line options, you can also choose various options when you are working in the fdisk menu.

Option Used To
n Create a new partition.
d Remove a partition.
p List existing partitions.
w Write changes to drive and exit utility.
q Cancel changes made and exit utility.

Using fdisk to list a storage device’s partitions.

fdisk Command Examples

1. To set the sector size of a disk:

# fdisk -b 1024 /dev/sdd
(sector size = 512, 1024, 2048 or 4096) 

2. To specify the number of cylinders of the disk:

# fdisk -C 1024 /dev/sdb 

3. To Specify the number of heads of the disk:

# fdisk -H 1024 /dev/sdb 

4. To Specify the number of sectors per track of the disk:

# fdisk -S sects /dev/sdb 

5. To list the partition tables for the specified devices and then exit:

# fdisk -l
# fdisk -l /dev/sdb 

6. To get the size of a particular disk:

# fdisk -s /dev/sdb 

7. To switch off DOS-compatible mode:

# fdisk -c  

8. To get the help for fdisk:

# fdisk -h 

9. To get the version of the fdisk:

# fdisk -v
Related Post