Sfdisk

From LQWiki
Jump to navigation Jump to search

sfdisk is a non-GUI program to display and manipulate partitions in an MBR partition table on a hard drive. Since version 2.26, it also supports GPT Partitions, SUN Partitions and SGI Partitions.

Examples

List sizes

 sudo sfdisk -s <partition>

will list the size of the partition in blocks. If no partition is named, all hard drives will be listed.

 sudo sfdisk -s /dev/sda1
 1024
 

List partitions

 sudo sfdisk -l <device>

will list all partitions on the device, including missing ("empty") primary partitions.

 sudo sfdisk -l /dev/sdj
 
 Disk /dev/sdj: 243197 cylinders, 255 heads, 63 sectors/track
 Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0
 
    Device Boot Start     End   #cyls    #blocks   Id  System
 /dev/sdj1          0+ 243197- 243198- 1953480704    7  HPFS/NTFS/exFAT
 /dev/sdj2          0       -       0          0    0  Empty
 /dev/sdj3          0       -       0          0    0  Empty
 /dev/sdj4          0       -       0          0    0  Empty

(note that the misalignment of Id and System columns above will happen on large drives)

Check Partitions

 sudo sfdisk -V <device>

will perform checks on the partition table entries (not on the filesystems within those partitions).

Create Partitions

 sudo sfdisk <device>

will read specification for a new partition from standard input. This is intended for use in a shell script.

Other Uses

There are enough other options for this command that the standard manual page lists ¨too many options" as a bug.

Provided by

Most (all?) Linux distributions incorporate this from the [util-linux] project.

See also

This article is a stub and needs to be finished. Plunge forward and help it grow!