4

Is there a more-correct way to unmount a device/filesystem/etc? Should I umount the device I originally mounted or the mount point?

mount /dev/sda1 /mnt/myusbstick
do stuff
umount /mnt/myusbstick

OR

umount /dev/sda1

2 Answers 2

6

On Linux, the recommended way (according to the util-linux maintainers)[citation neeed] is to use umount <mountpoint>, for several reasons:

  • The same device may be mounted on multiple locations, e.g. using bind mounts, btrfs subvolumes, or FUSE filesystems; you don't know which one would be unmounted first.

    (You can use umount --all-targets <device> though.)

  • A mount might have multiple backing devices, for filesystems such as btrfs, and umount won't necessarily understand all of them (as the mtab & mountinfo files only show one).

  • The backing device might be not what you think it is. For example, mount foo.iso /mnt will set up a loop device and mount that. (Though, luckily, umount foo.iso is also smart enough to look up the corresponding loop device.)

  • You can stack several mounts on the same location, with only the latest one being visible.

2
  • 1
    and can you clarify which is the mount point? e.g a or b of mount a b?
    – tarabyte
    Nov 12, 2015 at 17:34
  • 1
    The mountpoint is the directory, so b.
    – Tom Hale
    Sep 5, 2017 at 10:34
3

It doesn't matter which way you refer to the mount.

The only case where it makes a difference is when you have a device mounted to multiple mount points. In that case when you specify the device to the umount command, it'll unmount the most recently mounted mountpoint. Specifying a mountpoint will allow unmounting that specific mountpoint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.