Skip to content

Chapter 5 of 8

Storage, Filesystems, and LVM

Linux exposes block devices through a virtual filesystem populated by udev, the kernel's device manager that creates entries under /dev dynamically as hardware appears and disappears. lsblk and lsblk -f present a tree of block devices with their sizes, types, UUIDs, filesystem types, and mountpoints. blkid returns UUIDs, labels, and filesystem types for a device; stat filename reports detailed inode and timestamp information for a file. Filesystems are mounted based on /etc/fstab, which describes source, target, type, options, and dump/pass fields; mount -a mounts everything listed that is not already mounted, while findmnt -o TARGET,SOURCE,FSTYPE,OPTIONS shows the current mount table. Disk usage is summarized with df -h (per filesystem) or df -Th (with type), while du -h lists sizes recursively and du -sh gives a single total for a directory. SMART health is checked with smartctl -a /dev/sdX, software RAID status with cat /proc/mdstat, and chroot changes a process's apparent root directory for recovery or isolation scenarios.

Two journaling filesystems dominate Linux today. ext4 (created with mkfs.ext4) is versatile, supports shrinking, and exposes parameters via tune2fs -l. The default 5% reserved block percentage can be reduced with tune2fs -m 1; these blocks exist to keep root functional when the disk fills. e2fsck -n and fsck -n perform read-only integrity checks. XFS excels at large files and parallel I/O but cannot shrink; it is created with mkfs.xfs, diagnosed with xfs_info and xfs_repair -n, and defragmented online with xfs_fsr. Both are production-ready, with the choice depending on workload patterns. For backup and migration, rsync -a --delete src/ dest/ synchronizes two trees and removes files in the destination that no longer exist in the source, --dry-run previews changes, and -aAXH preserves ACLs, extended attributes, and hardlinks. tar -czf archive.tgz /dir creates a compressed archive, tar -tzf lists contents without extracting, tar -xzf path/inside -C /restore extracts specific files, and --listed-incremental=snapshot.file enables incremental backups. find . -exec command {} + applies a command to many files at once, and xargs builds and executes command lines from standard input, often used to bridge long find output with utilities like rm.

LVM adds a layer of flexibility on top of block devices. Physical Volumes (PVs) are aggregated into Volume Groups (VGs), which are divided into Logical Volumes (LVs) used as if they were partitions. lvextend -r -L +5G /dev/vg/lv extends an LV and resizes the underlying filesystem in one step; for XFS, an online grow requires xfs_growfs MOUNTPOINT after the LV grows. Snapshots are created with lvcreate -s -L 2G -n snap /dev/vg/lv, and merging a snapshot back uses lvconvert --merge /dev/vg/snap, usually requiring the origin to be inactive (unmounted or the system rebooted).

Partitions are managed with fdisk or parted; parted -l lists all block devices with their tables. parted /dev/sdX resizepart PARTNUM END resizes a partition, after which the filesystem is grown (resize2fs for ext4, xfs_growfs for XFS). GPT supports disks larger than 2 TB and up to 128 partitions, while MBR is legacy with a 4-partition limit; gdisk can convert between them (after a backup). UEFI systems require an EFI System Partition (FAT32, typically mounted at /boot/efi). SSDs benefit from TRIM, which informs the drive of freed blocks: fstrim -v /mountpoint runs it manually, while periodic fstrim.timer automates it, or discard can be added as a mount option. Special mounts include bind mounts (mount --bind /src /tgt), which can be made read-only with mount -o remount,ro,bind /tgt, and loop devices, which let a file be mounted as a block device, as with mount -o loop image.iso /mnt/iso. losetup -l lists active loop devices.

All chapters
  1. 1SSH, Remote Access, and File Transfer
  2. 2DNS and Name Resolution
  3. 3Systemd, Logging, and Scheduled Tasks
  4. 4Users, Permissions, and Linux Security
  5. 5Storage, Filesystems, and LVM
  6. 6Networking, Firewalls, and Diagnostics
  7. 7Web Servers, SSL/TLS, and Hosting Panels
  8. 8Process Management, Performance, and Containers

Drill it

Reading is not remembering. These come from the Sysadmin Cards deck:

Q

What is the purpose of the <code>~/.ssh/config</code> file?

It allows users to define shortcuts and configuration options (like Hostname, User, Port, IdentityFile) for SSH connections.

Q

What are the recommended permissions for the <code>~/.ssh/authorized_keys</code> file?

600 (read/write for owner only).

Q

What is a DNS <b>CNAME</b> record?

A Canonical Name record that maps one domain name (alias) to another domain name (canonical).

Q

What is a DNS <b>MX</b> record?

A Mail Exchange record that specifies the mail server responsible for accepting email messages on behalf of a domain.