Renaming LVM in CentOS 7

tl;dr

vgdisplay # Get the current VG name

Create and assign the variables: old_name (the current VG name) and new_name (desired new VG name)

old_name=
new_name=

Copy&Paste this entire block into your terminal

vgrename -v $old_name $new_name
sed -i "s/\/${old_name}-/\/${new_name}-/g" /etc/fstab;
sed -i "s/\([/=]\)${old_name}\([-/]\)/\1${new_name}\2/g" /boot/grub2/grub.cfg;
dracut -f -v /boot/initramfs-$(uname -r).img $(uname -r);
systemctl reboot -f;

Solution

First get the current VG name:

vgdisplay

Rename it.

vgrename -v old_name new_name

Update /etc/fstab (replace old_name with new_name)

vi /etc/fstab

Update grub.cfg (replace old_name with new_name)

vi /boot/grub2/grub.cfg

Backup boot image if desirable

 cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.bak

Update the boot image

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

Reboot. The -f switch (force) is required. If not included the shutdown process will be called and the system will hang waiting to reboot. If omitted you will need to use Ctrl+Alt+Delete to restart your computer (if you have physical access to it).

systemctl reboot -f


Was this article helpful?

mood_bad Dislike 0
mood Like 0
visibility Views: 1383