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)?

  • 1
    is the name of the luks device in /dev/mapper/ ? – cegfault Jan 15 '17 at 1:32
  • Rebooting 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. – Pointy Jan 15 '17 at 2:16
  • @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? – Pointy Jan 15 '17 at 2:18

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.

  • OK thank you! I will try that the next time it happens. (In fact maybe I'll make it happen on purpose.) – Pointy Jan 15 '17 at 23:43
  • you can also do dmsetup remove_all – Hitechcomputergeek May 17 '17 at 3:13
  • 5
    but this answer didn't even work for me - I just get device-mapper: remove ioctl on [device] failed: Device or resource busy – Hitechcomputergeek May 17 '17 at 3:29
  • Thanks, 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. – hife Nov 11 '17 at 19:38
  • @Hitechcomputergeek I got the same and had to close an old terminal I had left open to the drive. – Kevin Brotcke Nov 21 '17 at 4:42

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

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.