Hi,
I am trying to mount a USB drive to given symlink and mount it to a given mount point.
Mount is working but when the device removed, I can still see the mount
cat /etc/udev/rules.d/81-hnt-usb-rule.rules
ACTION="" KERNEL=="sd?1", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", \
SYMLINK+="hanthana%n", ENV{SYSTEMD_WANTS}="hnt-usb-rule.service"
ACTION="" RUN+="/usr/bin/umount $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')"
------------------------------------------------------------------------------------------------
[danishka@hanthana ~]$ cat /etc/systemd/system/hnt-usb-rule.service
[Unit]
Description=USB Mount
[Service]
Type=oneshot
ExecStart=/root/hnt.sh
[Install]
WantedBy=default.target
----------------------------------------------------------------------------------------------------------
cat /root/hnt.sh
#!/bin/bash
mkdir /backup
lsblk > /var/log/hnt.log
/usr/bin/mount /dev/hanthana1 /backup
------------------------------------------------------------------------------------------------
ACTION="" RUN+="/usr/bin/umount $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')"
[root@hanthana ~]# echo $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')
/dev/sda1
ACTION="" KERNEL=="sd?1", SUBSYSTEM=="block", ENV{ID_BUS}=="usb", \
SYMLINK+="hanthana%n", ENV{SYSTEMD_WANTS}="hnt-usb-rule.service"
ACTION="" RUN+="/usr/bin/umount $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')"
------------------------------------------------------------------------------------------------
[danishka@hanthana ~]$ cat /etc/systemd/system/hnt-usb-rule.service
[Unit]
Description=USB Mount
[Service]
Type=oneshot
ExecStart=/root/hnt.sh
[Install]
WantedBy=default.target
----------------------------------------------------------------------------------------------------------
cat /root/hnt.sh
#!/bin/bash
mkdir /backup
lsblk > /var/log/hnt.log
/usr/bin/mount /dev/hanthana1 /backup
------------------------------------------------------------------------------------------------
ACTION="" RUN+="/usr/bin/umount $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')"
[root@hanthana ~]# echo $(/usr/bin/mount | grep backup | /usr/bin/awk '{print $1}')
/dev/sda1
Even though you can't access /backup after removing the USB, mount command shows following results (After plugin the usb and remove several times). I wonder why it automatically remove these entries as fedora normally mount USBs on default location.
/dev/sda1 on /backup type ext4 (rw, relatime, seclabel)
/dev/sdb1 on /backup type ext4 (rw, relatime, seclabel)
/dev/sdc1 on /backup type ext4 (rw, relatime, seclabel)
/dev/sdd1 on /backup type ext4 (rw, relatime, seclabel)
I was testing on both Fedora 28 Gnome and LXDE.
Regards,
--
Danishka Navin
_______________________________________________ users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/users@xxxxxxxxxxxxxxxxxxxxxxx