The Linux Newbie Guide  ⇒    Fundamentals     Advanced     Supplement   Command Index   ENG⇒中
All rights reserved, please indicate the source when citing
  

Partitioning with fdisk


fdisk is a traditional disk partitioning tool, but it's quite old and can only support MBR partition tables. MBR-partitioned disks cannot exceed 2TB in size. Therefore, it's recommended to use another disk partitioning tool called parted, which supports GPT partitioning for disks larger than 2TB. Furthermore, parted also supports advanced formatting disk. fdisk operates in command mode and interactive mode. For partitioning (creating partitions), you can only use the interactive mode. The command mode only displays disk information. Most Linux distributions require superuser privileges to operate fdisk.

Example:
# fdisk -l ←List disk information
Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes

# fdisk /dev/sda ←Partition the disk "/dev/sda" (enters interactive mode, press <m> if you're unsure about available commands)

Example: (Operations after entering fdisk and pressing <m>)
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 ←Write partition and exit
x   extra functionality (experts only)

In the example above, any changes made, such as deleting or adding partitions, are only performed in RAM. Even if a mistake is made, it won't affect the disk data. You can always press <q> to exit if you're unsure, which won't endanger the disk. Changes are only written to the disk when you press <w>. Therefore, before pressing <w>, it's advisable to press <p> to print the planned partitions to confirm.

For more advanced interactive mode and usage of fdisk, please refer to the provided link.