Linux fdisk command
Quick links
About fdisk
Syntax
Examples
Related commands
Linux and Unix main page
Partition table manipulator for Linux.
fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects]
device
fdisk -l [-u] [device ...]
fdisk -s partition ...
fdisk -v
| -b sectorsize | Specify the sector size of the disk.
Valid values are 512, 1024, or 2048. (Recent kernels know the sector
size. Use this only on old kernels or to override the kernelâs ideas.) |
| -C cyls | Specify the number of cylinders of the disk. I have no idea why anybody would want to do so. |
| -H heads | Specify the number of heads of the disk. (Not the physical number, of course, but the number used for partition tables.) Reasonable values are 255 and 16. |
| -S sects | Specify the number of sectors per track of the disk. (Not the physical number, of course, but the number used for partition tables.) A reasonable value is 63. |
| -l | List the partition tables for the specified devices and then exit. If no devices are given, those mentioned in /proc/partitions (if that exists) are used. |
| -u | When listing partition tables, give sizes in sectors instead of cylinders. |
| -s partition | The size of the partition (in blocks) is printed on the standard output. |
| -v | Print version number of fdisk program and exit. |
Tip: You most have root access for this command to work.
fdisk -l
List the partition information of the computer you're logged into. Below is an example of what this output may look like.
Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63
sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280
bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 191
1534176 83 Linux
/dev/sda2 192 2231 16386300 83 Linux
/dev/sda3 2232
3506 10241437+ 83 Linux
/dev/sda4 3507 30401 216034087+ 5 Extended
/dev/sda5
3507 3767 2096451 82 Linux swap / Solaris
/dev/sda6 3768 3832 522081 83
Linux
/dev/sda7 3833 30401 213415461 83 Linux
Disk /dev/sdb: 250.0
GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start
End Blocks Id System
/dev/sdb1 * 1 30401 244196001 83 Linux
Caution: The DOS
6.x FORMAT command looks for some information in the first sector of the
data area of the partition, and treats this information as more reliable
than the information in
the partition table. DOS FORMAT expects DOS FDISK
to clear the first 512 bytes of the data area of a partition whenever a size
change occurs. DOS FORMAT will look at this extra
information even if the
/U flag is given -- we consider this a bug in DOS FORMAT and DOS FDISK.
The bottom line is that if you use fdisk to change the size of a DOS
partition table entry, then you must also use dd to zero the first 512 bytes
of that partition before using
DOS FORMAT to format the partition. For
example, if you were using disk to make a DOS partition table entry for /dev/sda1,
then (after exiting fdisk and rebooting Linux so that
the partition table
information is valid) you would use the command "dd if=/dev/zero of=/dev/sda1
bs=512 count=1" to zero the first 512 bytes of the partition.
BE EXTREMELY CAREFUL if you use the dd command, since a small typo can make all of the data on your disk useless.
For best results, you should always
use an OS-specific partition table program. For example, you should make DOS
partitions with the DOS FDISK program and Linux partitions with
the Linux
fdisk program.
