Registered: Jun 2004
cfdisk is a curses-based disk partition table manipulator.cfdisk tries to read the current partition table from the disk drive. It is functionally identical to fdisk, but with a graphical user interface (GUI).Unless you are a system adminstrator,better stick with cfdisk.And I haven't heard of cfdisk producing erreneous partition tables.
sfdisk has four (main) uses: list the size of a partition, list the partitions on a device, check the partitions on a device, and repartition a device.
sfdisk -s partition gives the size of partition in blocks. This may be useful in connection with programs like mkswap or so. Here partition is usually something like /dev/hda1 or /dev/sdb12, but may also be an entire disk, like /dev/xda.
% sfdisk -s /dev/hda9
If the partition argument is omitted, sfdisk will list the sizes of all disks, and the total:
% sfdisk -s
total: 12901917 blocks
The second type of invocation: sfdisk -l [options] device will list the partitions on this device. If the device argument is omitted, the partitions on all hard disks are listed.
% sfdisk -l /dev/hdc
Disk /dev/hdc: 16 heads, 63 sectors, 2045 cylinders
Units = cylinders of 516096 bytes, blocks of 1024 bytes, counting from 0
Device Boot Start End #cyls #blocks Id System
/dev/hdc1 0+ 406 407- 205096+ 83 Linux native
/dev/hdc2 407 813 407 205128 83 Linux native
/dev/hdc3 814 2044 1231 620424 83 Linux native
/dev/hdc4 0 - 0 0 0 Empty
The trailing - and + signs indicate that rounding has taken place, and that the actual value is slightly less (more). To see the exact values, ask for a listing with sectors as unit.
The third type of invocation: sfdisk -V device will apply various consistency checks to the partition tables on device. It prints `OK' or complains. The -V option can be used together with -l. In a shell script one might use sfdisk -V -q device which only returns a status.
The fourth type of invocation: sfdisk device will cause sfdisk to read the specification for the desired partitioning of device from its standard input, and then to change the partition tables on that disk. Thus, it is possible to use sfdisk from a shell script. When sfdisk determines that its standard input is a terminal, it will be conversational; otherwise it will abort on any error.
As a precaution, one can save the sectors changed by sfdisk:
% sfdisk /dev/hdd -O hdd-partition-sectors.save
Then, if you discover that you did something stupid before anything else has been written to disk, it may be possible to recover the old situation with
% sfdisk /dev/hdd -I hdd-partition-sectors.save
(This is not the same as saving the old partition table: a readable version of the old partition table can be saved using the -d option. However, if you create logical partitions, the sectors describing them are located somewhere on disk, possibly on sectors that were not part of the partition table before. Thus, the information the -O option saves is not a binary version of the output of -d.)
There are many options.
-v or --version
Print version number of sfdisk and exit immediately.
-? or --help
Print a usage message and exit immediately.
-T or --list-types
Print the recognized types (system Id's).
-s or --show-size
List the size of a partition.
-g or --show-geometry
List the kernel's idea of the geometry of the indicated disk(s).
-l or --list
List the partitions of a device.
Dump the partitions of a device in a format useful as input to sfdisk. For example,
% sfdisk -d /dev/hda > hda.out
% sfdisk /dev/hda < hda.out
will correct the bad last extended partition that the OS/2 fdisk creates.
-V or --verify
Test whether partitions seem correct. (See above.)
-i or --increment
Number cylinders etc. starting from 1 instead of 0.
Change only the single partition indicated. For example:
% sfdisk /dev/hdb -N5
will make the fifth partition on /dev/hdb bootable (`active') and change nothing else. (Probably this fifth partition is called /dev/hdb5, but you are free to call it something else, like `/my_equipment/disks/2/5' or so).
Make the indicated partition(s) active, and all others inactive.
-c or --id number [Id]
If no Id argument given: print the partition Id of the indicated partition. If an Id argument is present: change the type (Id) of the indicated partition to the given value. This option has the two very long forms --print-id and --change-id. For example:
% sfdisk --print-id /dev/hdb 5
% sfdisk --change-id /dev/hdb 5 83
first reports that /dev/hdb5 has Id 6, and then changes that into 83.
-uS or -uB or -uC or -uM
Accept or report in units of sectors (blocks, cylinders, megabytes, respectively). The default is cylinders, at least when the geometry is known.
-x or --show-extended
Also list non-primary extended partitions on output, and expect descriptors for them on input.
Specify the number of cylinders, possibly overriding what the kernel thinks.
Specify the number of heads, possibly overriding what the kernel thinks.
Specify the number of sectors, possibly overriding what the kernel thinks.
-f or --force
Do what I say, even if it is stupid.
-q or --quiet
Suppress warning messages.
-L or --Linux
Do not complain about things irrelevant for Linux.
-D or --DOS
For DOS-compatibility: waste a little space. (More precisely: if a partition cannot contain sector 0, e.g. because that is the MBR of the device, or contains the partition table of an extended partition, then sfdisk would make it start the next sector. However, when this option is given it skips to the start of the next track, wasting for example 33 sectors (in case of 34 sectors/track), just like certain versions of DOS do.) Certain Disk Managers and boot loaders (such as OSBS, but not LILO or the OS/2 Boot Manager) also live in this empty space, so maybe you want this option if you use one.
-E or --DOS-extended
Take the starting sector numbers of "inner" extended partitions to be relative to the starting cylinder boundary of the outer one, (like some versions of DOS do) rather than to the starting sector (like Linux does). (The fact that there is a difference here means that one should always let extended partitions start at cylinder boundaries if DOS and Linux should interpret the partition table in the same way. Of course one can only know where cylinder boundaries are when one knows what geometry DOS will use for this disk.)
--IBM or --leave-last
Certain IBM diagnostic programs assume that they can use the last cylinder on a disk for disk-testing purposes. If you think you might ever run such programs, use this option to tell sfdisk that it should not allocate the last cylinder. Sometimes the last cylinder contains a bad sector table.
Go through all the motions, but do not actually write to disk.
Only execute the BLKRRPART ioctl (to make the kernel re-read the partition table). This can be useful for checking in advance that the final BLKRRPART will be successful, and also when you changed the partition table `by hand' (e.g., using dd from a backup). If the kernel complains (`device busy for revalidation (usage = 2)') then something still uses the device, and you still have to unmount some file system, or say swapoff to some swap partition.
When starting a repartitioning of a disk, sfdisk checks that this disk is not mounted, or in use as a swap device, and refuses to continue if it is. This option suppresses the test. (On the other hand, the -f option would force sfdisk to continue even when this test fails.)
Just before writing the new partition, output the sectors that are going to be overwritten to file (where hopefully file resides on another disk, or on a floppy).
After destroying your filesystems with an unfortunate sfdisk command, you would have been able to restore the old situation if only you had preserved it using the -O flag.
Again,if you're not very experienced in partitioning hard disks,stick with cfdisk.