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
- Partition management
- Disk organization
- System setup
- Storage planning
- 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
View partitions:
fdisk -l
Change type:
fdisk /dev/sdb t # type 83 # Linux w # write
Expert mode:
fdisk -x /dev/sdb
Security Considerations
- Root access required
- Data loss risk
- System integrity
- Backup importance
- Boot safety
Additional Resources
Best Practices
- Backup first
- Verify changes
- Check alignment
- Plan layout
- Document changes
Partition Types
- Linux (83)
- Swap (82)
- Extended (5)
- NTFS (7)
- LVM (8e)
Troubleshooting
- Table errors
- Boot problems
- Alignment issues
- Type conflicts
- Size limits