I moved some disks from one system (guillemot) to another (fulmar) and the new system had a new name, but the volume groups were named after the previous system’s hostname (vg_guillemot0). I wanted to rename these volume groups so that they would match the system, but this was going to be tricky because you cannot do a volume group rename on a volume that is currently in use, and this was the root volumegroup (along with /var and /usr).
The following describes how I did this using a serial connection and a debirf rescue image:
First I created a debirf rescue boot environment
# aptitude install debirf
$ mkdir ~/debirf
$ cd ~/debirf
$ tar xzf /usr/share/doc/debirf/example-profiles/rescue.tgz
Then I edited the debirf.conf to setup a few things (like using our local apt proxy as a mirror).
Then I built the debirf image:
$ debirf make rescue
Then I copied it to my /boot partition and set it up to work with grub:
$ cp built debirf-rescue_lenny_2.6.26-1-686.cgz /boot
Then edit grub/menu.lst to use the existing vmlinuz-2.6.26-1-686 kernel and the debirf-rescue_lenny_2.6.26-1-686.cgz for the initrd, with serial configuration so it looks like this:
### END DEBIAN AUTOMAGIC KERNELS LIST
title Debirf rescue environment
kernel /vmlinuz-2.6.26-2-686 console=tty0, console=ttyS0,115200n8
initrd /debirf-rescue_lenny_2.6.26-2-686.cgz
Then I rebooted into this debirf rescue environment, logged in as root (no password).
Then I prepared my system to get at the devices. The system is setup with raid1+dmcrypt+lvm, so first I have to get the raid setup, and then the crypto layer:
0 debirf-rescue:~# modprobe -v raid1
0 debirf-rescue:~# mdadm --examine --scan >> /etc/mdadm/mdadm.conf
0 debirf-rescue:~# mdadm --assemble --scan
0 debirf-rescue:~# cryptsetup luksOpen /dev/md1 md1_crypt
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.
0 debirf-rescue:~# cryptsetup luksOpen /dev/md2 md2_crypt
Enter LUKS passphrase:
key slot 0 unlocked.
Command successful.
Then I want to get the volume groups available, but not activated, and then do the rename:
0 debirf-rescue:~# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_guillemot0" using metadata type lvm2
0 debirf-rescue:~# vgrename vg_guillemot0 vg_fulmar0
Volume group "vg_guillemot0" successfully renamed to "vg_fulmar0"
0 debirf-rescue:/etc/lvm# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_fulmar0" using metadata type lvm2
Once it is renamed, I can activate them:
0 debirf-rescue:/etc/lvm# vgchange -ay
3 logical volume(s) in volume group "vg_fulmar0" now active
0 debirf-rescue:/etc/lvm# lvs
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
root vg_fulmar0 -wi-a- 952.00M
usr vg_fulmar0 -wi-a- 4.66G
var vg_fulmar0 -wi-a- 4.66G
0 debirf-rescue:/etc/lvm#
Ok, now I am going to change some other things on the system to have the new name, so to do that I setup a chroot with the disks mounted:
0 debirf-rescue:~# mkdir /target
0 debirf-rescue:~# mount /dev/mapper/vg_fulmar0-root /target
0 debirf-rescue:~# mount /dev/md0 /target/boot
0 debirf-rescue:~# mount /dev/mapper/vg_fulmar0-var /target/var
0 debirf-rescue:~# mount /dev/mapper/vg_fulmar0-usr /target/usr
0 debirf-rescue:~# mount --bind /dev /target/dev
0 debirf-rescue:~# mount -t devpts devpts /target/dev/pts
0 debirf-rescue:~# mount -t proc proc /target/proc
0 debirf-rescue:~# mount -t sysfs sysfs /target/sys (on jessie and newer)
0 debirf-rescue:~# chroot /target
Then I run through and make various changes, be sure you change grub’s config and re-make the initramfs!
$EDITOR /etc/fstab
$EDITOR /etc/hosts
echo "fulmar" > /etc/hostname
$EDITOR /boot/grub/menu.lst
0 debirf-rescue:/# update-grub
0 debirf-rescue:/# update-initramfs -u -k all
0 debirf-rescue:/# umount /target/var
0 debirf-rescue:/# umount /target/usr
0 debirf-rescue:/# umount /target/boot
0 debirf-rescue:/# umount /target/dev/pts
0 debirf-rescue:/# umount /target/dev
0 debirf-rescue:/# umount /target/proc
0 debirf-rescue:/# umount /target
sync;sync;shutdown -r now