12

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

Pointy
  • 1,513
  • 5
  • 28
  • 45
  • 1
    is the name of the luks device in /dev/mapper/ ? – cegfault Jan 15 '17 at 01: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 02: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 02:18

3 Answers3

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
  • 2
    you can also do `dmsetup remove_all` – Hitechcomputergeek May 17 '17 at 03:13
  • 12
    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 03: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
  • 4
    @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 04:42
  • 2
    @Hitechcomputergeek See https://askubuntu.com/questions/429612/device-mapper-remove-ioctl-on-luks-xxxx-failed-device-or-resource-busy for how to find and close all the resources that are using the device. – jII Jul 22 '19 at 20:51
6

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

  • I 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. But `dmsetup remove_all` helped (it was suggested by Hitechcomputergeek as comment to accepted answer). – Martian2020 Apr 07 '22 at 14:56
3

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

sudo cryptsetup luksOpen /dev/sde1 lukslvm

Ikrom
  • 173
  • 1
  • 6