What does sfdisk do, and how does it compare to fdisk or parted?

Solution 1:

sfdisk reads and writes partition tables, but is not interactive like fdisk or cfdisk (it reads input from a file or stdin). It's generally used for partitioning drives from scripts or for partition table backup and recovery. Since it's command driven instead of menu driven, I can see the attraction for using it in documentation like this, since you can easily document the input.

Solution 2:

sfdisk is nice for software raid. When replacing a disk, simply:

sfdisk -d /dev/sda | sfdisk /dev/sdb

and you've cloned the partition table from sda to sdb.

now just add back to mdadm and good to go.

Solution 3:

sfdisk reads lines of the form

<start> <size> <id> <bootable> <c,h,s> <c,h,s>

where each line fills one partition descriptor.

... When a field is absent or empty, a default value is used.

So this sets up a new partition, starting at 0 and ending at the default of size.

The default value of size is as much as possible (until next partition or end-of-disk).