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.
You can use:
where
device_name
is the name of a storage device and should look something like/dev/sdb1
.Using
lsblk
orsudo fdisk -l
command you can find out all storage devices attached to your system.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:
If you are owner of the partition (see
chown
) you won't need sudo.To mount an ISO file located for example on
~/ISOs
:You could URL encode the path with Python 3 and
realpath
(to concatenate toarchive://
: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:
Mounting is done via:
or
Unmounting is done via:
or
The
object-path
can be found out by doing:Object of type
org.freedesktop.UDisks2.Block
seem to be valid asobject-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:
Mounting them can be done with:
Unmounting is possible via:
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:Conclusion
While both
gvfs-mount
andudisksctl
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.A simple solution that works as required (mounts to /media/{user}/{diskid}) except that it can not list devices but needs to be given the exact, case sensitive, volume label as argument $1
To mount:
To unmount:
Just ran into the issue myself, and found the following solution:
It will ask for the user password, even if it's you and you're already logged in.
I wrote this Bash script to work around this problem, but be aware that I'm a scripting newbie. All suggestions welcome! Usage and description follow below the script.
Usage:
The script accepts as an argument the label of the partition you want to mount and looks in the udisksctl dump for corresponding entries.
If a partition is found and it's not mounted, device name and path are shown and you're offered to mount the partition. The script searches for partial labels too, and it won't care about upper or lower case (useful when you don't remember the exact label).
If a partition is found and it's already mounted, you're offered to unmount it:
If your argument matches more than a result, the script shows you the matching partition labels and asks you to refine the search:
Script to mount drive -
mount-menu.sh
The
mount-menu.sh
script allows you to select unmounted drives/partitions for mounting. To call the script use:sudo mount-menu.sh
. This screen appears tailored to your unique machine environment:The menu clears and leaves this information in your terminal:
Now you can use:
cd /mnt/mount-menu.FPRAW
to access your external drive's partition.Then you can use
cd home/YOUR_NAME
being mindful not to put a/
in front ofhome
. Should you usecd /home
it would take you to your boot drive and out of the external drive.mount-menu.sh
script contentsTo create the script open the terminal and type:
Then copy the code below and paste it into
gedit
. Save the file and exitgedit
.Now mark the file as executable using:
Here's the script to copy:
umount-menu.sh
to Unmount Drives/PartitionsRepeat the file creation / execute bit marking process for the script
umount-menu.sh
. This script only unmounts drives / partitions that were mounted bymount-menu.sh
. It has the same selection menu and completes with the message:To call the script use:
sudo umount-menu.sh
umount-menu.sh
bash script: