LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-19-2022, 05:36 AM   #1
narcissus256
LQ Newbie
 
Registered: Aug 2020
Distribution: Arch
Posts: 9

Rep: Reputation: Disabled
Drive fails to unmount during shutdown – is that bad?


Hi,

I've got a luks encrypted msata drive which I automount using crypttab and fstab:
Code:
# /etc/crypttab
msata   UUID=<drive-uuid>  /path/to/keyfile   nofail,luks
Code:
# /etc/fstab
UUID=<decrypted-volume-uuid> /mnt/msata ext4 defaults,nofail 0 2
Whenever I shut the laptop down, the following errors appear in journalctl:
Code:
Mar 10 15:42:29 thinkpad systemd[1]: Failed unmounting /mnt/msata. 
░░ Subject: A stop job for unit mnt-msata.mount has finished 
░░ Defined-By: systemd 
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel 
░░ 
░░ A stop job for unit mnt-msata.mount has finished. 
░░ 
░░ The job identifier is 4061 and the job result is failed. 
Mar 10 15:42:29 thinkpad systemd-cryptsetup[6272]: Device msata is still in use. 
Mar 10 15:42:29 thinkpad systemd-cryptsetup[6272]: Failed to deactivate: Device or resource busy
I wondered if it's bad and may perhaps damage the drive overtime. If so, is there a solution?

I run Arch (5.16.15-arch1-1), I have asked on the Arch Forum, but nobody has answered for a week.

Thank you!
 
Old 03-19-2022, 01:06 PM   #2
suramya
Member
 
Registered: Jan 2022
Location: Earth
Distribution: Debian
Posts: 249

Rep: Reputation: 102Reputation: 102
It won't physically damage the drive, but there is a possibility of data loss when the system is rebooted without unmounting the partition. Some process is writing to the disk/using the disk that is preventing it from being unmounted. Check the output of iotop and search for the processes accessing /mnt/msata, that should show you the processes that are using that partition. Then you can investigate the programs found to see why they are not terminating when rebooting.
 
Old 03-20-2022, 06:12 AM   #3
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Code:
Failed to deactivate: Device or resource busy
That message is very clear.
 
Old 03-21-2022, 12:57 AM   #4
narcissus256
LQ Newbie
 
Registered: Aug 2020
Distribution: Arch
Posts: 9

Original Poster
Rep: Reputation: Disabled
Thanks! So I have figured out that "Device or resource busy" is because mpd is not giving up access to music on my msata drive.

I've got a user systemd unit starting mpd on startup.

Code:
# $HOME/.config/systemd/user/default.target.wants/mpd.service
[Unit]
Description=Music Player Daemon
Documentation=man:mpd(1) man:mpd.conf(5)
After=network.target sound.target

[Service]
Type=notify
ExecStart=/usr/bin/mpd --systemd

LimitRTPRIO=40
LimitRTTIME=infinity
LimitMEMLOCK=64M
ProtectSystem=yes

NoNewPrivileges=yes
ProtectKernelTunables=yes
ProtectControlGroups=yes
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
RestrictNamespaces=yes

[Install]
WantedBy=default.target
So I somehow have to stop this service just before shutdown. I admit I am not an expert on systemd, I have tried this:

Code:
# $HOME/.config/systemd/user/stop_mpd.service[Unit]
Description=Stop mpd before shutdown
DefaultDependencies=no
Before=shutdown.target

[Service]
Type=oneshot
ExecStart=systemctl --user stop mpd.service
TimeoutStartSec=0

[Install]
WantedBy=shutdown.target
But somehow it always fails:
Code:
Mar 20 21:31:25 thinkpad systemd[1]: Failed to start Stop mpd before shutdown.
░░ Subject: A start job for unit stop_mpd.service has failed
░░ Defined-By: systemd
░░ Support: https://lists.freedesktop.org/mailman/listinfo/systemd-devel
░░
░░ A start job for unit stop_mpd.service has finished with a failure.
░░
░░ The job identifier is 3883 and the job result is failed.
and anyway stop_mpd.service runs only after the error "Failed to deactivate: Device or resource busy".

So how would you write a user systemd service which gets run just before shutdown and which stops mpd.service? Or can one even specify that within mpd.service and not bother with stop_mpd.service?

Thank you!
 
Old 03-21-2022, 11:55 PM   #5
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
I have the exact same mpd.service, and no such problems.
It accesses an NFS mount on a different computer on the same network, so not quite your situation.
I never see problems with mpd when shutting down.
I don't think you can write a systemd.service to stop another systemd.service; IDK, it just feels wrong.
I also don't use crypttab; I forgot the details but I set my encrypted partitions up with the ArchWiki's help.

So maybe you have to
a) tell systemd to NOT auto(un)mount that partition, and write your own service for that <= the tricky part
b) tell it to unmount after mpd <= that part should be easy
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Can't unmount -- oops, can't fsck after unmount upnort Slackware 4 05-18-2019 11:41 AM
shutdown tumbleweed: failed to unmount /home; failed to unmount /var JZL240I-U Linux - Software 3 04-03-2017 07:23 AM
Missing unmount and unmount.cifs johnmccarthy Linux - Newbie 3 11-19-2011 07:01 AM
External USB hard drive doesn't unmount cleanly at shutdown DavidHindman Slackware 6 02-18-2009 09:04 PM
command 'unmount' not found - how can i unmount??? GloVe Linux - General 1 10-04-2003 06:33 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration