CrackOps
Interview PrepTracksLinuxAWS LabSoonInterview RoomSoon
Sign inStart free
CrackOps

Interview prep for the people who keep production up.

[email protected]
ProductInterview PrepTracksDashboardInterview Room
RolesDevOpsSREPlatformCloud
CompanyAboutContactPrivacyTerms
© CrackOps
Linux / Disk & Storage / mount

mount

Attach a filesystem to the directory tree

Intermediatediskfilesystemessential

mount attaches a filesystem (a disk, a partition, an NFS share, a tmpfs) to a directory so its files appear there. With no arguments it lists what is mounted; /etc/fstab tells the system what to mount at boot.

Syntaxmount [-t TYPE] [-o OPTIONS] DEVICE DIR | mount -a | mount

Watch it run

You want to see which devices are mounted where and with what options, without wading through dozens of pseudo filesystems.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
findmnt -t ext4,vfat

findmnt reads /proc/self/mountinfo and draws the tree: /boot/efi is mounted inside /boot, which is mounted inside /. -t filters by type so the 30-odd proc, sysfs, cgroup and tmpfs mounts are hidden.

Anatomy of a command

$
commandsudo

Mounting changes the system-wide tree, so it needs root (unless fstab marks the entry 'user').

How it works

mount resolves the source (UUID= and LABEL= through /dev/disk/by-uuid symlinks that udev maintains), detects the type with libblkid if -t is missing, then calls the kernel: the classic mount(2) syscall, or on util-linux 2.39 and newer kernels the fsopen/fsconfig/fsmount/move_mount API. The kernel finds the filesystem driver, reads and validates the superblock, replays the journal if the last shutdown was unclean, and creates a mount object that it attaches to the directory's dentry in your mount namespace. From then on every path lookup that reaches /archive crosses into the new filesystem; the old contents of the directory are hidden, not deleted. The result shows in /proc/self/mountinfo (findmnt reads it). At boot, systemd-fstab-generator turns each /etc/fstab line into a .mount unit; a missing device without nofail drops the machine into emergency mode.

A block device only becomes files and directories once the kernel reads its filesystem and attaches it to a directory in the tree.

NVMe attachmount dev dirmount(2)read superblockattachopen()at bootEBS volume100 GiB/dev/nvme2n1block deviceraw blocksYousudo mountmountutil-linuxKernel VFSext4 driver/archiveempty directoryAppwrites files/etc/fstabUUID=a7c3...
1/7
A volume appears

When the EBS volume is attached, the NVMe driver registers a block device and udev creates /dev/nvme2n1. It is just numbered blocks; there are no files yet.

← → to step

Options you'll actually use

(no args) / findmntList current mounts; findmnt shows a readable tree
-t TYPEFilesystem type: ext4, xfs, nfs4, tmpfs, vfat, iso9660...
-o OPTSComma-separated options: ro, rw, noatime, noexec, nosuid, nodev, nofail...
-aMount everything in /etc/fstab that isn't mounted yet (and not noauto)
-o remount,OPTSChange options of a mounted filesystem in place, e.g. remount,rw
--bind OLD NEWMake a directory tree visible at a second place
-o loopMount a filesystem image file through a loop device
-r / -wRead-only / read-write (same as -o ro / -o rw)
-vVerbose: say what was mounted where
findmnt --verifyCheck /etc/fstab for errors before you reboot

Common mistakes

/dev/nvme1n1 /data ext4 defaults 0 2 in /etc/fstab

NVMe device names follow discovery order and can change after a reboot or a new attachment, so the wrong disk may be mounted on /data.

UUID=5d1e7f3a-... /data ext4 defaults,nofail 0 2
Adding an fstab line and rebooting to test it

A typo or a missing device without nofail can drop the instance into emergency mode, and on EC2 you have no console keyboard by default.

sudo findmnt --verify && sudo mount -a
Copying files into /data while the volume isn't mounted

They land on the root filesystem and become hidden (but still use space) once the volume is mounted on top.

findmnt /data (or mountpoint /data) before writing
echo '...' >> /etc/fstab with sudo in front

The redirect is done by your unprivileged shell, so you get 'Permission denied'.

echo '...' | sudo tee -a /etc/fstab

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    List all mounted filesystems as a tree, then show only the mount holding /var/log. On a server you'd add -t ext4 to see only ext4 filesystems (the practice sandbox's root is an overlay, so that prints nothing there).

  2. 2

    Check /etc/fstab for errors without mounting or rebooting.

  3. 3

    Make ~/app visible read-only at /srv/app with a bind mount, and prove it's read-only. (May be refused in the sandbox; then write the commands.)

  4. 4

    Write an fstab line that mounts the filesystem with label 'archive' on /archive, without updating access times, and without blocking boot if the disk is missing.

Related commands

umountDetach a mounted filesystem safelylsblkList disks, partitions and where they are mountedblkidShow filesystem type, UUID and label of devicesdfReport used and free space per filesystemmkfsCreate a filesystem on a disk or partition
PreviousfdiskNextumount
Linux / Disk & Storage / mount

mount

Attach a filesystem to the directory tree

Intermediatediskfilesystemessential

mount attaches a filesystem (a disk, a partition, an NFS share, a tmpfs) to a directory so its files appear there. With no arguments it lists what is mounted; /etc/fstab tells the system what to mount at boot.

Syntaxmount [-t TYPE] [-o OPTIONS] DEVICE DIR | mount -a | mount

Watch it run

You want to see which devices are mounted where and with what options, without wading through dozens of pseudo filesystems.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 2
findmnt -t ext4,vfat

findmnt reads /proc/self/mountinfo and draws the tree: /boot/efi is mounted inside /boot, which is mounted inside /. -t filters by type so the 30-odd proc, sysfs, cgroup and tmpfs mounts are hidden.

Anatomy of a command

$
commandsudo

Mounting changes the system-wide tree, so it needs root (unless fstab marks the entry 'user').

How it works

mount resolves the source (UUID= and LABEL= through /dev/disk/by-uuid symlinks that udev maintains), detects the type with libblkid if -t is missing, then calls the kernel: the classic mount(2) syscall, or on util-linux 2.39 and newer kernels the fsopen/fsconfig/fsmount/move_mount API. The kernel finds the filesystem driver, reads and validates the superblock, replays the journal if the last shutdown was unclean, and creates a mount object that it attaches to the directory's dentry in your mount namespace. From then on every path lookup that reaches /archive crosses into the new filesystem; the old contents of the directory are hidden, not deleted. The result shows in /proc/self/mountinfo (findmnt reads it). At boot, systemd-fstab-generator turns each /etc/fstab line into a .mount unit; a missing device without nofail drops the machine into emergency mode.

A block device only becomes files and directories once the kernel reads its filesystem and attaches it to a directory in the tree.

NVMe attachmount dev dirmount(2)read superblockattachopen()at bootEBS volume100 GiB/dev/nvme2n1block deviceraw blocksYousudo mountmountutil-linuxKernel VFSext4 driver/archiveempty directoryAppwrites files/etc/fstabUUID=a7c3...
1/7
A volume appears

When the EBS volume is attached, the NVMe driver registers a block device and udev creates /dev/nvme2n1. It is just numbered blocks; there are no files yet.

← → to step

Options you'll actually use

(no args) / findmntList current mounts; findmnt shows a readable tree
-t TYPEFilesystem type: ext4, xfs, nfs4, tmpfs, vfat, iso9660...
-o OPTSComma-separated options: ro, rw, noatime, noexec, nosuid, nodev, nofail...
-aMount everything in /etc/fstab that isn't mounted yet (and not noauto)
-o remount,OPTSChange options of a mounted filesystem in place, e.g. remount,rw
--bind OLD NEWMake a directory tree visible at a second place
-o loopMount a filesystem image file through a loop device
-r / -wRead-only / read-write (same as -o ro / -o rw)
-vVerbose: say what was mounted where
findmnt --verifyCheck /etc/fstab for errors before you reboot

Common mistakes

/dev/nvme1n1 /data ext4 defaults 0 2 in /etc/fstab

NVMe device names follow discovery order and can change after a reboot or a new attachment, so the wrong disk may be mounted on /data.

UUID=5d1e7f3a-... /data ext4 defaults,nofail 0 2
Adding an fstab line and rebooting to test it

A typo or a missing device without nofail can drop the instance into emergency mode, and on EC2 you have no console keyboard by default.

sudo findmnt --verify && sudo mount -a
Copying files into /data while the volume isn't mounted

They land on the root filesystem and become hidden (but still use space) once the volume is mounted on top.

findmnt /data (or mountpoint /data) before writing
echo '...' >> /etc/fstab with sudo in front

The redirect is done by your unprivileged shell, so you get 'Permission denied'.

echo '...' | sudo tee -a /etc/fstab

Interview questions

Practice

Try these on a Linux machine of your own. Each task has a hint and a solution.

  1. 1

    List all mounted filesystems as a tree, then show only the mount holding /var/log. On a server you'd add -t ext4 to see only ext4 filesystems (the practice sandbox's root is an overlay, so that prints nothing there).

  2. 2

    Check /etc/fstab for errors without mounting or rebooting.

  3. 3

    Make ~/app visible read-only at /srv/app with a bind mount, and prove it's read-only. (May be refused in the sandbox; then write the commands.)

  4. 4

    Write an fstab line that mounts the filesystem with label 'archive' on /archive, without updating access times, and without blocking boot if the disk is missing.

Related commands

umountDetach a mounted filesystem safelylsblkList disks, partitions and where they are mountedblkidShow filesystem type, UUID and label of devicesdfReport used and free space per filesystemmkfsCreate a filesystem on a disk or partition
PreviousfdiskNextumount