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.

| improve this answer | |
  • 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
  • 1
    you can also do dmsetup remove_all – Hitechcomputergeek May 17 '17 at 3:13
  • 11
    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
  • 2
    @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
  • 1
    @Hitechcomputergeek See askubuntu.com/questions/429612/… for how to find and close all the resources that are using the device. – jII Jul 22 '19 at 20:51

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

| improve this answer | |

This one worked for me (change sde1 with your disk label):

sudo cryptsetup luksOpen /dev/sde1 lukslvm

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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