Disk and Partition Commands in Ubuntu with Examples + Cheat Sheet

Share

These disk and partition commands work on Ubuntu 26.04 LTS and Ubuntu 26.10. They cover listing drives, checking free space, partitioning and formatting a new disk, mounting it at boot and checking drive health. Copy-ready examples and a free cheat sheet are included.

Before You Start
Ubuntu version
Ubuntu 26.04 LTS or 26.10. lsblk, df, parted, fdisk and mkfs are installed by default.
Back up first
Partitioning and formatting erase data. Confirm the device name with lsblk before every destructive command.
Device names
Examples use /dev/sdb as an empty second disk. NVMe drives look like /dev/nvme0n1 with partitions p1, p2.
KEY TAKEAWAYS
01Look before you write
lsblk -f shows every disk, partition, filesystem and mount point at a glance.
02Space vs size
df -h reports free space per filesystem. du -sh measures folders.
03GPT for new disks
parted mklabel gpt is the modern choice for disks of any size.
04Label your filesystems
mkfs.ext4 -L name makes drives easy to recognise later.
05Mount by UUID
Use the UUID from blkid in /etc/fstab so mounts survive device name changes.
06Test fstab safely
Run sudo findmnt --verify and sudo mount -a before rebooting.
Free Cheat Sheet

Download the Ubuntu Disk and Partition Commands Cheat Sheet

Every command from this guide on one printable sheet. Grab the PDF, or pick EPUB, DOCX, MOBI or AZW3 for your reader.

Also see Top 40 Linux commands for Ubuntu 26.04, Advanced Linux commands, Chmod and chown commands in Ubuntu and Apt and snap commands in Ubuntu.

List disks and partitions

Start every disk task by identifying the right device. These commands only read information.

1. Show block devices

Lists disks and partitions as a tree. -f adds filesystem type, label, UUID and free space.

lsblk
lsblk
lsblk -f
lsblk -f sample output on Ubuntu 26.04
Sample output: lsblk -f with an NVMe system disk and a new data disk (illustrative).

2. Choose lsblk columns

Pick only the fields you need.

lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS
lsblk -o NAME,SIZE,TYPE,FSTYPE,LABEL,MOUNTPOINTS

3. Show UUIDs and labels

Prints the UUID, label and type of every filesystem.

sudo blkid
sudo blkid

4. Show partition tables

fdisk -l and parted -l print the partition layout of each disk.

sudo fdisk -l /dev/sdb
sudo fdisk -l /dev/sdb
sudo parted -l

5. Show what is mounted where

findmnt prints mounts as a tree. -D gives a df-style view.

findmnt
findmnt
findmnt /
findmnt -D

Check disk space

Use df to see how full each filesystem is, then du to find which folders are responsible.

6. Free space per filesystem

-h prints human-readable sizes. -T adds the filesystem type.

df -h
df -h
df -hT
df -hT sample output on Ubuntu 26.04
Sample output: df -hT showing size, use and type per filesystem (illustrative).

7. Check inodes

A disk can run out of inodes, which limit the number of files, while space is still free.

df -i
df -i

8. Size of a folder

Summarises the total size of one directory.

du -sh ~/Downloads
du -sh ~/Downloads

9. Find the biggest folders

Lists first-level folders by size, largest last.

sudo du -h –max-depth=1 /var | sort -h
sudo du -h --max-depth=1 /var | sort -h

10. Interactive disk usage

ncdu lets you browse folders by size and delete from inside the tool.

sudo apt install ncdu
sudo apt install ncdu
ncdu ~

Partition a new disk

The next commands destroy existing data on the target disk. Unmount it first and double-check the name with lsblk.

11. Wipe old signatures

Removes leftover filesystem and RAID signatures so tools do not get confused.

sudo wipefs -a /dev/sdb
sudo wipefs -a /dev/sdb

12. Create a GPT partition table

Writes a new, empty GPT label to the disk.

sudo parted /dev/sdb mklabel gpt
sudo parted /dev/sdb mklabel gpt

13. Create one partition for the whole disk

Creates a partition named data covering the disk with optimal alignment.

sudo parted -a optimal /dev/sdb mkpart data ext4 0% 100%
sudo parted -a optimal /dev/sdb mkpart data ext4 0% 100%

14. Partition interactively

fdisk is menu driven: n creates a partition, p prints the table, w writes and exits. cfdisk offers a simpler text interface.

sudo fdisk /dev/sdb
sudo fdisk /dev/sdb
sudo cfdisk /dev/sdb

Format and repair filesystems

Format the partition, not the whole disk. ext4 is the default Linux filesystem on Ubuntu. Use exFAT for USB drives shared with Windows and macOS.

15. Create an ext4 filesystem

Formats the partition and gives it a label.

sudo mkfs.ext4 -L data /dev/sdb1
sudo mkfs.ext4 -L data /dev/sdb1

16. Format a USB drive

FAT32 works everywhere. exFAT handles files over 4 GB. Install exfatprogs if mkfs.exfat is missing.

sudo mkfs.vfat -F 32 -n USB /dev/sdc1
sudo mkfs.vfat -F 32 -n USB /dev/sdc1
sudo mkfs.exfat -n USB /dev/sdc1

17. Change an ext4 label

Renames the filesystem without touching the data.

sudo e2label /dev/sdb1 backup
sudo e2label /dev/sdb1 backup

18. Check and repair ext4

Run only on an unmounted filesystem. -f forces a check even if it looks clean.

sudo umount /dev/sdb1
sudo umount /dev/sdb1
sudo e2fsck -f /dev/sdb1

19. Grow a partition and filesystem

growpart extends partition 1 into free space, then resize2fs grows ext4 to match. growpart comes from cloud-guest-utils.

sudo growpart /dev/sdb 1
sudo growpart /dev/sdb 1
sudo resize2fs /dev/sdb1

Mount drives and edit fstab

A filesystem is usable once it is mounted on a folder. Add it to /etc/fstab to mount it at every boot.

20. Mount a partition

Creates a mount point and attaches the filesystem to it.

sudo mkdir -p /mnt/data
sudo mkdir -p /mnt/data
sudo mount /dev/sdb1 /mnt/data

21. Unmount a partition

Close any files and terminals using it first.

sudo umount /mnt/data
sudo umount /mnt/data

22. Mount at boot by UUID

Copy the UUID from blkid and add one line to /etc/fstab. nofail lets the system boot if the drive is missing.

sudo blkid /dev/sdb1
sudo blkid /dev/sdb1
sudo nano /etc/fstab
# add a line like this:
UUID=your-uuid-here  /mnt/data  ext4  defaults,nofail  0  2

23. Test fstab before rebooting

findmnt –verify checks the file for errors, daemon-reload refreshes systemd and mount -a mounts every entry.

sudo findmnt –verify
sudo findmnt --verify
sudo systemctl daemon-reload
sudo mount -a
sudo findmnt --verify sample output on Ubuntu 26.04
Sample output: a clean findmnt –verify, then mount -a and findmnt confirming the new mount (illustrative).

24. Mount USB drives as a normal user

udisksctl mounts under /media like the desktop does, and can power the drive off safely.

udisksctl mount -b /dev/sdc1
udisksctl mount -b /dev/sdc1
udisksctl unmount -b /dev/sdc1
udisksctl power-off -b /dev/sdc

Drive health and swap

Check drives before they fail, and confirm swap is active on systems with little RAM.

25. Check SMART health

smartctl reads the drive self-monitoring data. -H gives a pass or fail summary, -a shows everything.

sudo apt install smartmontools
sudo apt install smartmontools
sudo smartctl -H /dev/sda
sudo smartctl -a /dev/nvme0

26. Show swap

Ubuntu uses a swap file at /swap.img by default.

swapon –show
swapon --show
free -h

Disk commands quick reference

Task Command
List disks lsblk -f
Free space df -hT
Folder sizes sudo du -h --max-depth=1 /var | sort -h
New GPT table sudo parted /dev/sdb mklabel gpt
New partition sudo parted -a optimal /dev/sdb mkpart data ext4 0% 100%
Format ext4 sudo mkfs.ext4 -L data /dev/sdb1
Mount sudo mount /dev/sdb1 /mnt/data
Get UUID sudo blkid /dev/sdb1
Test fstab sudo findmnt --verify && sudo mount -a

Tips and best practices

GNOME Disks (gnome-disk-utility) and GParted do the same jobs with a graphical interface. They are a good way to double-check a layout before you run a destructive command in the terminal.

After mounting a new ext4 drive, it is owned by root. Give your user access with sudo chown, covered in the chmod and chown guide linked below.