pmbootstrap shutdown: Make cryptsetup closing slightly more robust

I've had a strange case where `cryptsetup status` did not work
inside the chroot anymore, and only zapping it would resolve it.
But I couldn't zap, because the status check was preventing shutdown
(on which zap depends) from working. This commit works around that.
This commit is contained in:
Oliver Smith 2017-07-21 23:44:28 +02:00
parent 70fbed99da
commit 223f584e26
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 6 additions and 0 deletions

View File

@ -35,6 +35,12 @@ def shutdown_cryptsetup_device(args, name):
pmb.chroot.apk.install(args, ["cryptsetup"])
status = pmb.chroot.root(args, ["cryptsetup", "status", name], check=False,
return_stdout=True)
if not status:
logging.warning("WARNING: Failed to run cryptsetup to get the status"
" for " + name + ", assuming it is not mounted"
" (shutdown fails later if it is)!")
return
if status.startswith("/dev/mapper/" + name + " is active."):
pmb.chroot.root(args, ["cryptsetup", "luksClose", name])
elif status.startswith("/dev/mapper/" + name + " is inactive."):