You are not logged in.

#1 2015-03-06 12:21:17

grafzakenbarsch
Member
Registered: 2015-03-06
Posts: 11

systemd does not umount in spite of StopWhenUnneeded=true

Before going into details I have to say that although I am a seasoned Linux user, I am a noob to both systemd and Arch.

My goal is to setup a backup routine that starts automatically upon connection of the relevant USB storage which cleans up after itself (i.e.: umounts).

With the help of this resource, I got the first half running. But systemd does not umount.

This is the code:

  • /etc/udev/rules.d/00-luks-usb.rules

    ACTION=="add", \
    KERNEL=="sd*", \
    SUBSYSTEM=="block", \
    ATTRS{manufacturer}=="Western Digital", \
    ATTRS{serial}=="theserial", \
    ATTRS{product}=="Elements 1078", \
    SYMLINK="schwarzeplatte%n", \
    RUN+="/sbin/cryptsetup luksOpen $env{DEVNAME} schwarzeplatte --key-file /home/user/Dokumente/arbeiten/keys/usbbackup.lukskey", \
    TAG+="systemd", \
    ENV{SYSTEMD_WANTS}="usbbackup.service"
    
    ACTION=="remove", \
    ENV{ID_SERIAL}=="theserial", \
    RUN+="/sbin/cryptsetup luksClose schwarzeplatte"
  • /etc/systemd/system/usbbackup.service

    [Unit]
    Description=script to backup user data onto encrypted external USB storage
    BindsTo=dev-mapper-schwarzeplatte.device var-run-media-user-schwarzeplatte.mount
    After=dev-mapper-schwarzeplatte.device var-run-media-user-schwarzeplatte.mount
    RefuseManualStart=true
    
    [Service]
    ExecStart=/usr/local/sbin/usbbackup.sh
  • /etc/systemd/system/var-run-media-user-schwarzeplatte.mount

    [Unit]
    DefaultDependencies=no
    Conflicts=umount.target
    Before=umount.target
    StopWhenUnneeded=true
    
    [Mount]
    What=/dev/mapper/schwarzeplatte
    Where=/var/run/media/user/schwarzeplatte/
    Type=ext4
  • /etc/fstab

    /dev/mapper/schwarzeplatte      /var/run/media/user/schwarzeplatte/     ext4    noauto,x-systemd.automount,x-systemd.device-timeout=10  0 2
  • /etc/crypttab

    schwarzeplatte UUID=the-uuid    /home/user/Dokumente/arbeiten/keys/usbbackup.lukskey        luks,noauto

The unit dev-mapper-schwarzeplatte is created automatically.

I searched for where dependencies might be and tried the following, but it did not lead me to anything.

$ sudo systemctl list-dependencies var-run-media-user-schwarzeplatte.mount 
var-run-media-user-schwarzeplatte.mount
● ├─-.mount
● ├─dev-mapper-schwarzeplatte.device
● └─system.slice
$ sudo systemctl list-dependencies var-run-media-user-schwarzeplatte.mount --reverse
var-run-media-user-schwarzeplatte.mount
● └─dev-mapper-schwarzeplatte.device

Does anyone have insight what I should do?

(Bonus question: How could a desktop notification [KDE] be fired once the backup has finished, detailing the result?)

Thank you for reading!

Offline

#2 2015-03-07 20:39:37

myles
Member
Registered: 2011-10-06
Posts: 40

Re: systemd does not umount in spite of StopWhenUnneeded=true

You could see if there are any messages written to the logs, if you have a terminal open with this running:

journalctl -f

then plug the thing in and see what happens when it is meant to umount.

grafzakenbarsch wrote:

(Bonus question: How could a desktop notification [KDE] be fired once the backup has finished, detailing the result?)

I don't use KDE but may be pipe it through osd_cat? e.g.

echo "NOTIFIED\!" | osd_cat -d10

Last edited by myles (2015-03-07 20:47:31)

Offline

#3 2015-03-07 21:27:16

grafzakenbarsch
Member
Registered: 2015-03-06
Posts: 11

Re: systemd does not umount in spite of StopWhenUnneeded=true

thank you for answering!

The log unfortunately does not give any hints. It just outputs the last line of the backup script and nothing more.

Offline

#4 2015-03-07 22:38:25

myles
Member
Registered: 2011-10-06
Posts: 40

Re: systemd does not umount in spite of StopWhenUnneeded=true

In fstab and in .mount there is "schwarzeplatte/" with unecessary trailing /.
Reading 'man systemd.mount' and 'man sytemd.automount' with respect to the fstab option x-systemd.automount, I wonder if your .mount unit is being overridden by an automatically generated .automount unit?

Offline

Board footer

Powered by FluxBB