sfdisk
Partition disks and create partition tables in Linux
Syntax
sfdisk [options] device
Basic Usage
List partition information
sfdisk -l /dev/sda
Shows all partitions on the specified disk.
List all disks
sfdisk -l
Shows partitions on all available disks.
Create partition table interactively
sfdisk /dev/sda
Create partitions from specification file
sfdisk /dev/sda < partition_spec.txt
Common Options
-l, --list: List partition tables-d, --dump: Dump partition table in sfdisk format-f, --force: Force operations without prompting-n, --no-act: Show what would be done without doing it-N, --partno: Specify partition number-q, --quiet: Suppress warning messages-u, --unit: Specify units (cylinders, sectors, bytes)-v, --version: Display version information-h, --help: Display help information
Partition Specification Format
Partition Entry Format
Each line in a partition specification file has the format:
start,size,type,bootable
- start: Starting sector (or + for next available)
- size: Size in sectors (or + for remaining space)
- type: Partition type (83 for Linux, 82 for swap, etc.)
- bootable: * for bootable, - for non-bootable
Practical Examples
View partition table
sfdisk -l /dev/sda
Dump partition table to file
sfdisk -d /dev/sda > partition_backup.txt
Create simple partition layout
echo -e ",\n,,\n,," | sfdisk /dev/sda
Create specific partition layout
echo -e "2048,1048576,83,*\n1050624,2097152,82\n3147776,," | sfdisk /dev/sda
Test partition creation without applying
sfdisk -n /dev/sda < partition_spec.txt
Force partition table creation
sfdisk -f /dev/sda < partition_spec.txt
Create GPT partition table
sfdisk --label gpt /dev/sda
Create DOS partition table
sfdisk --label dos /dev/sda
Partition Types
Common Partition Type Codes
- 83: Linux filesystem
- 82: Linux swap
- 5: Extended partition
- ef: EFI System Partition
- 0c: FAT32 filesystem
- 07: NTFS filesystem
Best Practices
When to Use
- Automated disk partitioning
- Creating identical partition layouts
- System deployment and imaging
- Backup and restore of partition tables
- Non-interactive partitioning
Important Notes
- Always backup existing partition tables before making changes
- Use -n option to test partition creation without applying
- Be extremely careful with disk devices - data loss is possible
- Verify partition specifications before applying
- Consider using fdisk for interactive partitioning
- Partition changes may require system reboot