Given a mountpoint (directory) name, how do I start / stop the systemd
automounter only on that mountpoint?
I want a solution which works even if the mountpoint:
- is currently mounted
- has
[^0-9A-Za-z]
characters in the pathname
Given a mountpoint (directory) name, how do I start / stop the systemd
automounter only on that mountpoint?
I want a solution which works even if the mountpoint:
[^0-9A-Za-z]
characters in the pathnameIIRC this was added relatively recently, but it sounds like you might want to use systemd-mount --umount WHERE
. Making sure WHERE is passed correctly in the scripting language of your choice is your problem :).
Or you should be able to use the regular umount
command. systemd picks up unmounts using kernel events or something, so you won't end up with a misleading status on the corresponding .automount
unit.
systemd-umount
can be used to unmount a mount or automount point. It is the same as systemd-mount --unmount
– Tom Hale
Sep 05 '17 at 15:40
Discovery only supported for block devices, don't know what to do.
Any tips?
– Tom Hale
Sep 05 '17 at 15:47
--discover
shouldn't apply to unmount. "Or you should be able to use the regular umount
command."
– sourcejedi
Sep 05 '17 at 15:59
umount -vt autofs /media/backup
has weird behaviour - somtimes it says umount: /media/backup (systemd-1) unmounted
and sometimes umount: /media/backup unmounted
. In the latter case, it actually mounts the mountpoint!
– Tom Hale
Sep 05 '17 at 16:03
systemd-umount WHERE
does not work"
– sourcejedi
Sep 06 '17 at 15:18
Here is an example expressed in shell.
MOUNT="/media/backup"
MOUNT_UNIT="$(systemctl show --property=Id "$MOUNT" | sed -e s/^[^=]*=// )"
AUTOMOUNT_UNIT="$(echo "$MOUNT_UNIT" | sed -e s/[.]mount$/.automount/)"
systemctl stop "$AUTOMOUNT_UNIT"
To try and answer this question completely, you could instead use systemd-escape
to generate the unit name, as described in the answer to the linked question.
media-backup.automount
will need to be stopped as well. See this question which hopes for a more generic way of converting a path into a unit file name.
– Tom Hale
Sep 05 '17 at 16:21
.automount
without unmounting the currently mounted filesystem.
– Tom Hale
Nov 19 '17 at 13:22
With thanks to this answer:
#!/bin/bash
if [ $# -ne 1 ]; then
{
printf "Stop systemd automount at <mountpoint>\n" "${0##*/}"
printf "Usage: %s <mountpoint>\n" "${0##*/}"
} >&2
exit 1
fi
MOUNT=$1
sudo systemctl stop "$(systemd-escape -p --suffix=automount "$MOUNT")"
systemctl
and stop it. – Tom Yan Sep 06 '17 at 02:19.automount
has unexpected behaviour – Tom Hale Sep 06 '17 at 06:35.automount
without unmounting the currently mounted filesystem – Tom Hale Nov 19 '17 at 13:23