Skip to content

Linux Foundations / Understand the system underneath ยท Step 6 of 38

Lesson: mount and umountSwitch
โ† Linux Foundations

System administration

mount and umount

Attach filesystems to the directory tree and detach them safely.

A filesystem on a partition is not usable until it is mounted: attached to a directory in the tree. That directory is the mount point.

Mounting

Create an empty directory, then mount the partition on it:

$ sudo mkdir -p /mnt/data
$ sudo mount /dev/sdb1 /mnt/data
$ ls /mnt/data
lost+found

The lost+found directory is normal on a new ext4 filesystem.

If the mount point already contains files, they are hidden while something is mounted there. They are not deleted, and they reappear after unmounting.

mount usually detects the filesystem type. You can state it with -t, and pass options with -o:

$ sudo mount -t ext4 -o ro,noexec /dev/sdb1 /mnt/data

ro means read-only and noexec blocks running programs directly from that filesystem.

You can also mount by UUID or label, which does not depend on device naming:

$ sudo mount UUID=5ef4138f-5574-4227-8c74-58be9b62c010 /mnt/data
$ sudo mount LABEL=data /mnt/data

Seeing what is mounted

$ findmnt /mnt/data
TARGET    SOURCE    FSTYPE OPTIONS
/mnt/data /dev/sdb1 ext4   rw,relatime

Plain findmnt shows the whole tree. mount with no arguments prints a long list too.

Unmounting

The command is umount, with no first "n":

$ sudo umount /mnt/data

You can give the mount point or, in simple cases, the device. Unmounting writes any pending data to disk, so do it before unplugging removable media.

Target is busy

$ sudo umount /mnt/data
umount: /mnt/data: target is busy.

Something is still using it: perhaps a shell whose current directory is inside, or a program with an open file. Find it with:

$ sudo fuser -vm /mnt/data
$ sudo lsof /mnt/data

These tools may need installing. Leave the directory or stop the program, then retry. There is also umount -l (lazy), which detaches now and cleans up later. Use it with care, since programs may still be writing.

Mounts made with mount last only until reboot. For permanent ones, use /etc/fstab.

Try it

On a spare machine or VM, mount a tmpfs, which needs no disk:

$ sudo mkdir /mnt/ram
$ sudo mount -t tmpfs -o size=50M tmpfs /mnt/ram
$ findmnt /mnt/ram
$ sudo umount /mnt/ram

Check your understanding

mount and umount

All 5 sections ยท no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.