# Mounting Filesystems and Using /etc/fstab

> Chapter 11 of the Courseiva LF-LFCS curriculum — https://courseiva.com/learn/lf-lfcs/mounting-filesystems-and-using-fstab

**Official objective:** 4.3 — Mount and unmount filesystems, configure persistent mounts

## Introduction

Mounting a filesystem is the act of making a storage device – like a hard drive, USB stick, or network share – accessible to you as a folder inside the computer's unified file tree. For the LFCS exam, you must understand both how to mount and unmount devices manually and, more crucially, how to automate those mounts using the /etc/fstab configuration file so they persist across reboots.

## The House Extension Power Board Analogy

Your house's main electrical panel. 

 Your house has a main electrical panel in the basement. It's connected to the city's power grid. Inside your house, every room has outlets. When you build a new extension – say, a home office – that extension has its own walls, lights, and sockets. But those sockets are dead until you run a cable from the new room back to the main panel and flip the correct circuit breaker. Only then does electricity flow. 

 In Linux, your computer's root filesystem (the main panel) is always connected when the system starts. When you plug in a USB drive or add a new hard disk, that device has its own structure of folders and files (the extension's sockets). But you cannot use them until you 'mount' it – which is like running that cable and flipping the breaker. The /etc/fstab file (the circuit breaker schedule) tells Linux exactly which devices to connect automatically every boot, preventing the hassle of manually flipping breakers each time. Without fstab, every time you reboot, you'd have to manually 'run the cable' again – remembering device names and folder locations – the way you'd have to rewire your office extension every morning.

## Core explanation

At its core, a computer stores data on physical devices: hard drives, SSDs, USB sticks, even network servers. Each device organises its data using a filesystem – a structure of folders and files. Common filesystem types you'll encounter are ext4 (standard for Linux), XFS (used by Red Hat), NTFS (Windows), and vfat (older USB sticks). 

 The problem is that your operating system, Linux, sees these devices by raw name – for example, /dev/sda1, /dev/sdb1. These names are not user-friendly. You don't want to navigate to '/dev/sda1' every time you need a document. Instead, you want the data to appear in a familiar folder, like /home/user/Documents or /mnt/backup. 

 Mounting is the process of attaching a device's filesystem to a specific directory (called the mount point). Once mounted, the device's content appears inside that directory as if it were a regular part of the file tree. Think of it like attaching a new bookshelf to an existing library: the shelves (directories) keep their labels, but now the library is physically bigger. 

 The 'mount' command is used to do this manually. For example, 'mount /dev/sdb1 /mnt/usb' attaches the device /dev/sdb1 to the directory /mnt/usb. Unmounting, with 'umount /mnt/usb', detaches it. Crucially, you cannot unmount a device that is in use – if a program or terminal is inside that directory, the unmount will fail with a 'device is busy' error. 

 But manual mounting is impractical on a server. Imagine having to mount every disk by hand each time the server restarts. That is where /etc/fstab comes in. fstab is a plain-text configuration file that tells the system which filesystems to mount automatically at boot and how to mount them. Each line in fstab represents one device. 

 A typical fstab line contains six fields, separated by spaces or tabs: 

 - Device identifier: This can be the raw device name (e.g., /dev/sda1), but that is fragile – the name can change if you add or remove disks. Better to use the UUID (Universally Unique Identifier), a long serial number that stays the same regardless of the controller port. You can find a device's UUID using 'blkid /dev/sdb1'. 
 - Mount point: The directory where the device will appear (e.g., /home or /mnt/data). This directory must exist before mounting. 
 - Filesystem type: e.g., ext4, xfs, ntfs, vfat. 
 - Options: A comma-separated list of mount options. Common ones include defaults (read-write, suid, dev, exec, auto, nouser, async), ro (read-only), noexec (prevents executing binaries on that partition), noauto (do not mount at boot), and users (allow any user to mount/unmount). 
 - Dump: A backup utility flag. Usually 0 (ignore backups) for modern systems. 
 - Pass: Controls which filesystem is checked by fsck during boot. The root filesystem is typically 1, others are 2, and 0 means do not check at boot. 

 The 'mount -a' command reads /etc/fstab and mounts every entry that has the 'auto' option (which 'defaults' includes). This is the command Linux runs during boot to mount all your filesystems. 

 Remember: you can also mount network filesystems like NFS (Network File System) and CIFS/SMB (Windows shares) via fstab. Those entries specify the server's IP address and exported folder as the device, like '192.168.1.10:/shared/folder'. 

 A very common task is editing fstab to add a new disk that should always be available. After editing the file, always run 'mount -a' to test the syntax without rebooting. If you make a mistake – say, a wrong UUID – the system will hang at boot waiting for that device. For exam survival, know how to rescue a broken fstab by using 'single user mode' or the 'emergency' shell from the bootloader. 

 Finally, the 'findmnt' command is helpful to see the current mount tree. The 'lsblk' command lists all block devices (disks and partitions) and their mount points in a tree view.

## Real-world context

You are the sole IT administrator for a small e-commerce company. The company's web server runs on Ubuntu Linux. The server has three hard drives: one for the operating system (sda), one for the website's static assets – images, CSS, JavaScript (sdb), and one for customer uploads – product photos, documents (sdc). The web developer tells you that the uploads folder appears to have only 2 GB of space free, but you know the third drive is 500 GB. 

 The problem: the third drive (sdc) is not mounted. It sits in the server, connected, but without a mount point. Linux sees the device as /dev/sdc1, but no folder gives you access to it. The website's upload code writes to /var/www/uploads, which is currently on the system drive (sda), not the large disk. 

 Step 1: You physically identify the disk's partition using 'lsblk'. You see /dev/sdc1 is listed but has no mount point. 
 Step 2: You check its filesystem type with 'blkid /dev/sdc1'. It shows type ext4. 
 Step 3: You create a directory for the mount point: 'mkdir /mnt/uploads'. You could also use /var/www/uploads directly if it were empty, but safer is to temporarily mount elsewhere. 
 Step 4: You mount it manually: 'mount /dev/sdc1 /mnt/uploads'. 
 Step 5: You copy the existing uploads from /var/www/uploads to /mnt/uploads using 'rsync -av /var/www/uploads/ /mnt/uploads/'. 
 Step 6: You then unmount from the temporary spot: 'umount /mnt/uploads'. Then mount it directly: 'mount /dev/sdc1 /var/www/uploads'. Now the website's uploads folder uses the 500 GB drive. 
 Step 7: But if the server reboots, this mount is lost. To make it permanent, you edit /etc/fstab. You get the UUID: 'blkid /dev/sdc1' shows UUID='abc123...'. You add a line: 

 UUID=abc123... /var/www/uploads ext4 defaults 0 2 

 Step 8: You test the fstab entry by running 'mount -a'. No errors. You check with 'df -h /var/www/uploads' to confirm the new space. 
 Step 9: You document the change and tell the web team that the uploads are now safe on the dedicated drive. 

 A more complex scenario: the company also has a remote backup server using NFS. You need /backups to always be mounted. In fstab, you'd add: 

 192.168.1.50:/exports/backups /backups nfs defaults,_netdev 0 0 

 The '_netdev' option tells the system to wait for the network before attempting to mount. 

 The most common real-world mistake: forgetting to create the mount point directory before the fstab entry. If /var/www/uploads does not exist, mount will fail. Another common error: using the wrong device name (like /dev/sdc1) instead of the UUID. If you reboot and the disk order changes, your system will hang. Always use UUIDs for internal disks. 

 For the LFCS exam, you must also know how to rescue a system that fails to boot because of a bad fstab entry. In a real job, you would boot from a live USB, mount the system drive, and fix the fstab file. On the exam, they test the same rescue procedure using single user mode or the grub emergency shell.

## Exam focus

The LFCS exam objective 4.3 covers two major skills: manually mounting/unmounting filesystems using command-line tools, and configuring persistent mounts via /etc/fstab. The exam is performance-based – you will be given a live Linux system and must perform these tasks, not just answer multiple-choice questions. 

 Here is exactly what they test and the traps they set: 

 - Identifying devices: You must know 'lsblk', 'blkid', and 'fdisk -l' to find devices and their UUIDs. A common trap is having multiple disks with similar names, hoping you pick the wrong one. Always verify with UUID. 

 - Mounting with the correct filesystem type: They will give you an unmounted disk partition. If you omit the '-t' flag, mount often auto-detects, but sometimes they use a disk formatted with XFS or Btrfs on a system that does not auto-detect. Then the command fails. Know these types: ext4, xfs, vfat, ntfs-3g. 

 - The 'mount -a' test: After editing fstab, they always expect you to run 'mount -a' to verify the syntax. They may set up a scenario where the fstab has a deliberate error. If you reboot without testing, you fail. 

 - Unmounting busy devices: They will have a terminal open in the mounted directory. You must know to use 'lsof /mountpoint' or 'fuser -v /mountpoint' to find the process, then kill it or change directory before unmounting. A common trap is the 'umount -f' force option – it exists but can cause data corruption. The exam expects you to find and close the user first. 

 - Rescue mode: They may intentionally corrupt the fstab file (e.g., wrong UUID). You must boot into single user mode (append 'single' or '1' to the kernel line in GRUB) and fix the file. Knowing the path '/etc/fstab' and that you can use 'mount -o remount,rw /' to make the root writable in single user mode is critical. 

 - Network mounts: They often include an NFS mount in the exam scenario. You must know the '_netdev' option and that 'mount -a' will try network mounts even if the network is not ready unless you use that option. 

 - Mount options: They love to ask about 'noexec', 'nosuid', 'nodev', 'ro', and 'users'. Example: mount a USB drive with 'noexec' to prevent malware from running. The command 'mount -o noexec /dev/sdb1 /mnt/usb'. 

 - The six fstab fields: You must memorise them: device, mount point, type, options, dump, pass. They may present a line with missing fields or extra spaces and ask you to fix it. 

 - Auto vs noauto: A device marked 'noauto' will not mount at boot but can still be mounted manually. A common question: 'Why is my disk not mounting at boot?' Answer: check the options column for 'noauto'. 

 - Trap: using 'mount /dev/sdb1' without a mount point – it will fail because mount expects two arguments (device and mount point). 

 - Trap: thinking 'umount' is 'unmount'. The command is 'umount' (no 'n'). Typing 'unmount' will give 'command not found'. 

 - Trap: mounting to a non-empty directory. Linux allows it, but the original content becomes hidden. The exam expects you to either use an empty directory or move the content. 

 Key definitions to memorise: 
 - Mount point: a directory where a device's filesystem is attached. 
 - UUID: a 128-bit number used to uniquely identify a partition. 
 - fstab: the configuration file that defines filesystem mount behaviour. 
 - mount command: attaches a device to a directory. 
 - umount command: detaches it. 
 - defaults mount option: a shorthand for rw, suid, dev, exec, auto, nouser, async.

## Step by step

1. **Identify the device** — Use lsblk to list all block devices and their partitions. Use blkid to view the UUID and filesystem type of each partition. For example, 'lsblk' shows /dev/sdb as a 500GB disk with partition /dev/sdb1. 'blkid /dev/sdb1' reveals it is of type ext4 with UUID=abc123. This step is critical because you must know exactly which device you are working with before mounting.
2. **Create the mount point directory** — Choose an empty directory that will be the access point for the device. For example, 'mkdir /mnt/data'. If the directory does not exist, the mount command will fail. The mount point must exist on the filesystem before the mount operation. You can use an existing directory like /home, but only if you intend to replace its content – the original files become hidden until the device is unmounted.
3. **Mount the device manually** — Run 'mount /dev/sdb1 /mnt/data' or, better, 'mount UUID=abc123 /mnt/data'. Check success with 'df -h /mnt/data' or 'mount | grep /mnt/data'. This manual mount gives you access to the device immediately, but does not persist across reboots. Testing the manual mount first verifies that the device is readable and correctly formatted.
4. **Edit /etc/fstab to make the mount permanent** — Add a single line to /etc/fstab with the six fields: UUID=abc123 /mnt/data ext4 defaults 0 2. Use a text editor like vim or nano. The 'defaults' option set includes rw, suid, dev, exec, auto, nouser, async. The '0 2' at the end sets dump to 0 (no backup) and pass to 2 (filesystem check order). This is the step that automates the mount at boot.
5. **Test the fstab entry without rebooting** — Run 'mount -a' to mount all filesystems listed in fstab that have the 'auto' option. If there is a syntax error or wrong UUID, the command will output an error message. This test is crucial because a mistake in fstab can cause a boot failure. If successful, 'df -h' will show the device mounted on the specified point.
6. **Unmount the device correctly for maintenance or removal** — To unmount, first ensure no process is using the mount point: use 'lsof /mnt/data' or 'fuser -v /mnt/data' to find and close any open files. Then run 'umount /mnt/data' or 'umount /dev/sdb1'. The device will detach and the mount point directory will return to showing only its local content. If you need to remove the persistent mount, delete the corresponding line from /etc/fstab.

## Comparisons

### UUID in fstab vs Device name (e.g., /dev/sda1) in fstab

**UUID in fstab:**
- Stays the same regardless of disk order changes
- Unique per partition across all systems
- Preferred for internal disks in production systems

**Device name (e.g., /dev/sda1) in fstab:**
- Changes if disks are added or removed
- Not guaranteed to be consistent across reboots
- Acceptable for temporary, single-disk test systems only

### mount command vs umount command

**mount command:**
- Attaches a device to a directory
- Requires the device and mount point as arguments
- Can use -t to specify filesystem type

**umount command:**
- Detaches a device from its mount point
- Fails if the filesystem is busy
- Can use -l (lazy) for a delayed unmount

### defaults mount option vs noauto mount option

**defaults mount option:**
- Mounts the device automatically at boot
- Includes rw, suid, dev, exec, auto, nouser, async
- The most common option for permanent drives

**noauto mount option:**
- Does NOT mount at boot; you must mount manually
- Often used for removable media like USB drives
- Still allows manual 'mount /mountpoint' after boot

### mount with exec vs mount with noexec

**mount with exec:**
- Allows running binary executables on the filesystem
- Default in the 'defaults' option set
- Needed for /usr, /bin, /sbin partitions

**mount with noexec:**
- Prevents execution of any binaries on the filesystem
- Used for security on removable media or /tmp to prevent malware
- Shell scripts still run, but ELF binaries do not

## Diagram

_Flowchart showing the boot-time process of mounting filesystems as dictated by /etc/fstab, including the decision points for auto/noauto and error handling._

```mermaid
flowchart TD
    A[Boot sequence begins] --> B[Kernel reads /etc/fstab]
    B --> C{For each fstab entry}
    C -- Has 'noauto' option? --> D[Skip entry, not mounted at boot]
    C -- Has 'auto' option? --> E[Identify device using UUID or device name]
    E --> F{Device exists and is usable?}
    F -- Yes --> G[Create mount point if missing?]
    G --> H[Apply mount options (ro, noexec, etc.)]
    H --> I[Run fsck if pass > 0]
    I --> J[Mount the device to specified directory]
    F -- No --> K[Boot hangs or enters emergency shell]
    D --> L[System continues booting]
    J --> L
```

## Common misconceptions

- **Misconception:** I only need to add the raw device name like /dev/sda1 in fstab and it will always work because the device never changes. **Reality:** Device names like /dev/sda1 can change when you add or remove disks, or when the kernel detects them in a different order. Using the UUID (Universally Unique Identifier) ensures the correct partition is mounted regardless of its device name. (Beginners often see tutorials using /dev/sda1 and assume it's permanent, not realising that BIOS enumeration or kernel probing order can shift names across reboots.)
- **Misconception:** I can unmount a filesystem by simply running umount even if I am currently inside that mount point's directory. **Reality:** You cannot unmount a filesystem that is in use. If your current working directory is inside the mounted directory, or if any process has open files there, umount will fail with 'device is busy'. You must first change to a directory outside the mount point and close any open file handles. (This mistake happens because new users think the command is forceful enough to override usage, but the kernel protects active filesystems from being yanked out from under running processes.)
- **Misconception:** Mounting a USB drive using 'mount /dev/sdb1 /mnt' permanently adds it to the system and it will remount automatically after reboot. **Reality:** Mounting manually does not persist across reboots unless you add an entry to /etc/fstab. After a reboot, the USB must be remounted manually or via an fstab entry with the 'auto' option. (Beginners confuse the mounting command with configuration – they think a one-time action modifies system behaviour permanently, similar to how the 'ip addr' command might appear to change networking, but without persistence.)
- **Misconception:** If I edit /etc/fstab and make a mistake, the worst that happens is that the partition does not mount, and I can fix it later. **Reality:** A mistake in /etc/fstab can cause the system to fail to boot entirely. If the wrong UUID or mount option prevents a filesystem from being mounted, the boot process may hang waiting for that device. You then need to enter single user mode or use a live CD to fix the file. (New users think the boot process ignores errors in configuration files, but fstab is read during early boot before the system is fully operational, and a missing disk can cause a timeout or kernel panic.)
- **Misconception:** The umount command is spelled 'unmount' like the word 'unmount' in English. **Reality:** The correct command is 'umount' (without the 'n'). It is a historical abbreviation. Typing 'unmount' will produce a 'command not found' error. (This is a simple but persistent spelling mistake because the English word 'unmount' seems logical, and many online resources accidentally use the misspelling too.)

## Key takeaways

- Mounting attaches a storage device to a directory so its files become accessible as part of the file tree.
- The /etc/fstab file defines which filesystems mount automatically at boot, with each line containing six fields: device identifier, mount point, filesystem type, options, dump, and pass.
- Always use UUIDs instead of device names like /dev/sda1 in fstab to prevent boot failures when disk order changes.
- After editing /etc/fstab, immediately run 'mount -a' to test the syntax before rebooting.
- You cannot unmount a filesystem that is in use; use 'lsof' or 'fuser' to identify and stop the blocking processes first.
- If a bad fstab entry causes a boot hang, boot into single user mode (by appending 'single' to the kernel command line) and fix the file.
- The 'mount -o' option allows you to specify mount options like 'noexec' (prevent execution of binaries) and 'ro' (read-only).

## FAQ

**What is the difference between mount and fstab?**

mount is a command used to manually attach a device to a directory. fstab is a configuration file that tells the system which devices to mount automatically at boot. Think of mount as a manual light switch, and fstab as an automatic timer that switches lights on at sunrise.

**Why does my mount fail with 'mount: /mnt/usb: special device /dev/sdb1 does not exist'?**

This means the device /dev/sdb1 does not exist or is not connected. Run 'lsblk' to see the actual device names and partitions. A common cause is plugging the USB into a different port, which changes its name to /dev/sdc1 or similar.

**How do I find the UUID of a partition?**

Use the command 'blkid /dev/sda1' (replace sda1 with your partition). It will output something like: /dev/sda1: UUID="abc123" TYPE="ext4". You can also use 'lsblk -f' to see all UUIDs in a table format.

**What happens if I mount to a non-empty directory?**

The original contents of the directory become hidden while the device is mounted. They are not deleted; they reappear when the device is unmounted. This is usually undesirable, so always mount to an empty or purpose-created directory.

**Can I mount a network share with fstab?**

Yes. For an NFS share, add a line like '192.168.1.100:/export /mnt/nfs nfs _netdev 0 0'. The '_netdev' option is important because it tells the system to wait for the network to be ready before attempting the mount. For a Windows CIFS share, you need the 'cifs' type and mount options for credentials.

**My system hangs at boot because of a bad fstab entry. How do I fix it without reinstalling?**

When the bootloader (GRUB) appears, press 'e' to edit the kernel command line. Append 'single' or '1' to the end of the line that starts with 'linux', then press Ctrl+X to boot into single user mode. Then remount root as read-write with 'mount -o remount,rw /'. Edit /etc/fstab with nano to fix the line. Reboot.

## Check your understanding

1. **What command would you use to mount the device with UUID '1234-5678' to the directory '/mnt/backup' using the ext4 filesystem?**

   Answer: mount UUID=1234-5678 /mnt/backup -t ext4

2. **After editing /etc/fstab, what single command can you run to test all the entries without rebooting?**

   Answer: mount -a

3. **Your system fails to boot because you put a wrong UUID in /etc/fstab. What boot parameter can you add to the kernel command line to boot into single user mode?**

   Answer: Add 'single' or '1' to the end of the kernel command line in the GRUB menu.

4. **What is the difference between the mount options 'auto' and 'noauto'?**

   Answer: 'auto' causes the filesystem to be mounted automatically at boot; 'noauto' means it will not mount at boot and must be mounted manually.

5. **Why should you use the UUID of a partition instead of the device name (like /dev/sdb1) in /etc/fstab?**

   Answer: Because device names can change when hardware is added or removed, while the UUID stays fixed, preventing boot failures.

---

Interactive version with quiz and diagrams: https://courseiva.com/learn/lf-lfcs/mounting-filesystems-and-using-fstab
