27

I was looking over documentation for ZFS for Linux and I came accross a command that the instructions tell me to run to prepare a disk for use.

The command was;

sfdisk -q /dev/zvol/tank/fish << EOF
0,
EOF

The line breaks are included the command took up 3 lines

What does sfdisk do? Is it the same and creating a new partition table or is it something different?

Here is the documentation I was looking at, Link

3 Answers3

16

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.

8

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.

Rio
  • 91
4

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).

Rob
  • 2,422