Monday, May 6, 2024
25
rated 0 times [  25] [ 0]  / answers: 1 / hits: 40800  / 3 Years ago, thu, september 16, 2021, 10:49:30

How can I trigger an automount from the command line? By "automount" I don't mean fully automatic mounting, but getting a list of available devices and then selecting one and having it end up as /media/{user}/{diskid}. This functionality is provided by Nautilus or Thunar for example, but I can't seem to find a command line tool to trigger this kind of semi automatic mount.



pmount is the closest I have found, but seems to work by completely different mechanics underneath and makes devices show up as /media/sdf or something along the lines.


More From » command-line

 Answers
7

gio mount



gvfs is now listed as deprecated (2018) and you are advised to use 'gio' which is Gnome In Out and part of Glib. See Wikipedia.



For example, to auto-mount a second drive partition; create a bash script with executable permission to run at start-up with the following command:



gio mount -d /dev/sda2


If you are owner of the partition (see chown) you won't need sudo.



To mount an ISO file located for example on ~/ISOs:



gio mount "archive://file%3A%2F%2F%2Fhome%2Fpablo%2FISOs%2Fubuntu-18.04-desktop-amd64.iso"


You could URL encode the path with Python 3 and realpath (to concatenate to archive://:



python -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1] if len(sys.argv) > 1 else sys.stdin.read()[0:-1], ""))" "file://$(realpath ubuntu-18.04-desktop-amd64.iso)"


This will mount on /run/user/$(id -u)/gvfs/ .



As an alternative gnome-disk-image-mounter will moount on /media/$USER/.



To unmount use gio mount -u /run/user/$(id -u)/gvfs/archive* (or /media/$USER/, depending the way you mounted).



udisksctl



Listing available devices:



udisksctl status


Mounting is done via:



udisksctl mount -b /dev/sdf


or



udisksctl mount -p block_devices/sdf


Unmounting is done via:



udisksctl unmount -b /dev/sdf


or



udisksctl unmount -p block_devices/sdf


The object-path can be found out by doing:



udisksctl dump


Object of type org.freedesktop.UDisks2.Block seem to be valid as object-patch, the /org/freedesktop/UDisks2/ prefix has to be cut from the path for udisksctl to accept them.



gvfs-mount



Listing available devices can be done with:



gvfs-mount --list


Mounting them can be done with:



gvfs-mount -d /dev/sdf


Unmounting is possible via:



gvfs-mount --unmount /media/user/01234567890


One remaining problem is that I have no idea how to use the gvfs-mount --list output in a mount command, as --list won't show block device names and trying to use the device names it prints in a mount will result in:



Error mounting location: volume doesn't implement mount


Conclusion



While both gvfs-mount and udisksctl will work for the tasks, their interface is impractical as they don't provide human readable status of the disks available, just an overly verbose info dump.


[#29584] Friday, September 17, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
homerurhyth

Total Points: 338
Total Questions: 113
Total Answers: 105

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
;