fdisk [options] device
fdisk -l [device …] Interactive program for creation and manipulation of 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 can be specified by the +size{M,G,…} notation
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 Seems to be randomly generated so each disk is unique
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
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 84 OS/2 hidden or c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx
5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data
6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility
8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt
9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi ea Rufus alignment
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD eb BeOS fs
f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ee GPT
10 OPUS 55 EZ-Drive a7 NeXTSTEP ef EFI (FAT-12/16/
11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f0 Linux/PA-RISC b
12 Compaq diagnost 5c Priam Edisk a9 NetBSD f1 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f4 SpeedStor
16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ f2 DOS secondary
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fb VMware VMFS
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fc VMware VMKCORE
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fd Linux raid auto
1c Hidden W95 FAT3 75 PC/IX bc Acronis FAT32 L fe LANstep
1e Hidden W95 FAT1 80 Old Minix be Solaris boot ff BBT
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 (Randomly generated)
d display raw data of the first sector
D display raw data of the disklabel
f fix partitions order
c change number of cylinders, h change number of heads, s change number of sectors/track bad ideas
-B |
Mac osWith no arguments displays partition table and exits.Example with Rasbperry Pi SD card: > sudo fdisk /dev/disk2
Disk: /dev/disk2 geometry: 966/255/63 [15523840 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: 0C 64 0 1 - 1023 3 32 [ 8192 - 524288] Win95 FAT32L
2: 83 1023 3 32 - 1023 3 32 [ 532480 - 7790592] Linux files*
3: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
No Disk identifier: is displayed!
sudo /usr/sbin/fdisk -d /dev/disk2 1,63037439,0xEE,-,1023,254,63,1023,254,63 0,0,0x00,-,0,0,0,0,0,0 0,0,0x00,-,0,0,0,0,0,0 0,0,0x00,-,0,0,0,0,0,0 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
|
fdisk: 1> help
manual Show entire man page for fdisk
reinit Re-initialize loaded MBR (to defaults)
auto
quit saving current changes
|
sudo fdisk -e /dev/disk2 # Attempt to examine SD card for Raspberry Pi fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
device example /dev/sda. refers to the entire disk.
partition is a device name followed by a partition number. For example, /dev/sda1 is the first partition on the first hard disk
size
The "last sector" accepts size specified by number of sectors or by +size{K,B,M,G,…} notation.
If the size is prefixed by '+' it is interpreted as relative to the partition first sector in
bytes, unless . followed by the suffixes K==KB==KiB=1024, M==MB==MiB=1024*1024,…
fdisk can read (by I command) sfdisk scripts
which are applied to in-memory partition table allowing modifification before write it using command O.
GPT (GUID Partition Table) the modern standard for the layout of the partition table.
The first sector is reserved for a protective MBR.
GPT is always a better choice than MBR, especially on modern hardware with a UEFI boot loader.
MBR
A DOS-type partition table. There are 4 primary partitions. One may be an extended partition; this is a container holding logical partitions. The four primary partitions are numbered 1-4. Logical partitions always start with 5.
$FDISK_DEBUG=all |
SEE ALSO: cfdisk, mkfs, partx, sfdisk
fdisk: /dev/disk6: No such file or directory
fdisk -l
if sector 0 is not valid a boot sector. fdisk 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.
Calculates the correct cylinder, head, and sector values for
partitions 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 selector settings. (The boot selector permits the user to interactively 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 partition 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 provided 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 partition 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 (similar to what fdisk /mbr does under MS-DOS), even if the magic number 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.
Requires the use of a partition selection flag (-0, -1,
-2, -3, or -E number)
|
-S | When used alone output /bin/sh commands
for setting variables to the partition information. This could
be used by installation scripts.
|
-t disktab |
Read disktype from the named disktab(5) file instead of from
/etc/disktab.
|
-T disktype |
Use the disktype instead of the disklabel on device.
|
-u | Display the partitions and interactively ask which one
to edit. fdisk will step through each field showing the old
value and asking for a new one. The start and size can be specified 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.
If |
-v | Be more verbose, specifying -v more than once may increase the amount of output.
Using
|
-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.
15 to 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 cylinder/head/sector. If the partition starts (or ends) on a cylinder 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.
With -v two additional lines are output for each partition:
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.
these numbers are read from the bootblock, so are the values calculated by a previous run of fdisk.
Specify -w file to write the output to a
file and later specify -r file to read back .
This can be done without having write access to the disk volume.
`partition' is used to mean both an MBR partition and a NetBSD partition, sometimes in the same sentence.
from daemon-systems.org/man/fdisk.8.html