fdisk

Overview

The fdisk command manipulates disk partition tables. It’s used to view, create, delete, change, and copy partitions on storage devices.

Syntax

fdisk [options] device

Common Options

Option Description
-l List partitions
-b sectorsize Sector size
-u Display units
-v Version info
-c Compatibility mode
-w Write table
-s partition Size in blocks
-t type Specify type
-h Help
-x Expert mode

Interactive Commands

Command Description
m Help menu
p Print table
n New partition
d Delete partition
t Change type
v Verify table
w Write changes
q Quit without saving
l List types
x Expert mode

Key Use Cases

  1. Partition management
  2. Disk organization
  3. System setup
  4. Storage planning
  5. Data management

Examples with Explanations

Example 1: List Partitions

fdisk -l /dev/sda

Show partition table

Example 2: Create Partition

fdisk /dev/sdb
n    # new partition
p    # primary partition
1    # partition number
     # default first sector
+10G # size
w    # write changes

Example 3: Delete Partition

fdisk /dev/sdb
d    # delete partition
1    # partition number
w    # write changes

Common Usage Patterns

  1. View partitions:

    fdisk -l
  2. Change type:

    fdisk /dev/sdb
    t    # type
    83   # Linux
    w    # write
  3. Expert mode:

    fdisk -x /dev/sdb

Security Considerations

  1. Root access required
  2. Data loss risk
  3. System integrity
  4. Backup importance
  5. Boot safety

Additional Resources

Best Practices

  1. Backup first
  2. Verify changes
  3. Check alignment
  4. Plan layout
  5. Document changes

Partition Types

  1. Linux (83)
  2. Swap (82)
  3. Extended (5)
  4. NTFS (7)
  5. LVM (8e)

Troubleshooting

  1. Table errors
  2. Boot problems
  3. Alignment issues
  4. Type conflicts
  5. Size limits