Disk issues are some of the most common Linux problems. Applications fail when logs fill a partition, backups consume unexpected space, or a new disk is not mounted correctly.
DevOps engineers need to answer questions like:
dfdf reports filesystem-level disk usage.
df
df -h-h shows human-readable sizes such as G and M.
Example:
df -h /varThis is useful when a specific path is having storage issues.
dudu shows how much space directories and files consume.
du -sh /var/log
du -sh *
du -ah /var/log | sort -hCommon flags:
-s summary only-h human-readable-a include filesdf tells you how full the filesystem is. du helps you find what is taking the space.
lsblklsblk lists block devices such as disks and partitions.
lsblk
lsblk -fThis shows device names, sizes, mount points, and sometimes filesystem types.
It is especially useful after attaching a new cloud volume.
Linux makes filesystems available by mounting them into the directory tree.
Mount a device:
sudo mount /dev/xvdf1 /mnt/dataUnmount it:
sudo umount /mnt/dataThe command is umount, not unmount.
Note: A filesystem usually cannot be unmounted if processes are actively using it.
/etc/fstabTo mount a filesystem automatically at boot, add it to /etc/fstab.
Example entry:
UUID=1234-ABCD /data ext4 defaults,nofail 0 2Fields define the device, mount point, filesystem type, options, and fsck order.
A broken /etc/fstab entry can cause boot problems, so edit carefully and test before rebooting.
tartar is the standard archiving tool on Linux.
Create an archive:
tar -cvf backup.tar project/Extract an archive:
tar -xvf backup.tarCommon flags:
-c create-x extract-v verbose-f file namegzip and gunzipgzip compresses files.
gzip app.log
gunzip app.log.gzIt is often combined with tar:
tar -czvf backup.tar.gz project/
tar -xzvf backup.tar.gzHere -z tells tar to use gzip compression.
zip and unzipSome teams or tools prefer the ZIP format.
zip -r site.zip site/
unzip site.zipZIP is especially common when exchanging files across platforms.
When a disk fills up, you often need to find the biggest offenders.
A practical approach:
du -ah /var | sort -h | tail -n 20Another useful pattern:
find /var -type f -size +100MThis finds files larger than 100 MB.
Suppose alerts say /var is 95% full. You might investigate with:
df -h /var
du -sh /var/log/*
find /var/log -type f -size +100MIf one log file grew unexpectedly, you now know where to focus.
Or imagine attaching a new volume to a cloud VM. You could verify it with:
lsblk
sudo mount /dev/xvdf1 /mnt/data
df -h /mnt/dataThat confirms the device exists, is mounted, and has usable space.
Question: Which command from the lesson tells you the free space available on mounted filesystems such as /var?
<MCQExercise exercise={{
id: 'linux-disk-storage-q1',
title: 'Exercise 1: Checking filesystem capacity',
description: 'Choose the command that reports mounted filesystem usage and free space.',
options: [
{ id: 'a', text: 'df -h' },
{ id: 'b', text: 'du -sh' },
{ id: 'c', text: 'lsblk -f' },
{ id: 'd', text: 'tar -xvf' },
],
correctId: 'a',
explanation: 'The tutorial distinguishes df from du: df shows filesystem-level capacity and remaining space. That is why df -h is the first check when an alert says a partition is almost full.',
wrongExplanations: {
b: 'du measures how much space specific directories or files consume, but it does not tell you the overall free space left on the filesystem.',
c: 'lsblk is helpful for viewing devices and mount points, but it is not the command the lesson uses for free-space reporting.',
d: 'tar -xvf extracts archives and has nothing to do with checking capacity.',
},
}} />
Question: Which file should you edit to make a filesystem mount persist automatically at boot?
<MCQExercise exercise={{
id: 'linux-disk-storage-q2',
title: 'Exercise 2: Configuring persistent mounts',
description: 'Identify the configuration file used for boot-time filesystem mounts.',
options: [
{ id: 'a', text: '/etc/passwd' },
{ id: 'b', text: '/var/log/messages' },
{ id: 'c', text: '/etc/fstab' },
{ id: 'd', text: '/usr/bin/mounts' },
],
correctId: 'c',
explanation: 'The lesson points to /etc/fstab for persistent mounts and warns that incorrect entries can even cause boot problems. That is why it is the right file and one to edit carefully.',
wrongExplanations: {
a: '/etc/passwd manages user account metadata, not mounted filesystems.',
b: 'Log files may mention mount problems, but they do not define boot-time mount behavior.',
d: 'There is no tutorial-described file at /usr/bin/mounts for persistent mount configuration.',
},
}} />
Question: Which tar command from the lesson creates a gzip-compressed archive of the project directory?
<MCQExercise exercise={{
id: 'linux-disk-storage-q3',
title: 'Exercise 3: Building a compressed backup',
description: 'Choose the tar invocation that both archives and gzip-compresses a directory.',
options: [
{ id: 'a', text: 'tar -xvf project.tar.gz' },
{ id: 'b', text: 'tar -czvf backup.tar.gz project/' },
{ id: 'c', text: 'gzip project/ backup.tar' },
{ id: 'd', text: 'mount project/ backup.tar.gz' },
],
correctId: 'b',
explanation: 'The tutorial explains that c creates an archive, z enables gzip compression, v is verbose output, and f names the archive file. Combined, tar -czvf backup.tar.gz project/ is the correct create-and-compress pattern.',
wrongExplanations: {
a: 'x extracts an existing archive rather than creating one.',
c: 'gzip works on files, but this is not the tar-based archive creation flow shown in the lesson.',
d: 'mount attaches filesystems into the directory tree; it does not create archives.',
},
}} />
df -h for filesystems, du -sh for directories. They answer different questions and often disagree.df says full but du does not? A deleted file is still held open, find it with lsof +L1.df -i checks inodes. A filesystem can be "full" with space free if it has run out of them.du -sh * | sort -h is the fastest way to find where the space actually went./etc/fstab with mount -a before rebooting. A bad entry can leave the machine unbootable./dev/sdX: device names are not stable across reboots.tar -czf creates, -xzf extracts, -tzf lists. Always list an unfamiliar archive before extracting.Almost always a deleted file still held open by a running process. Unlinking a file removes the directory entry, but the blocks are not released until every file descriptor on it closes, so du cannot see it and df still counts it. This happens most often with a log file rotated or deleted while the service holds it open. Find the culprit with sudo lsof +L1, which lists open files with a link count of zero, then restart that process to release the space.
Start at the top and work down: sudo du -sh /* 2>/dev/null | sort -h shows which top-level directory is largest, then repeat inside the winner. du -sh * | sort -h at each level narrows it quickly. ncdu does the same interactively and is worth installing. For individual large files, sudo find / -type f -size +500M -exec ls -lh {} \;. On servers the answer is usually /var/log or a container runtime directory such as /var/lib/docker.
An inode holds a file's metadata, and a filesystem is created with a fixed number of them. Millions of tiny files can exhaust the inode table while gigabytes of space remain, and the kernel reports the generic No space left on device. df -i shows inode usage and confirms it in one command. The fix is deleting files rather than freeing bytes, typically a session directory, a mail spool or a cache that accumulated small files. Only reformatting changes the inode count.
Add a line to /etc/fstab with the device, mount point, filesystem type, options, dump and fsck fields. Use the filesystem UUID from blkid rather than /dev/sdb1, because device names depend on detection order and can change between boots. Pointing a mount at the wrong disk is a genuinely bad outcome. Then test with sudo mount -a, which applies fstab without rebooting. Skipping that test is how a typo becomes an unbootable machine, and adding nofail to the options limits the damage.
tar bundles many files into one archive and does not compress. gzip compresses a single file and does not bundle. They are used together, which is what tar -czf archive.tar.gz dir/ does. The z pipes the tar through gzip. zip does both at once and is the more portable choice for anything going to a Windows user. Practical notes: tar -tzf lists an archive's contents without extracting, which is worth doing before unpacking anything you did not create, and unzip -l is the equivalent.
Write bash scripts that fail loudly, not silently: use set -euo pipefail, quote variables, prefer [[ ]] over [ ], clean up with trap and lint with shellcheck.
Install software on any distro: apt versus apt-get, remove versus purge, fixing dpkg lock errors, dnf and rpm on Red Hat systems, and when snap is worth it.
Learn Linux environment variables: shell versus exported variables, .bashrc versus .bash_profile, extending PATH safely and why sudo drops your environment.