How to rename encrypted root volume

George Shuklin
OpsOps
Published in
2 min readFeb 11, 2021

The problem: I’ve moved (by using pvmove) my root volume from an encrypted partition on my old drive to a new one. During that process I’ve called underlying device (encrypted partition) new_root. After successful move there is no more ‘old root’, but name stuck. I’m not a historian to keep stuff called ‘new’ after two centuries, so I want to rename it to a more reasonable name, f.e. root_vol. I use Debian, but it (may be) applicable to Ubuntu too.

It’s doable, but more tricky than you expect it to be. The key issue is that the underlying device must be decrypted at initramfs time, and there is a little flexibility at that moment.

Here is the proper sequence to do rename. If you miss something and got yourself into broken initramfs shell, see recovery instruction is in the second chapter.

The proper way

1. Do runtime rename for the volume: dmsetup rename /dev/mapper/new_root root_vol. (In my case new_root is the current name of mounted dmcrypt volume, and root_vol is desired new name).

2. Edit /etc/crypttab, replace name (and uuid, if needed). UUID can be found with blkid command.

3. Run update-initramfs -k all -u

(check that there is no warnings related to the encrypted volume name).

That’s all. If you missed step 1, bad things would happen.

How to recover from bad crypttab

After some time of repeated complains on inability to find the vg with your root, you get dropped to initramfs shell.

Some docs says that you need to mount your root system into /root, but I found that procedure (for this exact case) was slightly different:

Use cryptestup luksOpen /dev/name_of_parition_to_use to open encrypted device.

Run lvm pvscan

Press Ctrl-D to finish recovery shell.

Don’t try to mount anything, initramfs would do it properly after you’ve presented it with expected vg.

Boot should continue. If not, something else is broken too. After boot, repeat first chapter, this time, properly.

That’s all.

--

--

George Shuklin
OpsOps

I work at Servers.com, most of my stories are about Ansible, Ceph, Python, Openstack and Linux. My hobby is Rust.