Disk formatting & partitioning

Linux Command Line Quick Reference

1 min read

Published Aug 18 2026


19
0
0
0

CLILinuxUbuntu

Formatting and partitioning can destroy data. Confirm the device name with lsblk before running any write operation. A device such as /dev/sdb represents a whole disk, while /dev/sdb1 represents a partition on it.

Inspect and partition disks

bash
lsblk -fsudo fdisk -lsudo parted -lsudo fdisk /dev/sdbsudo parted /dev/sdb

fdisk -l lists partition tables. Interactive fdisk can create, delete and change partitions, but changes are not written until you explicitly choose to write them. parted supports GPT and can also be used interactively or scripted.

After creating a partition, make a filesystem on the partition, not normally on the whole disk:

Create filesystems and swap

bash
sudo mkfs.ext4 /dev/sdb1sudo mkfs.xfs /dev/sdb1sudo mkfs.vfat -F 32 /dev/sdb1sudo mkswap /dev/sdb1sudo swapon /dev/sdb1sudo swapoff /dev/sdb1

mkfs.ext4 creates an ext4 filesystem. mkfs.xfs creates XFS. mkfs.vfat -F 32 creates FAT32. mkswap prepares swap space and swapon activates it.

Never run a mkfs command against a partition containing data you need. Formatting creates new filesystem structures and makes existing contents inaccessible.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Linux Command Line Quick Reference | Disk formatting & partitioning | SimpleSteps.guide