The requirement
Here’s the current setup – The root and swap volume reside on the volume group named vg_os.
# vgs VG #PV #LV #SN Attr VSize VFree vg_os 1 2 0 wz--n- 557.88g 1.88g
# lvs vg_os LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv_root vg_os -wi-ao---- 300.00g lv_swap vg_os -wi-ao---- 256.00g
We need to change the name of VG from vg_os to root_vg. Below is step by step procedure to do the same.
1. Renaming the volume group
# vgs VG #PV #LV #SN Attr VSize VFree vg_os 1 2 0 wz--n- 557.88g 1.88g
# vgrename vg_os root_vg Volume group "vg_os" successfully renamed to "root_vg"
# vgs VG #PV #LV #SN Attr VSize VFree root_vg 1 2 0 wz--n- 557.88g 1.88g
2. Modify the /etc/fstab
Replace references to the old VG name ( vg_os ) with the new VG name ( root_vg ) in the files /etc/fstab :
# vi /etc/fstab /dev/mapper/root_vg-lv_data /data ext4 defaults 1 2 /dev/mapper/root_vg-lv_swap swap swap defaults 0 0
3. Update the GRUB2 configuration file
Update The GRUB2 Configuration File: “/boot/grub2/grub.cfg” with new VG name (root_vg) instead of old VG name(vg_os).
Before
# cat /boot/grub2/grub.cfg | grep vg_os linux16 /vmlinuz-3.10.0-514.2.2.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet LANG=en_US.UTF-8 systemd.log_level=debug systemd.log_target=kmsg linux16 /vmlinuz-3.10.0-514.2.2.el7.x86_64 root=/dev/mapper/vg_os-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=vg_os/lv_root rd.lvm.lv=vg_os/lv_swap rhgb quiet LANG=en_US.UTF-8
Change the occurrences of vg_os with root_vg using sed:
# sed -i 's/vg_os/root_vg/g' /boot/grub2/grub.cfg
After
# cat /boot/grub2/grub.cfg | grep root_vg linux16 /vmlinuz-3.10.0-514.2.2.el7.x86_64 root=/dev/mapper/root_vg-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=root_vg/lv_root rd.lvm.lv=root_vg/lv_swap rhgb quiet LANG=en_US.UTF-8 systemd.log_level=debug systemd.log_target=kmsg linux16 /vmlinuz-3.10.0-514.2.2.el7.x86_64 root=/dev/mapper/root_vg-lv_root ro nomodeset crashkernel=auto rd.lvm.lv=root_vg/lv_root rd.lvm.lv=root_vg/lv_swap rhgb quiet LANG=en_US.UTF-8
4. activate new VG and refresh volumes
Now, activate the volume group:
# vgchange -ay
Change attributes of a logical volume. Do it for all logical volumes:
# lvchange /dev/root_vg/lv_root --refresh # lvchange /dev/root_vg/lv_swap --refresh
5. Create new initial ramdisk
Run the following commands to make a new initial ramdisk image for kernels. Make sure to take the backup of existing initramfs before rebuilding.
# ls -al /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img -rw------- 1 root root 19991626 Mar 22 18:29 /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img
# uname -r 3.10.0-514.2.2.el7.x86_64
# cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.$(date +%m-%d-%H%M%S).bak
# mkinitrd -f -v /boot/initramfs-$(uname -r).img $(uname -r) Executing: /usr/sbin/dracut -f -v /boot/initramfs-3.10.0-514.2.2.el7.x86_64.img 3.10.0-514.2.2.el7.x86_64 *** Including module: bash *** *** Including module: nss-softokn *** *** Including module: i18n *** *** Including module: network *** *** Including module: ifcfg *** *** Including module: drm *** *** Including module: plymouth *** *** Including module: dm *** Skipping udev rule: 64-device-mapper.rules Skipping udev rule: 60-persistent-storage-dm.rules Skipping udev rule: 55-dm.rules *** Including module: kernel-modules *** *** Including module: lvm *** Skipping udev rule: 64-device-mapper.rules Skipping udev rule: 56-lvm.rules Skipping udev rule: 60-persistent-storage-lvm.rules *** Including module: fcoe *** *** Including module: fcoe-uefi *** *** Including module: resume *** *** Including module: rootfs-block *** *** Including module: terminfo *** *** Including module: udev-rules *** Skipping udev rule: 91-permissions.rules *** Including module: biosdevname *** *** Including module: systemd *** *** Including module: usrmount *** *** Including module: base *** *** Including module: fs-lib *** *** Including module: shutdown *** *** Including module: uefi-lib *** *** Including modules done *** *** Installing kernel module dependencies and firmware *** *** Installing kernel module dependencies and firmware done *** *** Resolving executable dependencies *** *** Resolving executable dependencies done*** *** Hardlinking files *** *** Hardlinking files done *** *** Stripping files *** *** Stripping files done *** *** Generating early-microcode cpio image *** *** Constructing GenuineIntel.bin **** *** Store current command line parameters *** *** Creating image file *** *** Creating image file done ***