HOW TO RENAME VG AND LV IN REDHAT/CENTOS 7

1/2

Sometimes we need or want to change volume groups and/or logical volume names. You should be carefull when you modify root volume group because boot partition is located there. In this article we will see how to do it in a proper way.

Here are detailed informations about my VG, LV and mount points.

I want to rename “ cl “ volume group and “root” logical volume. Let’s start with volume group first.

The command is vgrename oldvg newvg

Then we will do same for logical volume. Command syntax is still the same:

lvrename /dev/newvg/oldlv  /dev/newvg/newlv

Here, as you noticed when you use tab bash will complete by new VG name, so root_vg will appear first time here. Then you should specify current LV name. Second argument is new LV name, where

/dev/root_vg/lv_root.

Do no forget to modify /etc/fstab

Above I modified first line with new VG and LV name;

/dev/mapper/root_vg-lv_root     /                       ext4    defaults        1 1

I also did the same for swap volume because it’s under root VG. I simply changed VG name.

/dev/mapper/root_vg-swap     swap                    swap    defaults        0 0

Now, you should pay attention we have to remake our grub configuration file. If not, your system risk to be crashed during to boot process.

[root@host ~]# cat /etc/default/grub

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT=”console”

GRUB_CMDLINE_LINUX=”crashkernel=auto rd.lvm.lv=cl/root rd.lvm.lv=cl/swap rhgb quiet”

GRUB_DISABLE_RECOVERY=”true”

Let’s make changes in “GRUB_CMDLINE_LINUX” line, add here new VG, LV names as:

[root@host ~]# cat /etc/default/grub

GRUB_TIMEOUT=5

GRUB_DISTRIBUTOR=”$(sed ‘s, release .*$,,g’ /etc/system-release)”

GRUB_DEFAULT=saved

GRUB_DISABLE_SUBMENU=true

GRUB_TERMINAL_OUTPUT=”console”

GRUB_CMDLINE_LINUX=”crashkernel=auto rd.lvm.lv=root_vg/lv_root rd.lvm.lv=root_vg/swap rhgb quiet”

GRUB_DISABLE_RECOVERY=”true”

Activate volume group by vgchange -ay

vg_logmog is not important because we did not make any change.

For all logical volumes that you renamed refresh their attributes:

By the way, I will just show the swap information in order to be sure that after reboot all changes will available.

Next step is to take a backup of initramfs then rebuild.

You can use following commands; first will create a backup file, second will rebuild initramfs.

# cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.$(date +%m-%d-%H%M%S).bak

# dracut -v -f /boot/initramfs-$(uname -r).img $(uname -r)

Continue to read