I configured an automount for a USB drive by adding an extra rule to /etc/fstab as belows
/dev/sda1 /media vfat noauto,nofail,x-systemd.automount,x-systemd.idle-timeout=2,x-systemd.device-timeout=2 This entry is then picked by systemd's fsab-generator to create two unit files for mount and automount of /dev/sda1:
- media.automount
- media.mount
Once inserted, the USB drive is mounted correctly into the mount point as specified. This is verified by running ls /media. The output of journalctl is:
Sep 17 13:19:55 pcxx systemd[1]: Mounted /media. Sep 17 13:19:57 pcxx systemd[1]: Unmounting /media... Sep 17 13:19:57 pcxx systemd[1]: Unmounted /media. 1. Why does systemd unmount /media right after mounting it?
The aim is to be able to cleanly unmount the USB drive, after using it.
I found out there are two ways to do it.
The first one is to run umount /media. This does the job but does corrupt media.automount service. The error message observed in journalctl and when running systemctl status -l media.automount is:
Sep 17 13:28:44 pcxx systemd[1]: media.automount: Got invalid poll event 16 on pipe (fd=59) Sep 17 13:28:44 pcxx systemd[1]: media.automount: Failed with result 'resources'. The second one is to run systemd's umount command systemd-umount /media. This also does the job but stops both media.mount and media.automount services. The consequence of this being not able to automount when the next USB drive is inserted, which defeats the purpose of having automount in the first place.
2. Is there a proper way to unmount a drive whose automount is handled by systemd without stopping the automount service?