From 71a1cc9b9872b2c16220f3634422547ed11bbb81 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 15 Jan 2013 13:21:19 +0100 Subject: [PATCH] new post: Problems after disconnecting LUKS device --- ...s-after-disconnecting-luks-device.markdown | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 _posts/2013-01-14-problems-after-disconnecting-luks-device.markdown diff --git a/_posts/2013-01-14-problems-after-disconnecting-luks-device.markdown b/_posts/2013-01-14-problems-after-disconnecting-luks-device.markdown new file mode 100644 index 0000000..fa3198d --- /dev/null +++ b/_posts/2013-01-14-problems-after-disconnecting-luks-device.markdown @@ -0,0 +1,62 @@ +--- +layout: post +title: Problems after disconnecting LUKS device +date: 14.01.2013 23:28 +--- + +Yesterday I got my 2TB backup disk. I formatted it and then used [LUKS][] to encrypt it and [LVM][] for the Volume Management. +After I copied some files to the new disk, I unmounted the disk, unplugged it and ... + +### ... Oh, shit. + +I forgot to `cryptsetup luksClose` it. + +That's not a good thing to do. __Always remember to luksClose! It's so much easier__ + +So after reconnecting the device, you can't really decrypt and mount it, because it did not get unmapped (`/dev/mapper/name` still exists and so do `/dev/name/*`) + +### No problem, we fix that! + +_(in the following my mapping name is `extern`, change accordingly)_ + +First see current status, especially `Open count` + + dmsetup info + +Now remove each mapped device (`-backup` and `-media` for me, I have 2 partiions on the disk): + + dmsetup remove extern-backup + dmsetup remove extern-media + +Once again check `Open count`, it should be `0` now. If so, go on and remove the mapping: + + dmsetup remove extern + +Now you got rid of all old mappings. Let's try to mount the disk again. Plug it in, then do: + + cryptsetup luksOpen /dev/sdb2 extern + +Type your password. +If the Volume Groups are missing, use: + + vgscan + vgchange -ay extern + +Now you can mount your partitions: + + mount /dev/extern/backup /mnt/backup + +Once you're done, deactivate the volume groups and close the crypt device: + + vgchange -an extern + cryptsetup luksClose extern + +Now remember to always use these two commands after unmounting the device and use the following to open it: + + vgchange -ay extern + cryptsetup luksOpen /dev/sdb2 extern + +I wrote a little helper script which does exactly these steps as needed. I'll include it in my next post, when I talk about how I use the setup for backups. + +[luks]: https://wiki.archlinux.org/index.php/LUKS +[lvm]: https://wiki.archlinux.org/index.php/LVM