Minimalism in removable drive handling
Learn how to handle USB devices without GVFS/Dolphin
GNOME, Cinnamon, MATE, XFCE and various other desktop environments use udisks2 and GVFS to handle external devices from file managers. GVFS is bloat, not installed on my system. KDE Dolphin is a better solution but it's still considered bloat because it depends on baloo and packagekit. In this post, I explain how to handle USB devices or memory cards without GVFS/Dolphin. It's a CLI workflow, no GUI. I use polkit rules to allow udisks2 to mount/unmount devices without authentication for users in the plugdev group.
WARNING
The suckless.org community and Hyperbola don't recommend udisks because it's bloat, unsecure. However better alternatives require advanced knowledge of fstab and mount options. In addition, only udisks can power-off external hard disk drive on Linux. Consider BSDs' bsdisks if you need a perfect alternative. GhostBSD xfce edition is user-friendly and can do it.
Create a file called udisks2.rules with this content:
polkit.addRule(function(action, subject) {
var YES = polkit.Result.YES;
var permission = {
"org.freedesktop.udisks2.filesystem-mount": YES,
"org.freedesktop.udisks2.encrypted-unlock": YES,
"org.freedesktop.udisks2.eject-media": YES,
"org.freedesktop.udisks2.power-off-drive": YES,
"org.freedesktop.udisks2.filesystem-mount-system": YES,
"org.freedesktop.udisks2.filesystem-unmount-others": YES
};
if (subject.isInGroup("plugdev")) {
return permission[action.id];
}
});
Move this file to /etc/polkit-1/rules.d/ Now, open a terminal and plug a USB stick. Type lsblk to find the device id. Let's say /dev/sdc. Enter the following command to mount it to /media/yourusername/label
udisksctl mount -b /dev/sdc1
You can see the label in most file explorers. If you use Midnight Commander like I do, then I recommend to bookmark /media/yourusername/ for quick access. Let's say the label is EMTEC-BLUE.
Then unmount it:
udisksctl unmount -b /dev/disk/by-label/EMTEC-BLUE
Congratulation! You are one step closer to suckless.org users.