9

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
tarabyte
  • 2,585

2 Answers2

8

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.

grawity
  • 501,077
5

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.

Vojtech
  • 1,272
  • 9
  • 6