ル-ツパーティションの名変Centos6.5

Hi,
I installed CentOS virtual machines to play around and train my Linux skills. The thing is I had no idea of the exact role of the machine when I installed it and called it client. However after a while I decided to call it server, so I had to rename every volume group and logical volume accordingly.

LVM provides you with commands to simply do that (vgrename, lvrename) but at least when it comes to reboot the root partitions it is not enough. When I rebooted my virtual machine after a while it just ended with a kernel panic.

Proper method to rename a root Volume Group (CentOS 6.5)

In the first place just have a look at what your VG/LV are named:

[root@Linux-client ~]# vgs
  VG             #PV #LV #SN Attr   VSize  VFree
  vg_linuxclient   1   2   0 wz--n- 39,51g    0
[root@Linux-client ~]# lvs
  LV      VG             Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_linuxclient -wi-ao---- 35,63g
  lv_swap vg_linuxclient -wi-ao----  3,88g


Now let say I want to provide this machine to a user and therefore change the naming from linuxclient to linuxuser.

[root@Linux-client ~]# vgrename vg_linuxclient vg_linuxuser
  Volume group "vg_linuxclient" successfully renamed to "vg_linuxuser"
[root@Linux-client ~]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  vg_linuxuser   1   2   0 wz--n- 39,51g    0


So the thing is I thought that it was enough at this step and at reboot it led to the Kernel Panic issue told upper. We now need to update volume groups and the entries in both fstab and grub;conf

[root@Linux-client ~]# vgchange -ay vg_linuxuser
  2 logical volume(s) in volume group "vg_linuxuser" now active
[root@Linux-client ~]# vi /etc/fstab
[root@Linux-client ~]# cat /etc/fstab


#
# /etc/fstab
# Created by anaconda on Tue Mar 25 20:51:20 2014
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/vg_linuxuser-lv_root /                       ext4    defaults        1 1
UUID=dc00fde4-a52a-46fe-bee4-f3d86995eecb /boot                   ext4    defaults        1 2
/dev/mapper/vg_linuxuser-lv_swap swap                    swap    defaults        0 0
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
[root@Linux-client ~]# vi /boot/grub/grub.conf
[root@Linux-client ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# 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 root=/dev/mapper/vg_linuxuser-lv_root
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-431.11.2.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.11.2.el6.x86_64 ro root=/dev/mapper/vg_linuxuser-lv_root rd_NO_LUKS rd_LVM_LV=vg_linuxuser/lv_swap rd_NO_MD LANG=fr_FR.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=fr-latin9 rd_LVM_LV=vg_linuxuser/lv_root rd_NO_DM rhgb quiet vga=795
        initrd /initramfs-2.6.32-431.11.2.el6.x86_64.img
title CentOS (2.6.32-431.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/vg_linuxuser-lv_root rd_NO_LUKS rd_LVM_LV=vg_linuxuser/lv_swap rd_NO_MD LANG=fr_FR.UTF-8 SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=fr-latin9 rd_LVM_LV=vg_linuxuser/lv_root rd_NO_DM rhgb quiet vga=795
        initrd /initramfs-2.6.32-431.el6.x86_64.img


Last thing is to update initrd to take our changes.

[root@Linux-client ~]# mkinitrd  --force /boot/initramfs-2.6.32-431.
initramfs-2.6.32-431.11.2.el6.x86_64.img  initramfs-2.6.32-431.el6.x86_64.img
[root@Linux-client ~]# mkinitrd  --force /boot/initramfs-2.6.32-431.11.2.el6.x86_64.img 2.6.32-431.11.2.el6.x86_64
[root@Linux-client ~]# reboot
[root@Linux-client ~]#
Broadcast message from root@Linux-client
        (/dev/pts/0) at 17:48 ...

The system is going down for reboot NOW!


My main source (see Sources bellow) states that if we do not reboot then it fails but is worked for me by just adding the --force option to mkinitrd.

Result of doing it unaware

So we know how to do it properly and I should have put this section before the previous one which was originally the case but as I first did the changes to present the proper way to rename a root Volume Group. So in this section I will try to put it back in the original state (renaming back from linuxuser to linuxclient) and doing nothing else. As I could not connect through SSH (as the system simply won't boot) I will add screenshots instead of copying/pasting the output from a console as soon as needed.

[root@Linux-client ~]# vgs
  VG           #PV #LV #SN Attr   VSize  VFree
  vg_linuxuser   1   2   0 wz--n- 39,51g    0
[root@Linux-client ~]# lvs
  LV      VG           Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_linuxuser -wi-ao---- 35,63g
  lv_swap vg_linuxuser -wi-ao----  3,88g
[root@Linux-client ~]# vgrename vg_linuxuser vg_linuxclient
  Volume group "vg_linuxuser" successfully renamed to "vg_linuxclient"
[root@Linux-client ~]# lvs
  LV      VG             Attr       LSize  Pool Origin Data%  Move Log Cpy%Sync Convert
  lv_root vg_linuxclient -wi-ao---- 35,63g
  lv_swap vg_linuxclient -wi-ao----  3,88g
[root@Linux-client ~]# reboot
[root@Linux-client ~]#
Broadcast message from root@Linux-client
        (/dev/pts/0) at 18:07 ...

The system is going down for reboot NOW!


After reboot you get this:
Doesn't look good, right ?
Long time no see a Kernel Panic but it does not help me much understand where the issue is (I did the change and shut-down the PC for a while and then BAM ! I get this.)

To make it more precise about what the issue seems to be you just need to remove the quiet option at boot by editing the boot arguments. When you see the countdown press a key to get to GRUB menu and highlight the version you want to run and press 'a' key. Note that is you are not using a QWERTY keyboard you might need to press another key( I need to press 'q' on my AZERTY keyboard for instance). Do your thing.

It is clearer to see where the issue lies. Obvious if you did the change a minute ago but helpful if some time have gone before you boot the machine again or if you were not aware of the changes made.

So now you can see that it is still trying to use the old Volume Group linuxuser instead of the actual linuxclient we renamed back into. therefore the Logical Volumes cannot be found either.

Trying to fix that mess

Now what can be done to repair this ?
The output tells you about an rdshell boot option but it has minimal commands so not very pleasant to work with. Better go with CentOS disk in rescue mode to try to fix it. Follow the menus and go to a console then chroot to /mnt/sysimage/ or whatever the partition had been mounted to.
At reboot you may also meet this message if you're using VirtualBox as I'm doing now.

FATAL: INT18: BOOT FAILURE

It is told to be a bug with VB so no worries.

Just before doing any more changes, let's have a look at  the LVM cache file and see that it still have old entries for linuxuser Volume Group.

Even after renaming the VG in its cache LVM still consider the old name.


Apply the vgchange command as in the previous chapter and you'll see there will be new updated entries but the old ones are still present. Actually I tried to delete this files after I had my Linux working thinking it would rebuilt it at boot time for instance but it doesn't seem so. you can also delete some files in /etc/lvm/archives with the old Volume Group in name if you want to.

Now let's update the files and start with grub.conf file. Instead of doing it manually I just used sed to make sure it is fast, simple and reliable. So basically just substitute your old VG name by the new one with sed and redirect the output to a temporary file. If you try to overwrite the original file you will end up with an empty one instead. Therefore we need that temp file which be renamed afterwards.

See that our change has been made. Compare the naming in the upper sample of grub.conf and the lower sample.

Let's do the same thing with fstab.

Changing fstab. Did a grep on it to show the changes.

Then we update our initrd file and reboot. Unlike the screenshot you need to use -f or --force if you overwrite an existing file.


 At boot you may see a message showing that LV are properly found, disks are checked and SELINUX needs to relabel the file-system. When it's done the PC will reboot and then boot properly.

At reboot you will see SELinux being aware of the changes made.

It is not always that simple to make changes when you don't really know the full procedure to have things done properly leading to future problems. In the first place I though like a Windows user when I saw that message. What is that mess? Should reinstall my system from scratch?
Then I got back to conscious state. First understand why it does not load (error messages) and then find the way to fix this (Searching the web). I'm happy I could fix this quite simply instead of doing the Windows common procedure before any kind of non booting system. There must be a way to repair this kind of errors.

Sources:

Browsed forums to get some hints here and there but some pages where definitely way more helpful to me.

Please don't touch the screen article It has all the relevant information to do it properly. I did it a bit differently that he does however. No rescue mode or any reboot.
EyeMen About the Error with VirtualBox. Before I found this I actually tried to update installation from install CD. Working but useless.