[CentOS] Is it possible to lvrename the current root partition?

Wed May 7 18:05:23 UTC 2008
Alfred von Campe <alfred at von-campe.com>

On May 2, 2008, at 17:24, Ross S. W. Walker wrote:
> Sure you can do all this from rescue mode off the first CD.
>
> Boot the cd type in 'linux rescue' and continue to the command prompt.

First, thanks for the detailed list, Ross.  It was very helpful.  I  
was able to rename both the VG and the LVs, but it was slightly more  
complicated than the items on the list.

> 1) make sure swap isn't using the swap lv
> 	- swapoff -a

What I did was say "Skip" when the rescue image asks you if you want  
it to find existing Linux installations and mount them under /mnt/ 
sysimage.  The reason I did this was that if you let it mount your  
partitions, you need to go through a lot of additional steps to get  
everything under /mnt/sysimage unmounted, and nothing in there is  
needed to do the rename (unless you want to rename the VG -- see below).

> 2) unmount all lvs mounted
> 	- umount /mnt/sysimage/boot
> 	- umount /mnt/sysimage

Not needed because of what I did in step 1, but there are additional  
mount points to unmount if you do let the rescue image do the mounts  
(do a "mount | grep  sysimage" to find all the mount points).

> 3) mark all lvs as unavailable
> 	- lvchange -a n <vgname>

This step is indeed required unless you chose to skip the mounting  
of /mnt/sysimage altogether.  Do a "lvm lvscan" to find out which LVs  
are active (and use "lvm lvchange" as described below).

> 4) rename the volume group
> 	- vgrename <oldvgname> <newvgname>

Well, vgrename is not part of the rescue disk.  So if you want to do  
this, you will have to mark the root LV as available, mount it, and  
then copy /mnt/<mountpoint>/usr/sbin/vgrename to /tmp.  Then you have  
to unmount the root partition and mark the LV as unavailable.

> 5) rename the logical volumes
> 	- lvrename <vgname>\<oldlvname> <newlvname>
>
> 6) repeat #5 as necessary

The lvrename binary (symbolic link) does not exit in rescue mode, so  
you will have to type "lvm lvrename" (and "lvm lvchange", etc.).   
Also, you have to use a forward slash here.

>
> 7) re-activate all the lvs
> 	- lvchange -a y <vgname>

Remember to use the new names.

> 8) re-mount the root and boot lvs,
> 	- mount /dev/<vgname>/<rootlv> /mnt/sysimage
> 	- mount /dev/<vgname>/<bootlv> /mnt/sysimage/boot

I think this part worked as is.

> 9) chroot to the mounts with, 'chroot /mnt/sysimage /bin/bash'

Before I could do this, I had to use mknod to create the device  
entries in /mnt/sysimage/dev/mapper/<vgname>-<lvname> and the  
symbolic links in /mnt/sysimage/dev/<vgname>/<lvname>.  Make sure the  
symbolic links point to /dev/mapper/... and not /mnt/sysimage/dev/ 
mapper/...  I don't remember if this was required to mount it while  
in rescue mode or to make the system bootable again.  But I remember  
that I had to do it.

> 10) edit /etc/fstab
>
> 11) edit /boot/grub/grub.conf
>
> 12) remake the initrd
> 	- mkinitrd -f /boot/initrd-$(uname -r).img $(uname -r)

You will have to type the release version of the kernel instead of  
relying on the output of uname -r.

It turns out that I can skip steps 7-12 since I plan to upgrade the  
systems from CentOS 4.6 to CentOS 5.1 immediately after doing the  
rename, and the installer (anaconda) will take care of all these  
details.   I just had to adjust my kickstart scripts to use the new  
names.

Anyway, thanks again for all the help.  I'm starting to upgrade my  
two dozen or so desktops to CentOS 5.1 using the new VG and LV names.

Alfred