Rename Root Volume Group
by Jeff Stonacek, Principal Architect
Renaming a volume group is a fairly straightforward process, assuming that the volume group is not the root volume group. That is to say, the volume group containing the boot image and root filesystem.
The reason I wrote this blog is because I am an ex-AIX administrator, so I believe that all root volume groups should be named rootvg. There really is no other name quite so succinct or aptly titled as rootvg, when describing the volume group containing the boot image and root filesystem. I mean, come on, VolGroup00? What is that nonsense? So when I discovered that one of my Linux systems had the mangled name of rootbvg for the root volume group, it made me cringe. The easiest thing to do (for people that do not suffer from mild OCD) would be to ignore it. Unfortunately, this was a template virtual machine, which had been cloned a few times so the problem had spread.
There are four main things that need to happen when renaming a root volume group, in order to make the change successful. They are:
- Renaming the volume group
- Fixing grub so it knows where the root filesystem is located
- Fixing the fstab file so filesystems and swap can mount at boot time
- Rebuilding the initramfs (initrd in prior Linux versions)
Rename Volume Group
First, let’s take a look at the existing LVM layout.
# vgs VG #PV #LV #SN Attr VSize VFree rootbvg 1 2 0 wz--n- 18.00g 0 # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root rootbvg -wi-ao---- 16.00g swap rootbvg -wi-ao---- 2.00g
Ok, pretty simple. One volume group incorrectly named “rootbvg” and two logical volumes, root and swap.
The command to rename the volume group is quite simple on Linux (unlike AIX).
# vgrename -v rootbvg rootvg Checking for existing volume group "rootbvg" Found same device /dev/sda2 with same pvid EWrmvICNJxEIqVN7NTiowt8Tss1Y3fdJ Checking for new volume group "rootvg" Archiving volume group "rootbvg" metadata (seqno 3). Writing out updated volume group Renaming "/dev/rootbvg" to "/dev/rootvg" Loading rootbvg-swap table (253:1) Suppressed rootbvg-swap (253:1) identical table reload. Suspending rootbvg-swap (253:1) with device flush Loading rootbvg-swap table (253:1) Suppressed rootbvg-swap (253:1) identical table reload. Renaming rootbvg-swap (253:1) to rootvg-swap Resuming rootvg-swap (253:1) Loading rootbvg-root table (253:0) Suppressed rootbvg-root (253:0) identical table reload. Suspending rootbvg-root (253:0) with device flush Loading rootbvg-root table (253:0) Suppressed rootbvg-root (253:0) identical table reload. Renaming rootbvg-root (253:0) to rootvg-root Resuming rootvg-root (253:0) Creating volume group backup "/etc/lvm/backup/rootvg" (seqno 4). Volume group "rootbvg" successfully renamed to "rootvg" Wiping cache of LVM-capable devices Wiping internal VG cache
Ok, that was easy.
# vgs VG #PV #LV #SN Attr VSize VFree rootvg 1 2 0 wz--n- 18.00g 0 # lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root rootvg -wi-ao---- 16.00g swap rootvg -wi-ao---- 2.00g
Since this is a Centos/RHEL/OEL 7 system, it uses Grub 2. However, the process to modify the location of the root filesystem is very similar to Grub. Merely edit the /etc/grub2.cnf file (actually a sym link to /boot/grub2/grub2.cnf) and change the location of the root filesystem. The hardest part of this operation is remembering that with Grub 2, the configuration file ends with .cnf not .conf. Replace all instances of the old volume group name with the new.
linux16 /vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/rootvg-root ro rd.lvm.lv=rootvg/root rd.lvm.lv=rootvg/swap rhgb quiet net.ifnames=0 biosdevname=0 initrd16 /initramfs-3.10.0-327.el7.x86_64.img
linux16 /vmlinuz-0-rescue-da30334eef8842caba0c81803f998805 root=/dev/mapper/rootvg-root ro rd.lvm.lv=rootvg/root rd.lvm.lv=rootvg/swap rhgb quiet net.ifnames=0 biosdevname=0 initrd16 /initramfs-0-rescue-da30334eef8842caba0c81803f998805.img
Save the grub2.cnf (grub.conf on older linux systems) and you’re done.
We have to tell /etc/fstab where our filesystems live. So edit the file and replace all occurrences of the old volume group name with the new.
/dev/mapper/rootvg-root / xfs defaults 0 0 UUID=cea2e959-b9a9-4657-9d9a-b3ba61654738 /boot xfs defaults 0 0 /dev/mapper/rootvg-swap swap swap defaults 0 0
Save the file and you’re done.
By the way, if you forget the entry for the swap file, your system will hang and you’ll have to turn off quiet boot to figure that out.
Initramfs / initrd
As stated earlier, I am running on a Centos/RHEL/OEL 7 system, so it uses the newer RAM file system to initiate the boot image. Older Linux systems used the inital ramdisk system, or initrd. We need to rebuild the initramfs so the system knows where to find the root filesystem. To do this, use the mkinitrd command.
mkinitrd -f -v /boot/initramfs-$(uname -r).img $(uname -r) Executing: /sbin/dracut -f -v /boot/initramfs-3.10.0-327.el7.x86_64.img 3.10.0-327.el7.x86_64 dracut module 'busybox' will not be installed, because command 'busybox' could not be found! dracut module 'nbd' will not be installed, because command 'nbd-client' could not be found! dracut module 'busybox' will not be installed, because command 'busybox' could not be found! dracut module 'nbd' will not be installed, because command 'nbd-client' could not be found! *** Including module: bash *** *** Including module: nss-softokn *** ... *** Creating image file *** *** Creating image file done ***
Finally, reboot the system and you are done.
As with most things related to Unix, making modifications to the root filesystem, or boot image, can be a little tricky, but renaming a volume group is relatively simple. However, throw in the fact that the volume group holds to root image, and things get a bit dicey. So in this blog, I demonstrated the process for accomplishing that.