Sfdisk

From Organic Design
Jump to: navigation, search

sfdisk is a command line utility to partition hard disks. Important because it can operate in a non-interactive way taking commands from STDIN. It can also produce output about the current state of the partitions on a device. With a little scripting it can be made to do the complex and confusing job of disk paritioning in preparation for installation of Peerix.

Examples

Here is an example of using sfdisk to examine the partitions on a physical disk.

root@turing:~/peerix# sfdisk -l /dev/hda

Disk /dev/hda: 77545 cylinders, 16 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Warning: The partition table looks like it was made
  for C/H/S=*/255/63 (instead of 77545/16/63).
For this listing I'll assume that geometry.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1   *      0+   4724    4725-  37953531   83  Linux
/dev/hda2       4725    4864     140    1124550    5  Extended
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
/dev/hda5       4725+   4864     140-   1124518+  82  Linux swap / Solaris

Here we are writing a new partion onto the disk. NOTE: I have used the -n switch which means "don't really do this, just go through the motions". The ; semicolon means "the whole thing", so we end up with one partition for the whole disk. This would be suitable for a Flash USB device where we want no unnecessary writes and we don't use a swap partition.

root@turing:~/peerix# sfdisk -n /dev/hda << EOF
> ;
> EOF

Disk /dev/hda: 77545 cylinders, 16 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Old situation:
Warning: The partition table looks like it was made
  for C/H/S=*/255/63 (instead of 77545/16/63).
For this listing I'll assume that geometry.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1   *      0+   4724    4725-  37953531   83  Linux
/dev/hda2       4725    4864     140    1124550    5  Extended
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
/dev/hda5       4725+   4864     140-   1124518+  82  Linux swap / Solaris
New situation:
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0

   Device Boot Start     End   #cyls    #blocks   Id  System
/dev/hda1          0+  77544   77545-  39082679+  83  Linux
/dev/hda2          0       -       0          0    0  Empty
/dev/hda3          0       -       0          0    0  Empty
/dev/hda4          0       -       0          0    0  Empty
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.