In one minute
- How Linux uses disks: how a disk is prepared, attached to the folder tree, and how you check and grow the space.
- "Disk full" is one of the most common production problems. Logs grow, Docker images pile up, a database gets bigger, and suddenly the app cannot save anything.
- A disk is split into partitions. Each partition gets a filesystem (a way of organising files). The filesystem is then mounted (attached) to a folder, such as
/data, so it appears in the tree. - 👉 When a disk is filling up, when you add a new disk, or when you grow a cloud disk.
Think of it like: a new shelf for your house. The shelf (disk) is divided into sections (partitions), you put boxes and labels on it (filesystem), then you hang it on a wall in a room (mount point) so people can use it.
How Linux sees storage
Physical disk (/dev/nvme1n1) └── Partition (/dev/nvme1n1p1) └── Filesystem (ext4 or xfs) └── Mounted at a folder (/data)| Word | Meaning |
|---|---|
| Block device | A disk or partition, shown as a file in /dev |
| Partition | A slice of a disk |
| Filesystem | How data is organised on a partition (ext4, xfs) |
| Mount point | The folder where the filesystem appears in the tree |
Listing disks: lsblk
lsblk lists every disk and partition, and where each one is attached.
👉 Before you touch any disk, and to find a newly added disk.
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSnvme0n1 259:0 0 30G 0 disk├─nvme0n1p1 259:1 0 29.9G 0 part /└─nvme0n1p15 259:3 0 106M 0 part /boot/efinvme1n1 259:4 0 100G 0 diskHere nvme1n1 is a 100 GB disk with no partitions and no mount point. That is a new, unused disk.
Remember it:
lsblk= list block devices.
How full is each disk? df
df shows how much space is used and free on each filesystem (disk free).
👉 The first command when someone says "the disk is full".
df -hFilesystem Size Used Avail Use% Mounted on/dev/root 30G 8.2G 22G 28% /tmpfs 2.0G 0 2.0G 0% /dev/shm-h shows sizes people can read. Set alerts when Use% passes 80–85%. At 100%, apps start failing in strange ways.
A filesystem can also run out of inodes even when there is free space. An inode is the slot that each file needs, so millions of tiny files can use them all up:
df -iWhat is using the space? du
du shows how much space a folder uses (disk usage).
👉 After df says a disk is full, to find what filled it.
du -sh /var/logdu -sh /var/* | sort -h # biggest folders under /var, largest lastdu -ah /var/log | sort -h | tail -n 10Go down one level at a time: / → /var → /var/lib → /var/lib/docker, until you find the cause. Usual suspects:
| Folder | Usual cause | Safe fix |
|---|---|---|
/var/log | Logs never cleaned up | Set up logrotate, compress old logs |
/var/lib/docker | Old images and stopped containers | docker system prune |
/tmp | Leftover temporary files | Delete old files |
/var/cache/apt | Downloaded package files | apt clean |
/var/lib/journal | A big systemd journal | journalctl --vacuum-size=500M |
Remember it:
df= how full is the disk.du= which folder filled it.
The trap: deleted, but still open
You delete a huge log, but df still says the disk is full. Why? A running program still has the file open, so Linux cannot free the space until the program lets go.
sudo lsof +L1 # files deleted but still opensudo systemctl restart app # or truncate instead of deleting:: > /var/log/app/huge.log # empties the file in place, space freed immediatelyEmpty (truncate) live logs. Do not delete them.
Adding a new disk
👉 You attached a new disk (for example, a new cloud volume) and want to use it.
lsblk # 1. find the new disk, e.g. /dev/nvme1n1sudo mkfs.ext4 /dev/nvme1n1 # 2. create a filesystem (erases the disk!)sudo mkdir -p /data # 3. create a mount pointsudo mount /dev/nvme1n1 /data # 4. mount itdf -h /data # 5. confirmsudo mount /dev/xvdf /dataMaking it stay after a reboot: /etc/fstab
/etc/fstab is the list of disks to mount at every boot.
A plain mount is forgotten after a reboot.
Add one line, using the disk's UUID (its permanent ID). Names like /dev/sdb can change between reboots. A UUID never does.
sudo blkid /dev/nvme1n1# UUID="3f1c...e2" TYPE="ext4"# /etc/fstabUUID=3f1c...e2 /data ext4 defaults,nofail 0 2nofaillets the server still boot if the disk is missing.- Test before you reboot with
sudo mount -a. A broken fstab line can stop a server from booting at all.
ext4 or xfs?
| ext4 | xfs | |
|---|---|---|
| Default on | Ubuntu, Debian | RHEL, Amazon Linux |
| Grow while in use | Yes (resize2fs) | Yes (xfs_growfs) |
| Shrink | Yes (unmounted) | No |
| Good at | General use, very mature | Big files and many writes at once |
Usually you just use your distribution's default.
LVM: flexible volumes
LVM (Logical Volume Manager) pools several disks together, so you can grow a volume without re-slicing disks.
👉 On servers where storage needs keep growing.
Physical volumes (disks) → Volume group (pool) → Logical volumes (what you mount)sudo pvcreate /dev/nvme1n1sudo vgextend vg0 /dev/nvme1n1 # add the disk to the poolsudo lvextend -r -L +50G /dev/vg0/data # grow the volume and its filesystem-r grows the filesystem together with the volume.
Think of it like: pouring water from several bottles (disks) into one big jug (volume group), then filling glasses (logical volumes) from the jug as needed.
Growing a cloud disk (AWS EBS)
👉 A cloud server's disk is filling up and you made it bigger in AWS.
- Make the volume bigger in the AWS console or CLI.
- Grow the partition:
sudo growpart /dev/nvme0n1 1 - Grow the filesystem:
sudo resize2fs /dev/nvme0n1p1(ext4) orsudo xfs_growfs /(xfs) - Check with
df -h.
No reboot and no downtime.
Real-world scenario: disk full at 3 a.m.
df -hdu -sh /var/loglsblkdf -h # / is at 100%du -sh /var/* | sort -h # /var/log is 18Gdu -ah /var/log | sort -h | tail -n 5 # app.log is 17G: > /var/log/app/app.log # free space immediately# then fix the cause: add logrotate for the appFirst the quick fix (empty the log), then the lasting fix (log rotation, covered in a later lesson).
Common mistakes
- Running
mkfson the wrong disk, which erases its data. Check three times withlsblkfirst. - Using
/dev/sdbnames in fstab instead of UUIDs. - Deleting open log files, then wondering why the space did not come back.
- Editing fstab and rebooting without testing with
mount -a.
Practice
- Show all disks and find the unused one.
- Show free space on every filesystem in readable sizes.
- Find how much space
/var/loguses. - Write the fstab line to safely mount a disk with UUID
abcd-1234at/dataas ext4.
Cheat sheet
| Command | What it does |
|---|---|
lsblk | List disks and partitions |
df -h / df -i | Space / inodes used per filesystem |
du -sh dir | Size of a folder |
mount dev dir / umount dir | Attach / detach a filesystem |
blkid | Show filesystem UUIDs |
mount -a | Test fstab |
: > file | Empty a file in place |
Key takeaways
- A disk is sliced into partitions, given a filesystem, then attached to a folder.
df -hshows how full each disk is.du -shshows which folder is big.- If a log is huge, empty it with
: > fileinstead of deleting it. - To keep a disk attached after reboot, add it to
/etc/fstabwith its UUID, then test withmount -a. - Cloud disks can be made bigger without turning the server off.