November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Rename volume group on which your root(/) partition resides.

We had few of the servers which was similar in file systems, disk partitions, applications, etc .., but was exception in only Volume Group(VG). So I had cloned the systems and thought of renaming the VG, but since root Logical Volume(LV) was configured on the same VG was unable to un-mount online. I had to bring down the server to perform below steps.
Below has been performed on CentOS-6.3 32-bit kernel version – 2.6.32-279.el6
 
Since it is root volume, we need to umount the file system, insert the CentOS CD/DVD to boot server in rescue shell.
#boot: linux rescue
when it prompts for the questions, choose your answers.
Question 5 : Rescue window
Offers to mount Linux installation in rw, read only or not at all. Either way, we will be provided with a shell. As this system’s root partition is on a logical volume in the volume group we wish to rename, we must not mount the system. [ SKIP ]
Make sure all your logical volumes are OFFLINE
# lvm lvscan
  INACTIVE            ‘/dev/vg_pcmk1/home’ [1.00 GiB] inherit
  INACTIVE            ‘/dev/vg_pcmk1/rootvg’ [13.18 GiB] inherit
  INACTIVE            ‘/dev/vg_pcmk1/swap’ [1.46 GiB] inherit
#
#lvm vgscan
found volume group vg_pcmk1
.
.
(output omitted)
– Rename the volume group
#lvm rename vg_pcmk1 vg_pcmk2
– Exit the shell and reboot the server. Let CentOS DVD be in the disk.
#exit
– Reboot the server in the rescue environment and while in Question 5, choose Continue
 
Eventually, a shell will appear. The system files are in /mnt/sysimage.  chroot into the system:
# chroot /mnt/sysimage
sh-4.1#vim /etc/fstab
– Change the entries of the volume group for the logical volumes which are residing.
# grep vg_pcmk2 /etc/fstab
/dev/mapper/vg_pcmk2-rootvg /                       ext4    defaults        1 1
/dev/mapper/vg_pcmk2-home /home                   ext4    defaults      1 2
/dev/mapper/vg_pcmk2-swap swap                    swap    defaults        0 0
#
– Change an entry in grub.conf file.
#vim /boot/grub/grub.conf
# grep vg_pcmk2 /boot/grub/grub.conf
        kernel /vmlinuz-2.6.32-279.el6.i686 ro root=/dev/mapper/vg_pcmk2-rootvg rd_LVM_LV=vg_pcmk2/rootvg rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rd_LVM_LV=vg_pcmk2/swap rhgb quiet
#
– Create a newly initrd image as below.
# tail -1 /boot/grub/grub.conf
        initrd /initrd-2.6.32-279.el6.i686.img
#
As updated above, create new initrd image and this will take some time and will have no output.
#mkinitrd /boot/initrd-$(uname -r).img $(uname -r)
– Exit from shell:
# exit
– Exit from Linux rescue:
# exit
– Remove the CD and boot the server.
Once your server logins, check the VG name, it would be successfully changed.
# df -h | grep vg_pcmk2
/dev/mapper/vg_pcmk2-rootvg
/dev/mapper/vg_pcmk2-home
#
NOTE: If no proper entries in root volume being made, kernel gets PANIC and will not sync and kills init process.

Since this is a new blog, I’ve been trolling through my Wiki looking for things that if not of broad general interest, are so esoteric and complicated that it might help some poor slob(s) Googling in futility, slowly losing the will to live….  We’ve all been that poor slob at one time ;->

Even if you’re not interested in renaming an LVM Volume Group per se, this blog post also demonstrates how to tweak an initial RAM disk, which I guess might be of broader interest than the special case in which it’s discussed.

Why Rename a VG?

Generally, you should NEVER rename LVM Volume Groups unless you like pain. Running ‘vgrename’ will change the name of the Volume Group- EXCEPT where it matters most: ‘initrd’ . The Initial RAM Disk references the Volume Group when trying to mount the root file system. If the Volume Group is incorrectly specified there, obviously the system will not boot.

A client asked me to rebuild a KVM Hypervisor several years ago.  Part of the brief was to migrate the VM’s on it which were running as .img files in /var/lib/libvirt to LVM partitions on the KVM Hypervisor itself.  Unfortunately for me, the previous sysadmin had used the default “VolGroupXX” naming convention inside all the VMs.  When the LVM structures were internal to the VM itself in their .img files they co-existed happily together despite all having the same Volume Group names.  However, when the VMs’ filesystems were squirted into LVM partitions on the KVM host, that’s where the conflict between shared VG names arose.

As a consequence, assuming the KVM Hypervisor Volume Group is itself not named VolGroupXXtoo, every VM you migrate will have a conflict with other VM’s VolGroupXX naming scheme unless you change them .  Good grief Charlie Brown.   This can all be avoided by naming the Volume Group after the hostname it lives on to ensure its’ uniqueness. But that wasn’t an option and I had to rename the Volume Groups.

Rename the Volume Group of a VM

This example entails migrating a named “myVM.img” running from a file to an LVM partition on the Hypervisor hosting it.

1. Create LVM partition on the Hypervisor where we can dd the VM into:

lvcreate  -L 10G -n myVM  KVMhypervisorVolGroup00

2. Unmount the running VM, “myVM.img” running from /var/lib/libvirt/images/:

unmount /var/lib/libvirt/images/

3. Squirt the VM’s image file into the LVM partition “myVM” just created on the Hypervisor. In this example, the VM file we’re moving to the partition resides in the default folder for KVM images. As a general practice when using dd, ALWAYS double check you haven’t flip-flopped the input and output parameter values before hitting the return key.

dd if=/var/lib/libvirt/images/myVM.img of=/dev/KVMhypervisorVolGroup00/myVM

4. Create device maps for the new partition where the VM has been moved so Device Mapper can find it:

kpartx -av /dev/KVMhypervisorVolGroup00/myVM

5. Scan and rebuild Volume Group caches:

vgscan

6. Determine the UUID of the of /dev/KVMhypervisorVolGroup00/myVM (the LV which the VM was migrated into):

vgdisplay

If you’re trying to identify two hosts sharing the same Volume Group name, you need to do this by UUID.  It is CRUCIAL that you identify correctly the UUID of VolGroup00 belonging to the VM you want to modify. Check the space of the “VG Size” details in the output of the vgdisplay command to differentiate between which UUID belongs to which VM.

7. Rename the Volume Group FROM “/dev/VolGroup00” TO “/dev/VolGroupMyVM.” By using the convention of replacing “00” in the Volume Group name with the VM’s hostname, we can ensure that the VG name is unique and we won’t bump into the problem of duplicate Volume Group names if we move this VM somewhere else in the future.

Triple check that you are specifying the UUID of the VM’s VolGroup00 you believe that you are altering before pulling the trigger! The reason we’re feeding the ‘UUID’ in lieu of the Volume Group name ‘VolGroup00 to the vgrename command is that the UUID is the only way to accurately distinguish between the two “VolGroup00” ‘s where several are shown.

vgrename UUID-goes-here /dev/VolGroupMyVM

8.  vgrename is only capable of renaming the Volume Group- it doesn’t change the UUID of our VM, which we need to do to get the Hypervisor to stop puking errors all over us about duff LVM Volume Groups.  Let’s change this so the VM is absolutely unique from the VM we are migrating away from:

vgimportclone -n myVM /dev/mapper/myVM

9.  Update any references to the VM’s UUID: Since we’ve changed the UUID, anywhere this appears, ie the VM’s fstab, this must also be updated.

10. Mount the VM to enable working on it’s filesystem:

mkdir /mnt/myVM
mount /dev/mapper/myVM /mnt/myVM

11. Edit the VM’s grub configuration to reflect the change in the Volume Group name:

vi /mnt/myVM/boot/grub/grub.conf

FROM:

kernel /vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=/dev/mapper/VolGroup00-LogVol00 rd_LVM_LV=VolGroup00/LogVol00 rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk crashkernel=auto selinux=0 nomodeset

TO:

kernel /vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=/dev/mapper/VolGroupMyVM-LogVol00 rd_LVM_LV=VolGroupMyVM/LogVol00 rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk crashkernel=auto selinux=0 nomodeset

Modify initrd

12. Edit Volume Group specified in the VM’s initrd (Initial RAM Disk) so the root partition can be found and booted: Make a directory to where we can edit a copy of our initrd image:

mkdir /mnt/myVM/initrd_edited

Copy the initrd image to our work directory:

cp -p /mnt/myVM/boot/initrd_image_to_edit.img /mnt/myVM/initrd_edited/

Change the name of the original initrd image to .OLD:

mv /mnt/myVM/boot/initrd_image_to_edit.img  /mnt/myVM/boot/initrd_image_to_edit.img.OLD

Change directories to where we copied the initrd image to work on it:

cd /mnt/myVM/initrd_edited/

Decompress the initrd image so it can be edited:

cat initrd-*|gzip -d|cpio -i

Delete the compressed copy in THIS directory:

rm initrd-*

Change the Volume Group in init FROM: VolGroup00 TO: VolGroupMyVM

vi init

Finally, compress the modified initrd back into an image and squirt the compressed image back to the VM’s /boot directory.

*!!!DANGER WILL ROBINSON, DANGER!!*: Ensure that you pipe this to the correct directory to avoid overwriting the Hypervisor’s initrd!!!

find|cpio -H newc -o|gzip>../originalInitrdName.img

13. Edit the VM’s fstab to change references of VolGroup00 TO VolGroupMyVM so everything will mount correctly:

vi /mnt/myVM/etc/fstab

14. If the VM is started without fixing fstab, it can still be done. Since the boot will hang without having first updated fstab with the new Volume Group name prior too booting the host, nothing will mount correctly and you’ll be dropped into a maintenance prompt:

Enter root password at maintenance prompt
mount -o remount -rw /
vi /etc/fstab
Make your changes to fstab, save them and finally:
shutdown -r now

15. Unmount the LVM volume that you mounted to work on the VM:

umount /mnt/myVM

Done. Repeat for each VM you’re dropping into a partition on the Hypervisor with the Volume Group “VolGroup00” …

Think that about does it.   Hope somebody found this useful to alleviate the pain I had correcting the mess.  If you find working through the steps that I’ve made any omissions/transpositions errors, lemme know and I’ll update the blog post.

 

 

Rename a Volume Group in Red Hat Enterprise Linux 6 (RHEL6)

WARNING:  Perform this at your own risk and double check LVM documentation!
* As always this will work perfectly well in CentOS 6.

As I was preparing a new VMware guest host to be my template master I realized AFTER the  RHEL6 install that I failed to rename the default volume group from vg_hostname-lv_root to something more generic for a VM template server.

This was surprisingly simple and straight forward, even booted up onto the guest host’s boot drive – no need to boot into rescue or emergency mode – just don’t muk it up.  Simply do the following (and be careful):

As root user (or using sudo) be sure to make backup copies of these two files in case you muk it up, and ensure you know how to boot up in rescue mode with other boot media.
# cp /etc/fstab /etc/fstab.orig
# cp /boot/grub/grub.conf /boot/grub/grub.conf.orig

Rename your volume group (vg)

# vgrename /dev/vg_OLDname /dev/vg_NEWname

Now change all instances of the old volume group in the following files:

/etc/grub.conf  (which is a symbolic link to /boot/grub/grub.conf)

/etc/fstab

mv /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.backup

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

 dracut

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>