Linux - fdisk - Partition table manipulator

> Operating System - Kernel (Windows, Unix, Linux) > Linux / Unix > Linux - Disk (storage devices)

1 - About

fdisk is a utility that creates and manipulates the partition tables.

fdisk doesn't understand GUID Partition Table (GPT) and it is not designed for large partitions. In particular case use more advanced GNU parted.

It understands DOS type partition tables and BSD or SUN type disklabels.

There are several fdisk programs around. Each has its problems and strengths. Try them in the order parted, fdisk, sfdisk.

Whenever a partition table is printed out, a consistency check is performed on the partition table entries. This check verifies that the physical and logical start and end points are identical, and that the partition starts and ends on a cylinder boundary (except for the first partition).

If possible, fdisk will obtain the disk geometry automatically. This is not necessarily the physical disk geometry (indeed, modern disks do not really have anything like a physical geometry, certainly not some- thing that can be described in simplistic Cylinders/Heads/Sectors form), but is the disk geometry that MS-DOS uses for the partition table.

Advertising

3 - Syntax

Changes you make to the partition table do not take effect until you issue the write (w) command.

fdisk is started by typing (as root) at the command prompt:

fdisk device
fdisk [-u] [-b sectorsize] [-C cyls] [-H heads] [-S sects] device
fdisk -l [-u] [device ...]
fdisk -s partition ...
fdisk -v

Options:

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

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

Advertising

3.1 - Version

With the -v otpion, Print version number of fdisk program and exit.

3.3 - List partition

With the -l option: 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.

[[email protected] ~]# fdisk -l

Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM

Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        2610    20964793+  83  Linux

3.4 - Help

fdisk /dev/sdb
Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

3.5 - Create partition

3.6 - Delete partition

  • d delete a partition

3.7 - Write the partition table

  • w write the new partition table and exit

3.8 - Quit

  • q quit without saving changes

3.9 - Flag

Advertising