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 / umount

umount

Detach a mounted filesystem safely

Beginnerdiskfilesystemtroubleshooting

umount detaches a filesystem from the directory tree, after flushing its pending writes to disk. You need it before detaching a volume, running fsck, or resizing, and the most common thing you'll see is 'target is busy'.

Syntaxumount [OPTIONS] DIR|DEVICE

Watch it run

You're about to detach the archive volume in the AWS console and must unmount it cleanly first.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
sudo umount -v /archive

Dirty data is flushed and the superblock is marked clean. The volume can now be detached safely.

Anatomy of a command

$
commandsudo

Unmounting needs root, like mounting (unless fstab marks the entry 'user').

How it works

umount calls the umount2() system call on the mount point. The kernel first checks whether the mount is still in use: any open file on it, a process whose current directory or root is inside it, a memory-mapped file, a swap file, or another filesystem mounted below it. If so it returns EBUSY and nothing changes. Otherwise it writes back all dirty pages and metadata for that filesystem, marks the superblock clean (so the next mount or boot won't force a check), and removes the mount from the tree; the directory's original contents become visible again. umount -l (lazy) detaches the mount from the tree right away and lets the kernel finish the cleanup when the last user goes away. umount -f is meant for unreachable NFS servers and does little for local disks. Detaching an EBS volume without unmounting is like pulling a USB stick: unflushed writes are lost.

Options you'll actually use

-vVerbose
-lLazy: detach now, clean up when no longer busy
-fForce; mainly for unreachable NFS servers
-RRecursively unmount everything below the mount point too
-aUnmount everything in /proc/self/mounts (used at shutdown)
-t TYPEWith -a: only filesystems of this type (e.g. -a -t nfs4)
-rIf unmounting fails, try to remount read-only
fuser -vm DIRCompanion: list processes using the mount
lsof +f -- DIRCompanion: list open files on that filesystem

Common mistakes

Detaching an EBS volume in the console while it's mounted

Unflushed writes are lost and the filesystem is left dirty; the instance may log I/O errors and hang processes.

sudo umount /data, remove or nofail the fstab line, then detach
Reaching for umount -l every time umount says busy

Lazy unmount hides the problem: processes keep writing to a filesystem you think is gone, and the device stays in use.

sudo fuser -vm /data (or lsof +f -- /data), stop those processes, then umount
Running umount /data from a shell whose current directory is /data

Your own shell keeps it busy.

cd ~ && sudo umount /data

Interview questions

Practice

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

  1. 1

    Check whether /mnt is a mount point, the way a script would.

  2. 2

    Write the commands to find which processes keep /data busy and then unmount it.

  3. 3

    Write the command that unmounts /mnt/rescue together with everything mounted below it.

Related commands

mountAttach a filesystem to the directory treelsofList open files, sockets and the processes holding themfsckCheck and repair a filesystemdfReport used and free space per filesystem
PreviousmountNextmkfs
Linux / Disk & Storage / umount

umount

Detach a mounted filesystem safely

Beginnerdiskfilesystemtroubleshooting

umount detaches a filesystem from the directory tree, after flushing its pending writes to disk. You need it before detaching a volume, running fsck, or resizing, and the most common thing you'll see is 'target is busy'.

Syntaxumount [OPTIONS] DIR|DEVICE

Watch it run

You're about to detach the archive volume in the AWS console and must unmount it cleanly first.

devops@devops-lab: ~ — zsh — 96×28
➜ ~
Step 1 of 3
sudo umount -v /archive

Dirty data is flushed and the superblock is marked clean. The volume can now be detached safely.

Anatomy of a command

$
commandsudo

Unmounting needs root, like mounting (unless fstab marks the entry 'user').

How it works

umount calls the umount2() system call on the mount point. The kernel first checks whether the mount is still in use: any open file on it, a process whose current directory or root is inside it, a memory-mapped file, a swap file, or another filesystem mounted below it. If so it returns EBUSY and nothing changes. Otherwise it writes back all dirty pages and metadata for that filesystem, marks the superblock clean (so the next mount or boot won't force a check), and removes the mount from the tree; the directory's original contents become visible again. umount -l (lazy) detaches the mount from the tree right away and lets the kernel finish the cleanup when the last user goes away. umount -f is meant for unreachable NFS servers and does little for local disks. Detaching an EBS volume without unmounting is like pulling a USB stick: unflushed writes are lost.

Options you'll actually use

-vVerbose
-lLazy: detach now, clean up when no longer busy
-fForce; mainly for unreachable NFS servers
-RRecursively unmount everything below the mount point too
-aUnmount everything in /proc/self/mounts (used at shutdown)
-t TYPEWith -a: only filesystems of this type (e.g. -a -t nfs4)
-rIf unmounting fails, try to remount read-only
fuser -vm DIRCompanion: list processes using the mount
lsof +f -- DIRCompanion: list open files on that filesystem

Common mistakes

Detaching an EBS volume in the console while it's mounted

Unflushed writes are lost and the filesystem is left dirty; the instance may log I/O errors and hang processes.

sudo umount /data, remove or nofail the fstab line, then detach
Reaching for umount -l every time umount says busy

Lazy unmount hides the problem: processes keep writing to a filesystem you think is gone, and the device stays in use.

sudo fuser -vm /data (or lsof +f -- /data), stop those processes, then umount
Running umount /data from a shell whose current directory is /data

Your own shell keeps it busy.

cd ~ && sudo umount /data

Interview questions

Practice

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

  1. 1

    Check whether /mnt is a mount point, the way a script would.

  2. 2

    Write the commands to find which processes keep /data busy and then unmount it.

  3. 3

    Write the command that unmounts /mnt/rescue together with everything mounted below it.

Related commands

mountAttach a filesystem to the directory treelsofList open files, sockets and the processes holding themfsckCheck and repair a filesystemdfReport used and free space per filesystem
PreviousmountNextmkfs