# fdisk Cheatsheet - Cheatsheets - Launch Pad

__ _______________________ _________._________________________ \_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/ | __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_ | \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \ \___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ / \/ \/ \/ \/ \/ \/ \/

# fdisk Cheatsheet

← Back to cheatsheets

← Home

fdisk is a command-line utility for disk partitioning. Used to create, delete, and manage partitions on storage devices.

## Basic Usage

- fdisk -l - List all partitions on all disks

- fdisk -l /dev/sda - List partitions on specific disk

- sudo fdisk /dev/sda - Open fdisk for disk (interactive mode)

## Interactive Commands

Once in fdisk (type `m` for menu):

- p - Print partition table

- n - Create new partition

- d - Delete partition

- t - Change partition type

- w - Write changes and exit

- q - Quit without saving

- l - List known partition types

- v - Verify partition table

- u - Change units (sectors/cylinders)

- m - Print menu

- a - Toggle bootable flag

## Common Operations

### Create New Partition

1. `sudo fdisk /dev/sda`
2. `n` - New partition
3. `p` - Primary partition (or `e` for extended)
4. Choose partition number (1-4)
5. Enter first sector (default is fine)
6. Enter last sector or size (e.g., `+10G` for 10GB)
7. `w` - Write changes

### Delete Partition

1. `sudo fdisk /dev/sda`
2. `p` - View partitions
3. `d` - Delete partition
4. Select partition number
5. `w` - Write changes

### Change Partition Type

1. `sudo fdisk /dev/sda`
2. `t` - Change type
3. Select partition
4. Enter type code (e.g., `83` for Linux, `82` for swap)
5. `w` - Write changes

## Partition Type Codes

- 82 - Linux swap

- 83 - Linux filesystem

- 85 - Linux extended

- 8e - Linux LVM

- ef - EFI system partition

- Use `l` in fdisk to see full list

## After Partitioning

After creating partitions, you may need to:

- `partprobe` - Inform OS of partition table changes

- `mkfs.ext4 /dev/sda1` - Format partition as ext4

- `mount /dev/sda1 /mnt` - Mount partition

- Add to `/etc/fstab` for permanent mounting

## Related Commands

- `lsblk` - List block devices in tree format

- `blkid` - Show block device attributes

- `parted` - Alternative partitioning tool (GPT support)

- `cfdisk` - Curses-based disk partitioner

- `gdisk` - GPT fdisk (for GPT partition tables)

## Configuration

### Config File Location

- `/etc/fstab` - File system table (mount points)

- `/proc/partitions` - Current partition information

## Tips

- Always use `-l` to list first before making changes

- Write changes (`w`) only when you're sure

- Use `q` to quit without saving if you make a mistake

- Backup important data before partitioning

- Use `partprobe` or reboot after partitioning

- For GPT disks, use `gdisk` instead of `fdisk`

- Be very careful - partitioning can destroy data

- Test changes on non-critical systems first

- Use `cfdisk` for easier interactive interface

← Back to cheatsheets

← Home