LAB-FS-05 - Device Files & Mounting
Device Files & Mounting
Understand how Linux represents physical hardware as files in /dev, and how to mount storage devices into the unified filesystem tree.
- Understand how Linux represents physical hardware as files in /dev, and how to mount storage devices into the unified filesystem tree.
- Repeat the workflow without copy-paste or step-by-step prompting.
- Use a disposable practice directory so accidental edits do not touch personal files.
Part A: The Field Guide
🎯 What & Why
We said earlier that Linux doesn’t have C:\ or D:\ drives. Everything is mapped into the single / root tree.
So what actually happens when you plug a USB drive into a Linux machine?
Two things happen:
- The Device File: The kernel detects the hardware and creates a magical “device file” inside the
/devdirectory. This file is the physical hardware. If you write data into this file, you are writing raw 1s and 0s directly to the metal of the USB drive. - The Mount Point: Because the single
/tree has nowhere to “put” the USB drive automatically, you (or the desktop environment) must create an empty folder somewhere (like/mnt/usb), and tell the kernel: “Take the raw hardware in/dev, format it into files/folders, and attach it to this empty directory.” This is called Mounting.
If you master /dev and mounting, you master storage on Linux.
🧠 Mental Model: The Doorway
Think of a physical hard drive as a massive windowless warehouse full of chaotic metal filing cabinets.
/dev/sda1is the physical external wall of the warehouse. You can throw raw data at the brick wall, but there’s no organization./mnt/my-drive(The Mount Point) is an empty doorway you built inside your house.mountis the magic spell that connects your empty doorway directly into the organized interior of the warehouse.
Once mounted, whenever you walk into /mnt/my-drive, you are actually walking inside the physical hard drive. When you are done, you umount it to close the doorway safely.
📖 Key Concepts in /dev
The Naming Convention
Linux names hard drives predictably.
SATA / USB Drives (sd = SCSI disk):
sda= First hard drive.sdb= Second hard drive.sda1= First partition on the first hard drive.sda2= Second partition on the first hard drive.
NVMe SSDs:
nvme0n1= First NVMe drive.nvme0n1p1= First partition on the first NVMe drive.
Virtual Machines:
vdaorxvda= Virtual disks.
Special Pseudo-Devices
Not everything in /dev is a hard drive. Some are kernel tools.
/dev/null: The Black Hole. Anything written here is immediately deleted forever. (echo "hello" > /dev/null)/dev/zero: The Infinite Zero Generator. Reading from here produces an endless stream of0bytes. Great for wiping hard drives./dev/urandom: The Chaos Generator. Reading from here produces an endless stream of random garbage data.
📖 Command Reference
lsblk — List Block Devices
The foundational command for storage. It visually maps physical drives (sda) to partitions (sda1) and shows where they are currently mounted.
$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 49.9G 0 part / └─sda14 8:14 0 4M 0 part sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part /mnt/data
mount — Attach hardware to the tree
Syntax: mount [DEVICE] [DIRECTORY]
$ # 1. Identify the new USB drive $ lsblk
(You see sdc1 is a new 16GB partition, currently unmounted)
$ # 2. Create an empty directory acting as the doorway $ sudo mkdir /mnt/usb
$ # 3. Attach the hardware to the doorway $ sudo mount /dev/sdc1 /mnt/usb
umount — Detach hardware (Safely Remove)
Syntax: umount [DIRECTORY_OR_DEVICE]
$ # Tell Linux to sync all data and close the doorway $ sudo umount /mnt/usb
⚠️ The “Target is Busy” Error
If you try to umount /mnt/usb while you are currently cd’d inside that directory (or any other program is reading a file there), Linux will refuse and say “Target is busy”.
Fix: cd ~ to leave the directory, then try unmounting again.
🌍 Real Scenarios
Scenario 1: Silencing a noisy script You have a script that outputs tons of useless text. You don’t want to see it.
$ ./noisy_script.sh > /dev/null
# All output is redirected into the black hole. Silent execution.
Scenario 2: Adding a terabyte data drive
You install a physical 1TB hard drive. Linux detects it as /dev/sdb. You format it (mkfs.ext4 /dev/sdb), create a folder (mkdir /data), mount it (mount /dev/sdb /data), and then add a line to /etc/fstab so it mounts automatically on the next reboot.
Scenario 3: Securely wiping a hard drive
You are throwing away an old server. You want to overwrite the entire second hard drive (/dev/sdb) with zeros so the data cannot be recovered.
# Take infinite zeros from /dev/zero, and write them directly over the raw device /dev/sdb
# DO NOT DO THIS TO YOUR MAIN DRIVE!
$ sudo dd if=/dev/zero of=/dev/sdb bs=1M
Part B: The Drill Deck
Terminal Required: Open your Linux terminal for these exercises.
G Guided Step by step - type exactly this and compare the result >
Exercise G1: The Disk Map
- Open your terminal. Let’s see your physical layout.
- Run:
lsblk - Identify your root partition (look under the
MOUNTPOINTcolumn for/). What is the device name associated with it? (e.g.,sda1,nvme0n1p2,vda1). - Run:
lsblk -f. This shows the filesystem types (ext4, xfs, vfat) and UUIDs of the drives.
Exercise G2: Throwing data into the void
- We are going to use the black hole device.
- Run a command that produces a lot of output, like
ls -laR /var/log(Recursive list of all logs). It floods your screen. - Run it again, but redirect the standard output (
>) into the black hole:ls -laR /var/log > /dev/null - Notice the silence. (If you still see “Permission denied” errors, it’s because those are Standard Error (2), not Standard Output (1). To silence both:
> /dev/null 2>&1).
Exercise G3: The Chaos Generator
- We are going to read from
/dev/urandom. Because it produces an infinite stream of random binary gibberish, we must pipe it throughheadto only grab a small piece. - Run:
head -c 50 /dev/urandom - You will see 50 characters of absolute garbage (which might break your terminal formatting temporarily). This is how Linux generates secure random numbers for encryption keys!
S Solo Task described, hints available - figure it out >
Exercise S1: Inspecting the Device Files
- Navigate to the devices folder:
cd /dev - Run
ls -l sda*orls -l nvme*to see your primary hard drive device files. - Look at the very first character of the permissions string on the left. Normal files start with
-. Directories start withd. These device files start withborc.bstands for Block device (hard drives).cstands for Character device (mice, keyboards,/dev/null). - Who owns these device files? (Look at the owner/group columns. Usually
rootanddisk). This is why you needsudoto mount them!
Exercise S2: Creating a Mount Point
- In your home directory, create an empty folder:
mkdir ~/mock_usb - Run
ls -la ~/mock_usb. It is completely empty (except for.and..). - In a real scenario, this is the exact “doorway” you would provide to the
mountcommand to attach a physical/dev/sdb1drive. You do not need to execute the mount command for this exercise.
M Mission Real scenario - no hints, combine multiple skills >
Mission M1: The ISO Loop Mount (Advanced)
Sometimes you download a massive .iso file (like a Linux installation CD). An ISO is just an image of a filesystem. You can mount files exactly the same way you mount hardware, using a “loop” device!
- Download a tiny, safe floppy image (or text file masquerading as one) or skip to mental visualization if you don’t have one. Let’s simulate the mental workflow:
- You have
/home/user/ubuntu.iso. - You create the doorway:
mkdir /mnt/cdrom - You mount the file as if it were hardware:
sudo mount -o loop /home/user/ubuntu.iso /mnt/cdrom - You can now
cd /mnt/cdromand read the files inside the ISO!
What command would you run to safely close this doorway and detach the ISO file when you are done?