How to rename the volume group for root and swap on Alma Linux 9?

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to rename the volume group for root and swap using Alma Linux 9

First steps

For this post, an Alma Linux 9 installation using LVM is assumed. So, this should not be a problem.

First, log in as root or some other user with root permissions.

It never hurts to update the system and install dracut

dnf update && dnf install dracut

After that, reboot the system.

Then, check the current configuration

vgs

Sample output

  VG        #PV #LV #SN Attr   VSize   VFree
  almalinux   1   2   0 wz--n- <31.00g    0 

Now check the configuration of the group

lvs almalinux

You will get an output screen like this

  LV   VG        Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root almalinux -wi-ao---- <28.77g                                                    
  swap almalinux -wi-ao----  <2.23g  
Current volume group status
Current volume group status

Remember that the name may change on your system.

Rename the volume group for root and swap on Alma Linux 9

Now rename the group with the following command

vgrename almalinux vg-root
  Volume group "almalinux" successfully renamed to "vg-root"

Then, verify the change

vgs
Rename Volume group
Rename Volume group

As you have changed the volume, you need to update the /etc/fstab file

vi /etc/fstab

And replace all references to the old name with the new one. Then, save the changes and close the editor.

We have to do the same with the grub file /boot/grub2/grub.cfg.

sed -i 's/almalinux/root-vg/g' /boot/grub2/grub.cfg

Verify changes

cat /boot/grub2/grub.cfg | grep root-vg

Sample output

  set kernelopts="root=/dev/mapper/root-vg-root ro crashkernel=1G-4G:192M,4G-64G:256M,64G-:512M resume=/dev/mapper/root-vg-swap rd.lvm.lv=root-vg/root rd.lvm.lv=root-vg/swap rhgb quiet "

Then activate the volume group

vgchange -ay
  2 logical volume(s) in volume group "vg-root" now active

And refresh the logical volume attributes

lvchange /dev/vg-root/root --refresh
lvchange /dev/vg-root/swap --refresh

The last step is to create a new initial ramdisk. To achieve this, verify its existence.

ls -al /boot/

Then, back it up

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

And generate a new one.

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

Remember that if you upgraded the kernel, you have to do it if there are other initramfs.

That’s all.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook