Rename LVM Volume Group Holding Root File System Volume

I’m not sure exactly when this change happened, but in Oracle [Enterprise] Linux 5 days a default installation would result in the root file system being created as a LVM logical volume (LV) named LogVol00 in a volume group (VG) named VolGroup00. I must confess that I wasn’t paying too much attention to LV and VG default names in the days I was playing with OL5 a lot, but that’s partly because there was nothing to drag my attention to them.

Along comes Oracle Linux 6 and off I go creating VMs, cloning them and then really not liking the fact that the default VG created during the installation, and holding the LV for the root file system, is named vg_<hostname> where <hostname> is the hostname of the original VM I installed. If I clone a VM the next thing I do is change the hostname, which means that I’m left with an inconsistent and somewhat confusing VG name. I think I screwed up one VM before realising that it wasn’t just simply a case of renaming the VG and updating /etc/fstab. I asked a friend who does much more Linux admin how to achieve what I wanted and didn’t take it any further when he said words to the effect of, “Yeah, it’s more complicated than that.”

Update [5th August 2014]

It turns out that renaming the volume group that hold the logical volume the root file system is on is not as complex as I had previously thought. Comments from Brian suggest that there is no need to recreate the initramfs and that it can be done without booting into rescue mode. I’ve just tested Brian suggestions and he’s right. It is as simple as:

  1. Rename Volume Group
  2. Update /etc/fstab
  3. Update /boot/grub/grub.conf
  4. Reboot

Brian – Thanks a lot for your comments and pointing out unnecessary steps.

This update makes the rest of the post mostly useless, but I’ll leave it all there for context.

End of update [5th August 2014]

Fairly recently I walked into the same situation again, only this time I decided that I wasn’t going to take “more complicated” for an answer :-). I searched, found a few articles that seemed to have logic in their approach and figured I had nothing to lose. I also thought there were some redundant steps in the posts I was following, hence feeling it’s worth blogging my slimmed down approach.

Well, that’s enough preamble. Here’s the details:

1) Boot Into Rescue Mode

For me booting from CD/iso was the easiest way to get into “rescue mode”. To do this select “Rescue installed system” when the welcome screen is presented during the boot process. You will then be prompted with:

Choose a Language – You know better than I what’s the best choice for you. Select it and then OK.

Keyboard Type – Again, pick what you think best matches your keyboard. Then select OK.

Rescue Method – Select “Local CD/DVD”, then OK.

Setup Networking – Select “No”

Rescue – Select “Continue”

Rescue (message about your system being mounted under /mnt/sysimage and use of chroot) – OK.

Rescue (another message about having mounted your system under /mnt/sysimage) – OK.

First Aid Kit quickstart menu – Select “shell  Start shell”, then OK.

The above will get you to a prompt so you can actually do what you came here for!

2) Rename Volume Group

The LVM commands you issue are the same as usual, only they need to be prefixed with lvm. I suggest listing the VGs to be sure the state of the system is as you expect, and using more is a good idea as you don’t have a scrollbar, i.e.:

lvm vgdisplay | more

Once you’re happy, rename the VG as below:

lvm vgrename <original> <desired>

You should get a success message after this command.

3) Update All References

Change the root directory to that of your installed system using chroot:

chroot /mnt/sysimage

The following files need to be modified to replace references to the old VG name with the new VG name:

  • /etc/fstab
  • /boot/grub/grub.conf

There will be multiple references per line in grub.conf, so a bit of “global replace” is in order.

4) Create New Ramdisk Image

Run the following command to make a new initial ramdisk image

mkinitrd --force /boot/initramfs-<kernel version>.img <kernel version>

Note that the force option is only required because there is already an existing image with the same name. You could use a different name if you want, but you’d need to add an appropriate entry to the grub.conf to reflect this.

If the above command completes without error messages and you didn’t make any errors in the editing of the files earlier then you should be all set… Only one way to find out!

5) Reboot Machine

Exit out of the chroot environment (type “exit”).

Exit out of the shell to return to the “First Aid Kit quickstart menu” (type “exit”).

First Aid Kit quickstart menu – Select “reboot Reboot”, then OK.

At the welcome screen select “Boot from local drive”.

If all goes well then remember to remove the CD/iso from your [virtual] CD drive.


The 2 articles that helped me with this are the following, so thanks to the authors:

Update [27th January 2014]

I have just noticed that the default volume group name when installing Oracle Linux 6.5 has changed from “vg_<hostname>” to “VolGroup”.

About these ads

7 thoughts on “Rename LVM Volume Group Holding Root File System Volume

  1. Just FYI, the mkinitrd step is not required for renaming a VG. The guy did it in the one article because he’d changed his grub.conf to say “vgrepair”. If you simply update the new VG name in grub.conf, you don’t need to make a new initramfs.

    • Specifically, this step:

      Make a copy of grub.conf
      # cp -p /boot/grub/grub.conf /boot/grub/old/grub.conf.20100512
      Update grub.conf with updated path to root partition and yet to be made
      initrd file -> initrd-2.6.18-194.el5.vgrepair.img
      From this article you referenced:

      I don’t know exactly why he did that. Neither your hostname nor the vg name are typically referenced in your initramfs name. So as long as you don’t mess with grub.conf, there’s no need to mess with initramfs at all.

  2. Sorry, last comment. This also isn’t required to be done from a rescue image at all. You can do it on a live system. You just have to get it right. Do the vgrename first, update both fstab and grub.conf, and if you’ve typed correctly, your system will reboot fine. If you do screw it up, it can be saved from a rescue image.

    • Actually, here’s a bit of the script I use for setting up new VMs from a template:

      echo “changing LVM names”
      vgrename $oldhostname $newhostname
      sed -i “s/$oldhostname/$newhostname/g” /etc/fstab
      sed -i “s/\/$oldhostname/\/$newhostname/g” /boot/grub/grub.cfg
      update-initramfs -c -k all

  3. Just wanted to thank you all. I did this on my linux mint (live system), and all went well. I used commands Josiah suggested (except the last one), just made copies of fstab and grub.cfg to test if replacing goes as intended. I’m sort of new to linux, so I wasn’t sure what’s going to happen with /dev/mapper/ symlinks and /dev/old_volume_group, but those are created from scratch on boot and old_volume_group is deleted (/dev/new_volume_group is created).

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s