Week 9

Storage Management

Learning Focus

This week introduces how Linux handles storage devices, filesystems, and mounting.
You’ll learn how Linux represents disks, how to format and mount them, and how to measure and manage disk usage.
These skills are critical for developers and administrators who manage servers, virtual machines, or containers that rely on reliable, well-organized storage.

D-M-F-S (Disks → Mounts → Filesystems → Space)

D – Disks and Devices

In Linux, all storage — from hard drives to USB sticks to cloud volumes — is treated as a block device.
Block devices provide raw, addressable storage that the system can format and mount.

1. Understanding Block Devices

Block devices are represented under /dev/ (for example, /dev/sda, /dev/sdb1).
Each name follows conventions:

Device NameMeaningExample
/dev/sdaFirst detected storage deviceSystem’s main disk
/dev/sdb1First partition on the second diskExternal drive partition
/dev/loop0Virtual device for a file-backed diskMounted .img file

To list all block devices, use: lsblk # lists disks, partitions, and their mount points in a tree format

To see how much space is used or available on each mounted device: df -h # displays disk usage in human-readable format (MB/GB)

These commands help administrators understand how disks are structured and what’s currently active.

2. Physical vs. Virtual Storage

  • Physical disks: Actual hardware (HDD, SSD, USB).

  • Virtual disks: Files that emulate a disk, often used for testing or virtualization (e.g., .img files).
    Linux treats both identically — both appear under /dev as block devices.

3. Common Disk Layouts

  • MBR (Master Boot Record) – older partitioning scheme; supports up to 2 TB and 4 partitions.

  • GPT (GUID Partition Table) – modern replacement; supports large disks and unlimited partitions.

System administrators use tools like fdisk, parted, or gdisk to create and inspect partitions.

 
 
 

M — Mounts and Mount Points

Before Linux can use a disk, it must mount it into the filesystem hierarchy.
Mounting means linking a device or partition to a directory, allowing users to access its files.

1. What is a Mount Point?

A mount point is simply a folder where a filesystem becomes accessible.
Example:

  • /mnt/data may contain files from a secondary disk.

  • /media/usb might hold a plugged-in USB drive.

To manually mount: sudo mount /dev/sdb1 /mnt/data

To unmount: sudo umount /mnt/data

Once mounted, the device’s contents appear inside that directory.

2. Loop Devices and Disk Images

You can simulate a physical disk by using a loop device, which treats a file as a virtual block device.

Example: sudo mount -o loop disk1.img /mnt/test

This lets you mount an .img file just like a real drive — useful for practice, virtualization, and testing backups.

3. Persistent Mounts with /etc/fstab

To automatically mount filesystems at boot, edit /etc/fstab.
Each entry defines the device, mount point, filesystem type, and options. Example: UUID=6b4a8c2a-… /data ext4 defaults 0 2

Using UUIDs ensures stability — device names like /dev/sdb1 can change after reboots or hardware reordering.

F — Filesystems

A filesystem defines how data is stored and organized on a device.
Without it, the disk is just raw binary blocks.

1. Creating a Filesystem

You use mkfs (make filesystem) to format a device:

CommandFilesystem TypeDescription
mkfs.ext4ext4Default Linux filesystem — stable and widely used
mkfs.xfsXFSExcellent for large files and high-performance systems
mkfs.btrfsBtrfsSupports snapshots, compression, and subvolumes
mkfs.vfatFATCross-platform compatibility (Windows, USB drives)

Example: mkfs.ext4 /dev/sdb1 # formats partition sdb1 as ext4 filesystem

2. Mounting a New Filesystem

After formatting: sudo mount /dev/sdb1 /mnt/newdisk

You can now read/write files there.
Use df -h to confirm the mount and check available space.

3. Permissions and Ownership

By default, only root can write to newly mounted filesystems.
Change ownership to your user: sudo chown $USER:$USER /mnt/newdisk

This ensures normal users can create and edit files inside.

4. Advanced Filesystem Features

Modern filesystems provide extra functionality:

FeatureDescriptionFilesystem
JournalingProtects data during crashesext4, XFS
SnapshotsCapture point-in-time copiesBtrfs, ZFS
QuotasLimit space per user/groupext4, XFS
CompressionReduce storage footprintBtrfs
EncryptionSecure data at restext4 (LUKS), ZFS

Each choice balances reliability, performance, and flexibility.

 

Navigate the tree​

S — Space and Storage Management

System administrators must monitor and manage space usage to prevent failures and maintain performance.

1. Measuring Disk Usage

Use du (disk usage) to check how much space directories or files consume:

du -sh /var/log # shows total space used by /var/log in human-readable form
du -sh * # displays size of each item in the current directory

2. Checking Filesystem Capacity

Use df -h again to check which filesystems are close to full.
A full disk can cause system crashes, log failures, or even prevent logins.

3. Cleaning and Reclaiming Space

Regular housekeeping is part of real-world storage management:

  • Delete or archive old logs (/var/log/)

  • Remove unused packages (sudo apt autoremove)

  • Find large files: sudo find / -type f -size +500M

  • Compress old data using tar, gzip, or bzip2

4. Monitoring and Alerts

On production systems:

  • Use cron scripts or monitoring tools (e.g., df, du, or ncdu) to check usage daily.

  • Configure alerts when disks reach 80–90% capacity.

  • Automate log rotation with /etc/logrotate.conf.

5. Practical Tools for Developers

For developers, understanding storage helps in:

  • Configuring container volumes (Docker, Podman)

  • Managing virtual disks in VMs or WSL

  • Debugging file I/O bottlenecks

  • Mounting build artifacts, ISO images, and test environments efficiently

This concludes Lecture 9. Please return to Blackboard to access the Week 9 materials.

Scroll to Top