systemd failed to unmount during shutdown

At first my machine was giving the following message while shut down.

Job usere1000.service/stop running (59s / no Limit): User job app-gnome-yandexx2ddisk-1908.scope/stop running (58s / no limit)...

Then I set KillUserProcesses=yes is /etc/systemd/logind.conf. Now the machine shutdown first but give error

Failed unmounting media-ismail-SSDWorking.mount - /media/ismail/SSDWorking.

Just to mention, my Yandex.Disk that sync via a daemon is located in this ssd (/media/ismail/SSDWorking) which was giving message earlier.

Maybe because my system is not killing the process before unmounting (I am not sure).

Update 1:

I found /run/systemd/generator/media-ismail-SSDWorking.mount with the following conternt:

# Automatically generated by systemd-fstab-generator

[Unit]
Documentation=man:fstab(5) man:systemd-fstab-generator(8)
SourcePath=/etc/fstab
After=blockdev@dev-disk-byx2dlabel-SSDWorking.target

[Mount]
What=/dev/disk/by-label/SSDWorking
Where=/media/ismail/SSDWorking
Options=nosuid,nodev,nofail,x-gvfs-show

I think if I can add app-gnome-yandexx2ddisk-1908.scope in After= via systemd-fstab-generator for unmount then it might solve the problem.

Update 2:

$ systemd-umount /dev/sda1
$ journalctl -xe
 A stop job for unit media-ismail-SSDWorking.mount has begun execution.
░░
░░ The job identifier is 3897.
Jul 07 12:38:22 debian-i5 umount[10089]: umount: /media/ismail/SSDWorking: target is busy.
Jul 07 12:38:22 debian-i5 systemd[1]: media-ismail-SSDWorking.mount: Mount process exited, code=exited, status=32/n/a
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ An n/a= process belonging to unit media-ismail-SSDWorking.mount has exited.
░░
░░ The process' exit code is 'exited' and its exit status is 32.
Jul 07 12:38:22 debian-i5 systemd[1]: Failed unmounting media-ismail-SSDWorking.mount - /media/ismail/SSDWorking.
░░ Subject: A stop job for unit media-ismail-SSDWorking.mount has finished
░░
░░ The job identifier is 3897 and the job result is failed.

Update 3:

If I run yandex-disk stop, then systemd-mount /dev/sda1, it simply unmount. So the issue is, the system is not stopping yandex-disk before trying to unmount.

Update 4:

I have run the following:

sudo tee /etc/systemd/system/run-before-shutdown.service << END
[Unit]
Description=Run my custom task at shutdown
Requires=network.target
DefaultDependencies=no
Before=reboot.target shutdown.target

[Service]
Type=oneshot
User=ismail
Group=ismail
ExecStart=/bin/true
ExecStop=/usr/bin/bash -c '/usr/bin/yandex-disk stop'
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
END

sudo systemctl daemon-reload
sudo systemctl start run-before-shutdown.service
sudo systemctl enable run-before-shutdown.service

Still getting error:

Failed unmounting media-ismail-SSDWorking.mount - /media/ismail/SSDWorking.
Asked By: Ahmad Ismail

||

OP here. The issue was resolved after I introduced yandex-disk to systemd.

sudo tee /etc/systemd/system/yandex-disk.service << END
[Unit]
Description=Yandex Disk Service
After=network.target
RequiresMountsFor=/media/ismail/SSDWorking

[Service]
Type=forking
User=ismail
Group=ismail
ExecStart=/usr/bin/yandex-disk start
ExecStop=/usr/bin/yandex-disk stop

[Install]
WantedBy=multi-user.target
END

sudo systemctl start yandex-disk
sudo systemctl enable yandex-disk
sudo systemctl daemon-reload
Answered By: Ahmad Ismail
Categories: Answers Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.