fdisk command examples
Linux fdisk - Manipulating the Partition Table
The fdisk command is used to display or manipulate your partition tables on your Linux system. "fdisk" is a menu driven utility that is used to work with physical disks.
The basic syntax of the fdisk command is: fdisk [device]
fdisk accepts single keystrokes followed by pressing the "Enter" key. fdisk can also be used to quickly display your partition table outside of the interactive menu system.
root@john-desktop:~# fdisk -l Disk /dev/sda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders, total 312581808 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 Disk identifier: 0x000132a7 Device Boot Start End Blocks Id System /dev/sda1 * 2048 307357695 153677824 83 Linux /dev/sda2 307359742 312580095 2610177 5 Extended /dev/sda5 307359744 312580095 2610176 82 Linux swap / Solaris
To enter the interactive menu you have to issue: fdisk device
! ! WARNING: fdisk can delete partitions which can cause data loss and make your system not bootable ! !
! ! You should only use fdisk if you fully understand what you are doing.
fdisk Interactive Help Menu
root@john-desktop:~# fdisk /dev/sda 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) Command (m for help):
To access the above menu, I issued the command "fdisk /dev/sda". I then keyed in "m" for the help menu. Any commands that I use from this menu will work only with the device "/dev/sda". It is imperative you are sure that you have the correct device! When working with Primary and Extended partitions the choice number of 1 to 4 is offered. Logical partitions are only available when an Extended partition has been created. Logical partition numbers are from 5 to 16.
Commonly used options
Toggles the boot partition "on" or "off"
Delete a partition. You will be asked to specify the partition number that you require deleting.
List known partition 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 C: 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 eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext'd (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/ 10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b 11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor 12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor 14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary 16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS 17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE 18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux RAID auto 1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep 1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT 1e Hidden W95 FAT1 80 Old Minix
Interactive Help Menu.
New partition, Here you will be prompted for partition type - "Primary", "Extended" or "Logical"
See example of "n" option in use: Example of fdisk in use
Display Partition table. The partition information displayed is currently stored in memory. Any changes made are only reflected when they have been written using the "w" option.
Quit fdisk without making any changes.
Change partition System ID (type). This are the numbers that are displayed when using the "l" option.
Write any changes made to disk. Changes are only made when this option has been selected.
When you have made changes to your systems partition table. You may be required to force your system to re-read its partition table. This is often preferable to re-booting your system.
The basic syntax of the Linux partprobe command is: partprobe [-d] [-s] [devices....]
Don't update the kernel.
Display a summary of devices and their partitions.
Show summary of options.
Output from partprobe command
root@john-desktop:~# partprobe -s
/dev/sda: msdos partitions 1 2 <5>