Umount device or mount point

mountumount

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

Best Answer

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.

Related Question