I had repeatable disk corruption due to this issue, so I think fixing it
should be given a higher priority!  I experienced this issue with Ubuntu
22.04 (and probably 20.04) on an encrypted LVM installation:

systemd-shutdown[1]: Could not detach DM /dm/dm-9: Device or resource busy
systemd-shutdown[1]: Could not detach DM /dm/dm-7: Device or resource busy
systemd-shutdown[1]: Could not detach DM /dm/dm-11: Device or resource busy
systemd-shutdown[1]: Could not detach DM /dm/dm-10: Device or resource busy
systemd-shutdown[1]: Could not detach DM /dm/dm-1: Device or resource busy
systemd-shutdown[1]: Could not detach DM /dm/dm-0: Device or resource busy
systemd-shutdown[1]: Failed to finalize DM devices, ignoring.

I found the easiest way to check for these messages is to shutdown using:
sudo systemctl halt

For some years I've tried to configure LVM to use an NVMe drive as a
cache for the / and /home partitions on my main drive, but I always
ended-up getting severe corruption after some time.  Recently I realised
that after booting, lvmcache would spend a long time copying my whole
NVMe cache back to the main drive (and slow everything down until that
finished), as "sudo lvs -a" showed that "Cpy%Sync" was non-zero but
dropping.  I read that:

"The most likely cause is your system was not shutdown cleanly so dm-
cache has no choice but to assume all blocks are dirty and need writing
back."

Once I realised the above "Device or resource busy" error messages were
probably related to this problem, I followed Boulardii's earlier tip
here about installing dracut-core.  Since then I no-longer get those
error messages - and fingers crossed I haven't had any corruption since
re-enabling LVM's caching.

In case it helps, my /etc/crypttab file looks roughly like this:

sdz5_crypt UUID=... /dev/disk/by-label/DRIVENAME:/filename.key 
luks,discard,noauto,keyscript=passdev
nvme0n1_crypt UUID=... /dev/disk/by-label/DRIVENAME:/filename.key 
luks,discard,noauto,keyscript=passdev

(I did try adding ,x-initrd.attach but that didn't help.)

And maybe helpful for others: Some time ago I switched from Ext4 to
Btrfs, because the disk corruption spread badly before Ext4 noticed (and
by that time it was way too late to repair it - I had to format &
restore).  With a correctly configured Btfs (-mdup), it stops the system
at the first sign of corruption (easily repaired), and that allowed me
to try various ways to fix the problem - which were all unsuccessful
until now.  Also beware that converting an Ext4 partition to Btrfs
results in it using -msingle which is extremely fragile, so make sure to
convert it to -mdup ASAP.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1905166

Title:
  systemd-shutdown cannot detach DM

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/finalrd/+bug/1905166/+subscriptions


-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to