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

2
  • linux.die.net/man/8/sfdisk here's the man page, although I don't know how helpful it'll be, it's a start.
    – Rob
    Dec 5, 2011 at 18:11
  • I actually have that exact manpage open. I understand what sfdisk -q does, what I don't understand is the << EOF 0, EOF part. Dec 5, 2011 at 18:13

3 Answers 3

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.

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

4
  • So its just a quick way to partition the drive. Dec 5, 2011 at 19:00
  • Yeah, that's what it seems like. I'd use something I was more comfortable with if it was available.
    – Rob
    Dec 5, 2011 at 19:18
  • Yeah I agree, so according to what I listed that would create 1 partition that is the full size of the disk right? Because it shows me 4 partitions but only 1 was Linux and 3 were Empty. Dec 5, 2011 at 19:24
  • It will create one partition, starting at the beginning of the disk, and ending the start of the next partition.
    – Rob
    Dec 5, 2011 at 19:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .