partition maintenance program

fdisk [options] device

fdisk -l [device…]

Interactive program for creation and manipulation of partition tables. It understands GPT, MBR, Sun, SGI and BSD partition tables.noninteractive version

Block devices (Disks, RAM drive) can be divided into one or more logical disks called partitions, recorded in the partition table, usually found in sector 0 of the disk and duplicated elsewhere. (Aka `disk slices' and a `disklabel'.)

First, last, sectors and sizes specified by the +size{M,G,...} notation are aligned according to the device properties.

   m   print this menu,        
   i  information about a partition   

Command (m for help): i
Partition number (1-3, default 3): 3

         Device: /dev/mmcblk0p3
          Start: 31117312
            End: 62333951
        Sectors: 31216640
      Cylinders: 487761
           Size: 14.9G
             Id: 83
           Type: Linux
    Start-C/H/S: 832/0/1
      End-C/H/S: 143/3/16
   p  print
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc5b4c492

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1          8192    93236    85045 41.5M  c W95 FAT32 (LBA)
/dev/mmcblk0p2         94208 31116287 31022080 14.8G 83 Linux
/dev/mmcblk0p3      31117312 62333951 31216640 14.9G 83 Linux

v  verify  
Remaining 1995 unallocated 512-byte sectors.

   F  list free space,   
Unpartitioned space /dev/mmcblk0: 3 MiB, 3145728 bytes, 6144 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

Start   End Sectors Size
 2048  8191    6144   3M

   n   add new,   t  change type,   d  delete 
   l  list known types 

   u   change display/entry units 

   w  write table to disk and exit      q  quit without saving changes

   Create a new label: g GPT, G SGI (IRIX) , o DOS , s  Sun 

   O   output sfdisk script, I input script 
  DOS (MBR Master BOot Record):
   a  toggle a bootable flag,  b  edit nested BSD disklabel,  c toggle the dos compatibility flag

 x  extra functionality (experts only)
  DOS (MBR) b   move beginning of data in a partition, i   change the disk identifier 
   d   print the raw data of the first sector from the device
   D   print the raw data of the disklabel from the device
   f   fix partitions order
   c   change number of cylinders,      h   change number of heads,   s  change number of sectors/track bad ideas

Don't erase the begining of the first sector when creatiing a new disk label. (for GPT and MBR.)
Default nondos. mode cannot be separated from -c by a space, the correct short form is -c=dos.
Display a help text and exit.
--color [auto|never|always]
Colorize the output.
List the partition tables then exit. , Default devices from /proc/partitions
sudo fdisk -l /dev/mmcblk0
Disk /dev/mmcblk0: 29.7 GiB, 31914983424 bytes, 62333952 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xc5b4c492

Device         Boot    Start      End  Sectors  Size Id Type
/dev/mmcblk0p1          8192    93236    85045 41.5M  c W95 FAT32 (LBA)
/dev/mmcblk0p2         94208 31116287 31022080 14.8G 83 Linux
/dev/mmcblk0p3      31117312 62333951 31216640 14.9G 83 Linux
See partx for various output formats.
--output list
output columns to display. --help shows supported columns. The default list of columns may be extended if list is specified in the format +list (e.g. -o +UUID).
size in 512-byte sectors . DEPRECATED in favour of blockdev(1).
--type type
Enable support only for disklabels of the specified type,
show sizes in 'sectors' or in 'cylinders'. default is sectors. unit cannot be separated from -u by a space, example -u=cylinders.
--cylinders n
Specify the number of cylinders of the disk.
--heads n
Not the physical number, the number used for partition tables.)
--sectors n
Specify the number of sectors per track of the disk. (Not the physical number, but the number used for partition tables.) A reasonable value is 63.
--wipe when
Wipe filesystem, RAID and partition-table signatures from the device, in order to avoid possible collisions. The argument when can be auto, never or always.
When this option is not given, the default is auto, in which case signatures are wiped only when in interactive mode. In all cases detected signatures are reported by warning messages before a new partition table is created. See wipefs(8.
--wipe-partition when
Wipe filesystem, RAID and partition-table signatures from a newly created partitions, in order to avoid possible collisions. The argument when can be auto, never or always. When this option is not given, the default is auto, in which case signatures are wiped only when in interactive mode and after confirmation by user. In all cases detected signatures are reported by warning messages before a new partition is created. See also wipefs(8) command.
--sector-size bytes
Specify the sector size of the disk. Valid values are 512, 1024, 2048, and 4096. fdisk differentiates between logical and physical sector size. This option changes both sector sizes to sectorsize.
Display version information and exit.
fdisk from util-linux 2.29.2
fdisk -h

 fdisk [options]       change partition table
 fdisk [options] -l [] list partition table(s)

Display or manipulate a disk partition table.

 -b, --sector-size       physical and logical sector size
 -B, --protect-boot            don't erase bootbits when creating a new label
 -c, --compatibility[=]  mode is 'dos' or 'nondos' (default)
 -L, --color[=]          colorize output (auto, always or never)
                                 colors are enabled by default
 -l, --list                    display partitions and exit
 -o, --output            output columns
 -t, --type              recognize specified partition table type only
 -u, --units[=]          display units: 'cylinders' or 'sectors' (default)
 -s, --getsz                   display device size in 512-byte sectors [DEPRECATED]
     --bytes                   print SIZE in bytes rather than in human readable format
 -w, --wipe              wipe signatures (auto, always or never)
 -W, --wipe-partitions   wipe signatures from new partitions (auto, always or never)

 -C, --cylinders       specify the number of cylinders
 -H, --heads           specify the number of heads
 -S, --sectors         specify the number of sectors per track

 -h, --help     display this help and exit
 -V, --version  output version information and exit

Available columns (for -o):
 gpt: Device Start End Sectors Size Type Type-UUID Attrs Name UUID
 dos: Device Start End Sectors Cylinders Size Type Id Attrs Boot End-C/H/S Start-C/H/S
 bsd: Slice Start End Sectors Cylinders Size Type Bsize Cpg Fsize
 sgi: Device Start End Sectors Cylinders Size Type Id Attrs
 sun: Device Start End Sectors Cylinders Size Type Id Flags

For more details see fdisk(8).

Mac os

usage: fdisk [-ieu] [-f mbrboot] [-c cyl -h head -s sect] [-S size] [-r] [-a style] disk -i: initialize disk with new MBR -u: update MBR code, preserve partition table -e: edit MBRs on disk interactively -f: specify non-standard MBR template -chs: specify disk geometry -S: specify disk size -r: read partition specs from stdin (implies -i) -a: auto-partition with the given style -d: dump partition table -y: don't ask any questions -t: test if disk is partitioned `disk' is of the form /dev/rdisk0. auto-partition styles: boothfs 8Mb boot plus HFS+ root partition (default) hfs Entire disk as one HFS+ partition dos Entire disk as one DOS partition raid Entire disk as one 0xAC partition


The device is usually /dev/sda, /dev/sdb or so. A device name refers to the entire disk. Old systems without libata (a library used inside the Linux kernel to support ATA host controllers and devices) make a difference between IDE and SCSI disks. In such cases the device name will be /dev/hd* (IDE) or /dev/sd* (SCSI).

The partition is a device name followed by a partition number. For example, /dev/sda1 is the first partition on the first hard disk in the system. See also Linux kernel documentation (the Documentation/devices.txt file). SIZES The "last sector" dialog accepts partition size specified by number of sectors or by +{K,B,M,G,...} notation. If the size is prefixed by '+' then it is interpreted as relative to the partition first sector. In this case the size is expected in bytes and the number may be followed by the multiplicative suffixes KiB=1024, MiB=1024*1024, and so on for GiB, TiB, PiB, EiB, ZiB and YiB. The "iB" is optional, e.g. "K" has the same meaning as "KiB". The relative sizes are always aligned according to device I/O limits. The +{K,B,M,G,...} notation is recommended. For backward compatibility fdisk also accepts the suffixes KB=1000, MB=1000*1000, and so on for GB, TB, PB, EB, ZB and YB. These 10^N suffixes are deprecated.


fdisk allows to read (by 'I' command) sfdisk compatible script files. The script is applied to in-memory partition table, and then it is possible to modify the partition table before you write it to the device. And vice-versa it is possible to write the current in-memory disk layout to the script file by command 'O'. The script files are compatible between cfdisk, sfdisk, fdisk and another libfdisk applications. For more details see sfdisk(8).


DOS mode and DOS 6.x WARNING

Note that all this is deprecated. You don't have to care about things like geometry and cylinders on modern operating systems. If you really want DOS-compatible partitioning then you have to enable DOS mode and cylinder units by using the '-c=dos -u=cylinders' fdisk com- mand-line options. 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 or cfdisk to change the size of a DOS partition table entry, then you must also use dd(1) to zero the first 512 bytes of that partition before using DOS FORMAT to format the partition. For example, if you were using fdisk 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. fdisk usually obtains 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 something that can be described in the simplistic Cylinders/Heads/Sectors form), but it is the disk geometry that MS-DOS uses for the partition table. Usually all goes well by default, and there are no problems if Linux is the only system on the disk. However, if the disk has to be shared with other operating systems, it is often a good idea to let an fdisk from another operating system make at least one partition. When Linux boots it looks at the partition table, and tries to deduce what (fake) geometry is required for good cooperation with other systems. Whenever a partition table is printed out in DOS mode, a consistency check is performed on the partition table entries. This check veri- fies that the physical and logical start and end points are identical, and that each partition starts and ends on a cylinder boundary (except for the first partition). Some versions of MS-DOS create a first partition which does not begin on a cylinder boundary, but on sector 2 of the first cylinder. Partitions beginning in cylinder 1 cannot begin on a cylinder boundary, but this is unlikely to cause difficulty unless you have OS/2 on your machine. 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 or Linux cfdisk programs.


Implicit coloring can be disabled by an empty file /etc/terminal-colors.d/fdisk.disable.
See terminal-colors.d(5) for more details about colorization configuration. The logical color names supported by fdisk are: header The header of the output tables. help-title The help section titles. warn The warning messages. welcome The welcome message.


FDISK_DEBUG=all enables fdisk debug output.
LIBFDISK_DEBUG=all enables libfdisk debug output.
LIBBLKID_DEBUG=all enables libblkid debug output.
LIBSMARTCOLS_DEBUG=all enables libsmartcols debug output.
LIBSMARTCOLS_DEBUG_PADDING=on use visible padding characters. Requires enabled LIBSMARTCOLS_DEBUG.
SEE ALSO cfdisk(8), mkfs(8), partx(8), sfdisk(8)

fdisk [-afiuvBFS] [-0 | -1 | -2 | -3]
[-t disktab] [-T disktype] [-E number] [-b cylinders|heads|sectors]
[-s id/start/size[/bootmenu]] [-c bootcode] [-r|w file] [device]

fdisk -l

Used to divide space on a disk into partitions and set one active. There can be at most 4 partitions defined in sector 0, one of which can be an extended partition which can be split into any number of sub-partitions.

NetBSD does not use the partitioning done by fdisk, instead it uses a NetBSD disklabel saved in sector 1 of the NetBSD partition.

The standard MBR boot code will only boot the `active' partition. NetBSD contains two alternate boot programs which allow the user to select which partition to boot. The `mbr_ext' code will boot NetBSD from an extended partition but will not work on old systems that do not support LBA reads.

At the start fdisk determines if the sector 0 is valid as a boot sector. If not, it initialises the boot code as well as the partition table, all four partitions will be marked empty.

The flags -a, -i or -u are used to indicate that the partition data is to be updated. The fdisk program will enter an interactive conversational mode. This mode is designed not to change any data unless you explicitly tell it to; fdisk selects defaults for its questions to guarantee that behaviour.

fdisk will calculate the correct cylinder, head, and sector values for any partition you edit. If you specify -v you will be asked whether you want to specify them

When all the data for the first sector has been accumulated, fdisk will ask if you really want to write the new partition table. Only if you reply affirmatively to this question will fdisk write anything to the disk.

-0 Update partition slot 0.
-1 Update partition slot 1.
-2 Update partition slot 2.
-3 Update partition slot 3.
-a Change the active partition. In interactive mode this question will be asked after the partitions have been processed.

-b cylinders/heads/sectors Specify the BIOS parameters for cylinders, heads, and sectors. It is used only in conjunction with the -u flag.

-B On an i386 or amd64 system, interactively update the boot selec- tor settings. (The boot selector permits the user to interac- tively select the boot partition, and thus which operating system is run, at system boot time. See mbr(8) for more information.)

-c bootcode Specify the filename that fdisk should read the bootcode from. If the name of a directory is specified, then fdisk will look for files with the default names in that directory. The default is to read from /usr/mdec/mbr, /usr/mdec/mbr_bootsel or /usr/mdec/mbr_ext depending on whether bootmenu was specified for any partitions on an i386 machine, and leave the bootcode empty for other machines.

-E number Update extended partition number. If the specified extended par- tition doesn't exist an additional extended partition will be created.

-f Run fdisk in a non-interactive mode. In this mode, you can only change the disk parameters by using the -b flag. This is pro- vided only so scripts or other programs may use fdisk as part of an automatic installation process. Using the -f flag with -u makes it impossible to specify the starting and ending cylinder, head, and sector fields. They will be automatically computed using the BIOS geometry. If -u and -s are specified then the details of the specified par- tition will be changed. Any other partitions which overlap the requested part of the disk will be silently deleted.

-F Indicate that device is a regular file. Unless the geometry of device is told to fdisk by -T disktype, fdisk will count the 512-byte sectors in device and produce a fake geometry.

-i Explicitly request initialisation of the master boot code (simi- lar to what fdisk /mbr does under MS-DOS), even if the magic num- ber in the first sector is ok. The partition table is left alone by this (but see above).

-l Lists known sysid values and exit.

-r file Read the boot record from file file instead of the specified disk. The geometry information used is still that of the disk volume. Any changes are written back to the file.

-s id/start/size[/bootmenu] Specify the partition id, start, size, and optionally bootmenu. This flag requires the use of a partition selection flag (-0, -1, -2, -3, or -E number)

-S When used with no other flags print a series of /bin/sh commands for setting variables to the partition information. This could be used by installation scripts.
-tong> disktab Read disktype from the named disktab(5) file instead of from /etc/disktab.

-T disktype Use the disklabel disktype instead of the disklabel on device.

-u Display the partitions and interactively ask which one you want to edit. fdisk will step through each field showing the old value and asking for a new one. The start and size can be speci- fied in blocks (nn), cylinders (nnc), megabytes (nnm), or giga- bytes (nng), values in megabytes and gigabytes will be rounded to the nearest cylinder boundary. The size may be specified as $ in which case the partition will extend to the end of the available free space.

fdisk will not allow you to create partitions which overlap.

If bootmenu is specified for any partition fdisk will determine whether the installed boot code supports the bootselect code, if it doesn't you will be asked whether you want to install the required boot code.

-v Be more verbose, specifying -v more than once may increase the amount of output.

Using -v with -u allows the user to change more parameters than normally permitted.

-w file Write the modified partition table to file file instead of the disk.

When called with no arguments, it outputs the partition table. An example
 Disk: /dev/rwd0d
         NetBSD disklabel disk geometry:
         cylinders: 16383, heads: 16, sectors/track: 63 (1008 sectors/cylinder)
         total sectors: 40032696

         BIOS disk geometry:
         cylinders: 1023, heads: 255, sectors/track: 63 (16065 sectors/cylinder)
         total sectors: 40032696

         Partition table:
         0: NetBSD (sysid 169)
             bootmenu: net 1.5.
             start 4209030, size 8289540 (4048 MB, Cyls 262-778), Active
         1: Primary DOS with 32 bit FAT (sysid 11)
             bootmenu: win98
             start 63, size 4208967 (2055 MB, Cyls 0-262)
         2: NetBSD (sysid 169)
             bootmenu: current
             start 32515560, size 7517136 (3670 MB, Cyls 2024-2491/234/40)
         3: Ext. partition - LBA (sysid 15)
             start 12498570, size 20016990 (9774 MB, Cyls 778-2024)
         Extended partition table:
         E0: NetBSD (sysid 169)
             bootmenu: test
             start 12498633, size 12305727 (6009 MB, Cyls 778-1544)
         E1: Primary DOS with 32 bit FAT (sysid 11)
             start 24804423, size 4096512 (2000 MB, Cyls 1544-1799)
         E2: Primary DOS with 32 bit FAT (sysid 11)
             start 28900998, size 3614562 (1765 MB, Cyls 1799-2024)
         Bootselector enabled, infinite timeout.
This example disk is divided into four partitions the last of which is an extended partition. The sub-partitions of the extended partition are also shown. In this case there is no free space in either the disk or in the extended partition.

The various fields in each partition entry are: ptn_number: id_name (sysid id_number) bootmenu: bootmenu start start, size size (MB MB, Cyls first-next) [, Active]

ptn_number is the number of the partition. id_name is the name of the filesystem type or operating system that uses this partition.

id_number is the number that identifies the partition type. 169 decimal is used for NetBSD partitions, 15 decimal to create an extended partition and 0 to mark a partition as unused. Use fdisk -l to list the known partition types.

bootmenu is the menu prompt output by the interactive boot code for this partition. This line is omitted if the prompt is not defined.

start, size are the start address and size of the partition in sectors.

MB is the size of the partition in megabytes.

first, next are the bounds of this partition displayed as cylin- der/head/sector. If the partition starts (or ends) on a cylin- der boundary the head and sector values are omitted. If -v is not specified the start of extended partitions and the first partition on the disk are rounded down to include the mandatory red tape in the preceding track.

Active is output if this is the active partition.

If the -v flag is given two additional lines are output for each parti- tion: beg: cylinder cylinder, head head, sector sector end: cylinder cylinder, head head, sector sector cylinder, head, sector are the beginning or ending address of a partition.

Note: these numbers are read from the bootblock, so are the values calculated by a previous run of fdisk.

NOTES This program is only available (and useful) on systems with PC-platform- style MBR partitioning. On NetBSD this includes the following ports: amd64, arc, bebox, cobalt, hpcarm, hpcmips, hpcsh, i386, macppc, mvmeppc, netwinder, ofppc, playstation2, and prep.

Traditionally the partition boundaries should be on cylinder boundaries using the BIOS geometry, all of the first track should be reserved for use by the BIOS. Although the BIOS geometry is typically different from the geometry reported by the drive, neither will match the actual physi- cal geometry for modern disks (the actual geometry will vary across the disk). Keeping the partition boundaries on cylinder boundaries makes partitioning a driver easier as only relatively small numbers need be entered.

The automatic calculation of the starting cylinder and other parameters uses a set of figures that represent what the BIOS thinks is the geometry of the drive. The default values should be correct for the system on which fdisk is run, however if you move the disk to a different system the BIOS of that system might use a different geometry translation.

If you run the equivalent of fdisk on a different operating system then the bootmenu strings associated with extended partitions may be lost.

Editing an existing partition is risky, and may cause you to lose all the data in that partition.

You should run this program interactively once or twice to see how it works. This is completely safe as long as you answer the last question in the negative. You can also specify -w file to write the output to a file and later specify -r file to read back the updated information.
This can be done without having write access to the disk volume.


/usr/mdec/mbr Default location of i386 bootcode
/usr/mdec/mbr_bootsel Default location of i386 bootselect code
/usr/mdec/mbr_ext Default location of i386 bootselect for extended partitions


disktab(5), disklabel(8), mbr(8), mbrlabel(8)

WARNING The word `partition' is used to mean both an MBR partition and a NetBSD partition, sometimes in the same sentence.

There are subtleties that the program detects that are not explained in this manual page.

NetBSD 3.0

from daemon-systems.org/man/fdisk.8.html