fdisk is one of the most popular disk partition management utility on Linux, it can create, delete, change partition table of a disk. It supports up to 4 primary partitions and much large number of logical partitions within only one primary partition. Each partition has to be >=40MB.

It's very easy to use, but considering it's also dangerious to the data on the disk, here I show some examples:

List disk partition table

# fdisk -l /dev/sda

Disk /dev/sda: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005c3c7

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          26      207820+  fd  Linux raid autodetect
Partition 1 does not end on cylinder boundary.
/dev/sda2              26         217     1534207+  fd  Linux raid autodetect
Partition 2 does not end on cylinder boundary.
/dev/sda3             217         478     2096482+  fd  Linux raid autodetect
Partition 3 does not end on cylinder boundary.
/dev/sda4             478      243201  1949672498   fd  Linux raid autodetect

If you don't specify the device with option '-l', fdisk will display all disk partitions on all the disks

List disk and partition table size

# fdisk -s /dev/sda
1953514584

# fdisk -s /dev/sda[1-9]
/dev/sda1: 207820
/dev/sda2: 1534207
/dev/sda3: 2096482
/dev/sda4: 1949672498

The example above show disk and its partitions in kb, but fdisk manual says '-s' option reports disk size in blocks. Indeed the disk is 2TB disk. I have no idea about this.

In any case fdisk can only manage up to 2000GB disk, to manage disks larger than 2TB, use GNU parted to manage them.

Get into interactive interface and print help

# fdisk /dev/sdar

WARNING: GPT (GUID Partition Table) detected on '/dev/sdar'! The util fdisk doesn't support GPT. Use GNU Parted.


WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help):

Delete an existing partition

You probably already noticed, in previous example, it reported a warning, says the disk partition was GPT, not supported by fdisk. Anyway, we delete it

Command (m for help): print
...
    Device Boot      Start         End      Blocks   Id  System
/dev/sdar1               1      242252  1953514583+  ee  GPT

Command (m for help): d 1
Selected partition 1

Command (m for help): p
...

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): w
The partition table has been altered!

Note: Don't forget write the changes back to partition table if you want keep the change.

Create a disk partition

Command (m for help): p

Disk /dev/sdar: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x08042224

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4) p
Partition number (1-4): 1
First sector (63-3907029167, default 63):
Using default value 63
Last sector, +sectors or +size{K,M,G} (63-3907029167, default 3907029167): +200G

Command (m for help): p

Disk /dev/sdar: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x08042224

    Device Boot      Start         End      Blocks   Id  System
/dev/sdar1              63   419430463   209715200+  83  Linux

Create one or more logical partitions

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4) e
Partition number (1-4): 2
First sector (419430464-3907029167, default 419430464):
Using default value 419430464
Last sector, +sectors or +size{K,M,G} (419430464-3907029167, default 3907029167): +100G

Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4) l
First sector (419430527-629145664, default 419430527):
Using default value 419430527
Last sector, +sectors or +size{K,M,G} (419430527-629145664, default 629145664): +10G

Command (m for help): p

Disk /dev/sdar: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x08042224

    Device Boot      Start         End      Blocks   Id  System
/dev/sdar1              63   419430463   209715200+  83  Linux
/dev/sdar2       419430464   629145664   104857600+   5  Extended
/dev/sdar5       419430527   440402047    10485760+  83  Linux

Now you see the logical partition 5 was created in the partition 2. Note: only one primary partition can be subdivided.

Replicate disk partition to another disk ?

Use sfdisk for fdisk created disk partition, see the other article Copy disk partition to another disk

For more block devices commands, see blkid, lsblk, parted.