Mounting USB disk with LUKS encrypted partion fails with a cryptsetup "Device already exists" error
Solution 1
Yes, this happens when luks encrypted device was not cleanly deactivated with cryptsetup close.
You can try to remove the mapping using
dmsetup remove /dev/mapper/luks-...
if you want to avoid rebooting.
Solution 2
From my side, when it happened the dmsetup remove /dev/mapper/luks-
command didn't work due to the fact that the specified mapped disk is no more present under /dev/mapper ...
So I had to manually close the old mapping with:
cryptsetup luksClose /dev/sdxx /dev/mapper/luks-...
(where sdx correspond to the luks partition you have identified with fdisk -l
Solution 3
This one worked for me (change sde1
with your disk label):
sudo cryptsetup luksOpen /dev/sde1 lukslvm
Related videos on Youtube
JasonWoof
Updated on September 18, 2022Comments
-
JasonWoof over 1 year
I've got an external USB drive with an encrypted LUKS partition. I generally have no problems mounting the device; I click it from the xfce4 desktop and get a dialog where I enter the password.
When I try to mount the drive now, I type in the password and get the error:
Error unlocking /dev/sdc1: Command-line `cryptsetup luksOpen "/dev/sdc1" "luks-..."' exited with non-zero exit status 5: Device luks-... already exists
What do I need to do in order to mount the drive? Is it somehow corrupted? How can the device already exist if it's not mounted (and wasn't plugged in until a short time ago)?
-
cegfault over 7 yearsis the name of the luks device in /dev/mapper/ ?
-
JasonWoof over 7 yearsRebooting works, of course, but it'd be nice to know if there's a way to un-munge the situation. I suspect the external device may not have been cleanly unmounted at a suspend operation or something.
-
JasonWoof over 7 years@cegfault Well that's a good question; I suspect so, but I don't know for sure. I have since rebooted. I didn't know to check that; I apologize. If it happens again and I check that, what does the answer (there or not there) mean?
-
-
JasonWoof over 7 yearsOK thank you! I will try that the next time it happens. (In fact maybe I'll make it happen on purpose.)
-
Hitechcomputergeek about 7 yearsyou can also do
dmsetup remove_all
-
Hitechcomputergeek about 7 yearsbut this answer didn't even work for me - I just get
device-mapper: remove ioctl on [device] failed: Device or resource busy
-
hife over 6 yearsThanks, after my encrypted external hard drive shut down due to a defective power supply, with a different power cord I got the same message as OP. This fixed it.
-
Kevin Brotcke over 6 years@Hitechcomputergeek I got the same and had to close an old terminal I had left open to the drive.
-
jII almost 5 years@Hitechcomputergeek See askubuntu.com/questions/429612/… for how to find and close all the resources that are using the device.
-
Martian2020 about 2 yearsI manually deleted the file trying to tackle the issue in the question, it resulted in this situation. Also I deleted some other files, so
fdisk
no longer displayed "hanged" disk. Butdmsetup remove_all
helped (it was suggested by Hitechcomputergeek as comment to accepted answer).