Disk Mounting

Monday, Feb 1, 2021
#unix #tips

udisks is a lovely tool for removable drive mounting on linux. The UNIX model is much older than flashdrives and sd cards. As a result, the procress of creating a “mount point” and manually mounting your drives feels pretty jank. Instead, the udisks tool (or now udisks2) can be used to allow your normal user account to automatically create a mount point, mount your flashdrive, and set the correct permissions when you plug in your flashdrive. It relies on d-bus – so the daemon will be started and stopped when needed. You probably don’t need to enable it manually. If you’re having issues you might need to add your user to a storage group. You can cat /etc/group to see a list of available groups on your system.

By default udisks doesn’t “automatically mount” your drives. Instead, you run a command to mount a new flashdrive and later one to unmount it. Personally, I prefer this as I often want to format flashdrives rather than mounting them. It’s also a good idea to leave it off to prevent security exploits that take advantage of automount. However, if you would like automount – like most of the graphical distributions have by default, just install a udisks wrapper such as udiskie, udevil, or a desktop environment like GNOME or KDE that includes a wrapper.

These are the commands to mount and unmount.

udisksctl mount -b
udisksctl unmount -b

I created an mnt and umnt alias for them.

Update - 2020/02/23

I accidentally wrote /etc/passwd as the file with a list of available secondary groups, I meant to write /etc/group. For reference /etc/passwd contains a list of users, including their primary group and login shell. /etc/shadow is the location with your user’s hashed passwords and is normally read/write only by root and sometimes the shadow group. Henry pointed this out. Thanks!