22

My system is fully encrypted with dm-crypt and LVM. I recently moved the encrypted partition from /dev/sda5 to /dev/sda2.

My question is: how can I change the name the encrypted partition is mapped to from sda5_crypt to sda2_crypt?

I can boot the system all right. But the prompt I get at boot time says (sda5_crypt) though the UUID maps to /dev/sda2:

  Volume group "vg" not found
  Skipping volume group vg
Unlocking the disk /dev/.../UUID  (sda5_crypt)
Enter passphrase:

I tried to live-boot, decrypt sda2, activate vg, chroot to /dev/vg/root and run update-grub2 but to no avail.

Merely editing /etc/crypttab doesn't work either.

n.r.
  • 2,173
  • 3
  • 18
  • 30

2 Answers2

28

"sda5_crypt" crypttab change as per suggestion below:

Replace OLD_NAME with NEW_NAME in /etc/crypttab & /etc/fstab, and then:

# dmsetup rename OLD_NAME NEW_NAME
# cp -a /dev/mapper/NEW_NAME /dev/mapper/OLD_NAME
# update-initramfs -u -k all
# rm /dev/mapper/OLD_NAME
# update-grub
# reboot
ska
  • 3
  • 2
n.r.
  • 2,173
  • 3
  • 18
  • 30
  • 2
    rescue should not be necessary. just edit the crypttab, update-initramfs, and next time you boot it should be renamed. You can also rename it in the running system using `dmsetup rename oldname newname`. Note that this does not free the old name, as it may be in use. – frostschutz Jun 28 '13 at 18:29
  • @frostschutz You have to be able to get at that `/etc/crypttab` file somehow… Doing the mounting manually from the initramfs shell so that you can boot the normal system is possible, but not easy. A rescue system is the quicker option if you aren't intimately familiar with `cryptsetup` and LVM commands. – Gilles 'SO- stop being evil' Jun 28 '13 at 22:45
  • 1
    @Gilles: sure, but the question stated "I can boot the system all right." – frostschutz Jun 29 '13 at 11:29
  • You just saved me a big headache @n.r. Thank you – deitch May 06 '16 at 10:38
  • 1
    This is the right method, but a few more details should be pointed out: 1) Don't forget to update `/etc/fstab` before these commands, too, or you're root partition won't mount. 2) You may receive an error on `update-grub` that it can't find the previous name. Assuming you're only renaming the crypt name, then you can ignore the error, reboot, and run `update-grub` after you boot up. – Fmstrat Mar 15 '19 at 14:45
  • There's no `update-initramfs` or `update-grub` in recent Fedora installations, here `dracut --force` appears to do the trick in generating the `initrd`. The Grub configuration doesn't need to be changed as it's referring to the root device via its (unchanged) UUID anyway. – ckujau Oct 24 '21 at 13:45
0

I just came across this issue - with the additional complication that I haven't seen the warning of the last update-initramfs. So I renamed the device in crypttab, ran update-initramfs, restarted and had a problem. I solved it as follows, basically the same n.r. but I had to alter the commands slightly:

  1. Boot a Live (K)Ubuntu System from USB
  2. Open the device in Dolphin/? which setups all the needed configuration and asks you your password
  3. Open the console in the root directory of your broken system
  4. Execute the following line by line
sudo -s
# get the name the partition was mounted with, starts with luks
dmsetup ls
# rename the loop device (check with ls /dev/mapper)
dmsetup rename LUKS_NAME NEW_NAME

# prepare chroot
mount --bind /dev dev/
mount --bind /proc proc/
mount --bind /sys sys/
chroot .

# mount devices (I missed this first, you need both)
mount boot
mount /

# ready to update
update-initramfs -u -k all
y_z
  • 101
  • 1