Renaming a Linux Volume Group Containing the Root File System

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:

  1. 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.)

  2. Do not mount any file system from your volume group.

  3. Deactivate all logical volumes by executing the following command as root or prefix lvchange by sudo if you are not root:
    ls -1 /dev/<VG>/lv* | xargs -iVOL lvchange -an VOL

    Note: You have to replace <VG> by your volume group’s name.

  4. Rename the volume group by this command (prefix it with sudo if you are not root):

    vgrename <VG> <NEW-VG>

    Replace <VG> by your old volume group’s name and <NEW-VG> by the new name.

  5. Now reactivate your logical volumes by issuing the following command:

    ls -1 /dev/<NEW-VG>/lv* | xargs -iVOL lvchange -ay VOL

    Replace <NEW-VG> as mentioned before. Place sudo before lvchange if you are not root.

  6. Now mount your root file system (or whatever file system contains /etc) and – if your system is not a Debian – the /boot:

    mkdir /tmp/mysys
    mount /dev/<NEW-VG>/<ROOT-LV> /tmp/mysys
    mount /dev/<BOOT-DEV> /tmp/mysys/boot

    Replace <NEW-VG> accordingly. <ROOT-LV> ist the name of the logical volume on which your root file system is stored, e.g. lv_root. <BOOT-DEV> is the partition which holds your /boot file systems, e.g. sda1.

    Don’t forget to place sudo in front of these commands if you are not logged in as root.

  7. Edit now the fstab of your system which you’ll find in /tmp/mysys/etc/fstab. Change the devices to reflect the changed volume group name.

  8. Edit your grub configuration now. It is located in one (or all, thanks to symlinks) of these locations:


    In your configuration you will find several kernel parameters like root or 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.

  9. 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.

This entry was posted in Linux, Operating systems, Virtualization and tagged , , , , . Bookmark the permalink.

3 Responses to Renaming a Linux Volume Group Containing the Root File System

  1. Gint says:

    Hello Oliver! How are you my friend? Hope all is well with Hannah and Lisa.

    I stumbled upon this blog after making a mistake and attempting to recover. While I have no doubt that your method works, I have an easier way if you’re rebooting anyway, at least on redhat and its derivatives (CentOS, OEL, etc…).
    vgrename vg_old vg_new
    edit /etc/fstab and change the old vg references to the new vg name
    edit /boot/grub/grub.conf and change the old vg references to the new vg name

  2. Lucha says:

    great article, really love it!

  3. Ivan says:

    If running Ubuntu Trusty LTS and your root is something like this:

    /dev/mapper/trusty–vg-root on / type ext4 (rw,errors=remount-ro)

    All you really need to do is:

    1. Do vgrename
    2. Update /etc/fstab
    3. Run update-grub
    4. Reboot

    That’s it.

Leave a Reply

Your email address will not be published. Required fields are marked *