Not often, but sometimes you find yourself in situations where you have to rename a volume group on Linux. You have a base image in a virtualization platform, for example. You clone it and you realize that your preferred Linux distribution used the hostname of the original image for a volume group’s name. Your perfectionism and your sense of order don’t allow it that your new machine’s volume group is based on another machine’s hostname. Time to rename! — But there is the root file system on it. How to do it?
To rename a volume group in Linux is not a problem at all. First you have to unmount all file systems on the volume group and set the corresponding logical volumes to “not available” by
lvchange -an. Rename the volume group with
vgrename now. Reactivate all logical volume by using
lvchange -ay. Last but not least you have to change the device entries in
/etc/fstab and remount the formerly unmounted file system again. So far, so good.
The problem with a volume group containing the root file system is, that you cannot simply unmount it. Here are more steps and a reboot of the system necessary.
WARNING: Be very carefully while changing your volume group’s name. An error while changing your Linux system’s volume group might result in a non-booting or wrong working system. So take care what you are doing! Make sure that you have an up to date backup of your systems, especially (but not exclusively!) while changing a productive system!
The following steps are provided “as-is”. I make no warranty of any kind. I shall not be liable for any errors or for incidental or consequential damages. You will change an essential part of your system so be prepared if something goes accidentally wrong or this instruction does not fit your Linux system. Make a backup and calculate the time to use it in the case that something goes wrong!
This said, here is a recipe:
Boot your machine with a rescue or live Linux system which supports LVM as well as the file systems used on your system. (A good choice would be the rescue mode of the boot media of your Linux distribution.)
Do not mount any file system from your volume group.
- Deactivate all logical volumes by executing the following command as
sudoif you are not
ls -1 /dev/<VG>/lv* | xargs -iVOL lvchange -an VOL
Note: You have to replace
<VG>by your volume group’s name.
Rename the volume group by this command (prefix it with
sudoif you are not
vgrename <VG> <NEW-VG>
<VG>by your old volume group’s name and
<NEW-VG>by the new name.
Now reactivate your logical volumes by issuing the following command:
ls -1 /dev/<NEW-VG>/lv* | xargs -iVOL lvchange -ay VOL
<NEW-VG>as mentioned before. Place
lvchangeif you are not
Now mount your root file system (or whatever file system contains
/etc) and – if your system is not a Debian – the
mkdir /tmp/mysys mount /dev/<NEW-VG>/<ROOT-LV> /tmp/mysys mount /dev/<BOOT-DEV> /tmp/mysys/boot
<ROOT-LV>ist the name of the logical volume on which your root file system is stored, e.g.
<BOOT-DEV>is the partition which holds your
/bootfile systems, e.g.
Don’t forget to place
sudoin front of these commands if you are not logged in as
Edit now the
fstabof your system which you’ll find in
/tmp/mysys/etc/fstab. Change the devices to reflect the changed volume group name.
grubconfiguration now. It is located in one (or all, thanks to symlinks) of these locations:
/tmp/mysys/boot/grub/grub.conf /tmp/mysys/boot/grub/menu.lst /tmp/mysys/etc/grub.conf
In your configuration you will find several kernel parameters like
rd_LVM_LV, which you have to change to reflect your volume group’s new name. Simply search for your old volume group’s name and replace all occurrences with your new one.
Now shutdown your rescue or live system and boot into your system normally.
If something goes wrong you will have to boot your rescue or live Linux system again and correct the problems.