learninfra · Linux · Networking · Kubernetes · System Design · AI Infrastructure · Exam blueprints · Drills

Remote Filesystems & Swap

Move a full disk's uploads to a NAS over NFS, mount it safely at boot, mount on demand, and add swap for the lean nights.

An interactive Linux lesson: 21 steps, about 32 minutes, on a live simulation in your browser.

You are on call for web01, the shop server. Customers upload avatars and invoices into /srv/uploads, and tonight an export job dumped a 32G archive called night-0314.tgz next to them. That directory lives on /, the same filesystem as the operating system.

df -h / asks the filesystem how full it is: 100%, Avail 0. du -sh /srv/* walks the directories and points at uploads. ls -lh names the file. When one filesystem holds the OS and the data, one flood breaks both.

What you will learn

  1. A full disk at midnight

    • Uploads fill the root disk: One filesystem for the OS and the data means one flood takes down both. df shows which filesystem is full, du shows which directory filled it.
    • Delete it while the writer runs: rm deletes a name. The blocks free when the last process holding the file lets go, so a deleted-but-open file keeps df full.
    • Copy the uploads to the NAS
  2. The NAS over NFS

    • Meet the NAS: NFS makes a directory on another machine appear under one of yours. The server exports it, the client mounts it.
    • Mount it with -t nfs: The first mount field for NFS names the server and its export, not a disk. df on it reports the server's free space.
  3. Mounts that survive reboot

    • Six fields in /etc/fstab: fstab is six fields: what to mount, where, which type, with what options, dump, and fsck order.
    • defaults trusts the disk: defaults means rw, suid, dev, exec and auto. A network share gets nosuid, noexec and nodev, because you did not choose its files.
    • Break it: mount before the network
    • Order it after the network: _netdev orders a mount after the network, nofail lets the boot survive without it, and noauto keeps the boot from trying it directly.
    • Nobody touches it all weekend: noauto plus x-systemd.automount means the share mounts on first use and costs nothing while nobody needs it.
    • Drill: write the NAS fstab line
  4. Mounts on demand

    • autofs: maps instead of units: An automounter mounts on first access and unmounts after idle. systemd does it per fstab line, autofs does it from maps.
    • Break it: the NAS goes dark
    • soft, hard, intr: pick your pain: hard retries forever and hangs with the server, soft fails fast and can corrupt writes, intr lets Ctrl-C break the wait.
  5. Swap for the lean nights

    • Swap on a spare partition: mkswap is mkfs for swap and swapon is mount without a directory. Swap holds no files, only parked memory pages.
    • Keep it, and rank it: Swap priority decides the order pages leave RAM: highest number first, equal numbers share the load.
    • No spare disk? Use a file: A swapfile is swap without repartitioning. Reserve it, chmod it 600, and from mkswap on the kernel cannot tell the difference.
    • Paging before killing: Swap first, OOM killer last. Paging buys time, killing buys survival, and si/so in vmstat show the trade happening.
    • Drill: show the swap areas
  6. Recap & playground

    • Cheat sheet
    • Playground