Wednesday, May 12, 2010

Renaming a volume group that your root partition is sitting on ....

This week's self inflicted issue was renaming a volume group which had the root partition running on it. My system is running RHEL 5.5. A few twists and turns were made. I would imagine that the lvrename steps could occur after the vgrename. But, I decided to document what worked for me and here it is:

Rename Logical Volumes and Volume Groups
current swap situation:
# swapon -s
Filename Type Size Used Priority
/dev/mapper/VolGroup00-LogVol01 partition 14319608 0 -2
turn off swap
# swapoff -a
# swapon -s
Rename the logical volumes:
# lvrename VolGroup00 LogVol00 root
# lvrename VolGroup00 LogVol01 swap1
# lvrename VolGroup00 LogVol02 tmp
Turn swap back on:
# swapon -a
# lvscan
ACTIVE '/dev/VolGroup00/root' [119.25 GB] inherit
ACTIVE '/dev/VolGroup00/tmp' [2.94 GB] inherit
ACTIVE '/dev/VolGroup00/swap1' [13.66 GB] inherit
Shutdown the server:
# shutdown -h now
Boot server into a linux rescue shell using the RHEL 5.5. installation DVD (or an iso on a usb key). At the Red Hat splash screen and "boot:" prompt enter
# linux rescue
Answer a number of questions
  1. Language: English [ OK ]
  2. Keyboard: us [ OK ]
  3. What type of Media contains the rescue media?: Local CDROM [ OK ]
  4. Do you want to start the Network Interfaces on this system? [ NO ]
  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 ]
A shell appears. Scan for logical volumes. What you need to see is that the scan found the voloume group you wish to rename e.g.
# lvm vgscan
Found VolGroup00

Make sure logical volumes are inactive:
# lvm lvscan
inactive '/dev/VolGroup00/root' [119.25 GB] inherit
inactive '/dev/VolGroup00/tmp' [2.94 GB] inherit
inactive '/dev/VolGroup00/swap1' [13.66 GB] inherit

Rename the volume group:
# lvm vgrename VolGroup00 vg00
Volume group "VolGroup00" successfully renamed to "vg00"

Exit the shell and reboot the server. Leave the RHEL Installation DVD in.
# exit

Go back into linux rescue mode
Answer questions 1 to 4 as above. In step 5 choose to mount system in read write mode.
5. "Rescue" window, choose [ CONTINUE ]

Eventually, a shell will appear. The system files are in /mnt/sysimage. chroot into the system:
# chroot /mnt/sysimage
Label logical volumes:
# e2label /dev/vg00/root /
# e2label /dev/vg00/tmp TMP
# mkswap -L SWAP1 /dev/mapper/vg00-swap1
Setting up swapspace version 1, size = 14663282 kB
LABEL=SWAP1, no uuid
Make a copy of /etc/fstab:
# cp -p /etc/fstab /etc/old/fstab.20100512
Update fstab with correct Labels:
# vim fstab
# diff -uw /etc/old/fstab.20100507 /etc/fstab
--- /etc/old/fstab.20100512 2010-04-13 03:45:12.000000000 -0400
+++ /etc/fstab 2010-05-12 14:45:13.000000000 -0400
@@ -1,8 +1,8 @@
-/dev/VolGroup00/LogVol00 / ext3 defaults 1 1
-/dev/VolGroup00/LogVol02 /tmp ext3 defaults 1 2
+LABEL=/ / ext3 defaults 1 1
+LABEL=TMP /tmp ext3 defaults 1 2
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
-/dev/VolGroup00/LogVol01 swap swap defaults 0 0
+LABEL=SWAP1 swap swap defaults 0 0
Make a copy of grub.conf
# cp -p /boot/grub/grub.conf /boot/grub/old/grub.conf.20100512
Update grub.conf with updated path to root partition and yet to be made
initrd file -> initrd-2.6.18-194.el5.vgrepair.img
# vim /boot/grub/grub.conf
# diff -uw /boot/grub/old/grub.conf.20100512 /boot/grub/grub.conf
--- old/grub.conf.20100512 2010-05-03 11:39:36.000000000 -0400
+++ grub.conf 2010-05-12 15:17:41.000000000 -0400
@@ -4,7 +4,7 @@
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
-# kernel /vmlinuz-version ro
+# kernel /vmlinuz-version ro root=/dev/vg00/root
# initrd /initrd-version.img
@@ -13,5 +13,9 @@
title Red Hat Enterprise Linux Server (2.6.18-194.el5)
root (hd0,0)
- kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/VolGroup00/root # rhgb quiet crashkernel=128M@16M
+ kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/vg00/root rhgb # quiet crashkernel=128M@16M
+ initrd /initrd-2.6.18-194.el5.vgrepair.img
+title Red Hat Enterprise Linux Server (2.6.18-194.el5)
+ root (hd0,0)
+ kernel /vmlinuz-2.6.18-194.el5 ro root=/dev/vg00/root rhgb # quiet crashkernel=128M@16M
initrd /initrd-2.6.18-194.el5.img
Make a new initrd image - to match entry in grub.conf:
# mkinitrd /boot/initrd-2.6.18-194.el5.vgrepair.img 2.6.18-194.el5
This takes some time and there is no output.

Exit from shell:
# exit
and from linux rescue
# exit
System begins to reboot. When it has finished shutting down services, but before it begins to start them, remove the dvd. At the menu choose the VG Repair kernel (or leave and let the system boot into the default)

Good luck,


Miroslav ġurian said...

Thank you man,

I fogot to update initial ramdisk and update grub.cfg at the same time. You have saved my day. Thanks again!

Lunchbox said...

If you're using e2labels in fstab, you may just want to commit to that in grub as well -- then, if you reorder things so that your system reboots with e2labels fstab, and you've got that working, the rename operations will go that much more smoothly.

I'd strongly recommend that (for people discovering this post years later like me) if there's a choice: sever the dependency on the literal volume names in fstab and grub, bounce once, then proceed to do the renames. Ideally, you'll cut down the amount of time spent in Rescue.