{"id":4062,"date":"2014-12-10T00:37:23","date_gmt":"2014-12-09T16:37:23","guid":{"rendered":"http:\/\/rmohan.com\/?p=4062"},"modified":"2014-12-10T00:38:45","modified_gmt":"2014-12-09T16:38:45","slug":"rename-volume-group-on-which-your-root-partition-resides","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4062","title":{"rendered":"Rename volume group on which your root(\/) partition resides."},"content":{"rendered":"<div class=\"gmail_default\">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<b> root<\/b>\u00a0Logical 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.<\/div>\n<div class=\"gmail_default\"><\/div>\n<div class=\"gmail_default\">Below has been performed on <b>CentOS-6.3 32-bit kernel version &#8211;\u00a02.6.32-279.el6<\/b><\/div>\n<div class=\"gmail_default\"><b>\u00a0<\/b><\/div>\n<div class=\"gmail_default\">Since it is root volume, we need to umount the file system, insert the CentOS CD\/DVD to <b>boot <\/b>server in <b>rescue shell.<\/b><\/div>\n<div class=\"gmail_default\">#boot: linux rescue<\/div>\n<div class=\"gmail_default\"><\/div>\n<div class=\"gmail_default\">when it prompts for the questions, choose your answers.<\/div>\n<div class=\"gmail_default\">Question 5 : Rescue window<\/div>\n<div class=\"gmail_default\">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&#8217;s root partition is on a logical volume in the volume group we wish to rename, we must not mount the system. [ SKIP ]<\/div>\n<div class=\"gmail_default\"><\/div>\n<div class=\"gmail_default\">Make sure all your logical volumes are OFFLINE<\/div>\n<div class=\"gmail_default\"><\/div>\n<div class=\"gmail_default\">\n<div class=\"gmail_default\"># lvm lvscan<\/div>\n<div class=\"gmail_default\">\u00a0 INACTIVE \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8216;\/dev\/vg_pcmk1\/home&#8217; [1.00 GiB] inherit<\/div>\n<div class=\"gmail_default\">\u00a0 INACTIVE \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8216;\/dev\/vg_pcmk1\/rootvg&#8217; [13.18 GiB] inherit<\/div>\n<div class=\"gmail_default\">\u00a0 INACTIVE \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0&#8216;\/dev\/vg_pcmk1\/swap&#8217; [1.46 GiB] inherit<\/div>\n<div class=\"gmail_default\">#<\/div>\n<div><\/div>\n<div>#lvm vgscan<\/div>\n<div>found volume group vg_pcmk1<\/div>\n<div>.<\/div>\n<div>.<\/div>\n<div>(output omitted)<\/div>\n<div><\/div>\n<div>&#8211; Rename the volume group<\/div>\n<div>#lvm rename\u00a0vg_pcmk1\u00a0vg_pcmk2<\/div>\n<div><\/div>\n<div>&#8211; Exit the shell and reboot the server. Let CentOS DVD be in the disk.<\/div>\n<div>#exit<\/div>\n<div><\/div>\n<div>&#8211; Reboot the server in the rescue environment and while in Question 5, choose <b>Continue<\/b><\/div>\n<div><b>\u00a0<\/b><\/div>\n<div>\n<div>Eventually, a shell will appear. The system files are in \/mnt\/sysimage. \u00a0chroot into the system:<\/div>\n<div># chroot \/mnt\/sysimage<\/div>\n<div><\/div>\n<div>sh-4.1#vim \/etc\/fstab<\/div>\n<div>&#8211; Change the entries of the volume group for the logical volumes which are residing.<\/div>\n<div><\/div>\n<div>\n<div># grep vg_pcmk2 \/etc\/fstab<\/div>\n<div>\/dev\/mapper\/vg_pcmk2-rootvg \/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ext4 \u00a0 \u00a0defaults \u00a0 \u00a0 \u00a0 \u00a01 1<\/div>\n<div>\/dev\/mapper\/vg_pcmk2-home \/home \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ext4 \u00a0 \u00a0defaults \u00a0 \u00a0 \u00a01 2<\/div>\n<div>\/dev\/mapper\/vg_pcmk2-swap swap \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0swap \u00a0 \u00a0defaults \u00a0 \u00a0 \u00a0 \u00a00 0<\/div>\n<div>#<\/div>\n<\/div>\n<div><\/div>\n<div>&#8211; Change an entry in grub.conf file.<\/div>\n<div>#vim \/boot\/grub\/grub.conf<\/div>\n<div>\n<div># grep vg_pcmk2 \/boot\/grub\/grub.conf<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 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 \u00a0KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rd_LVM_LV=vg_pcmk2\/swap rhgb quiet<\/div>\n<div>#<\/div>\n<\/div>\n<div><\/div>\n<div>&#8211; Create a newly initrd image as below.<\/div>\n<div>\n<div># tail -1 \/boot\/grub\/grub.conf<\/div>\n<div>\u00a0 \u00a0 \u00a0 \u00a0 initrd \/initrd-2.6.32-279.el6.i686.img<\/div>\n<div>#<\/div>\n<\/div>\n<div><\/div>\n<div>As updated above, create new initrd image and this will take some time and will have no output.<\/div>\n<div>#mkinitrd \/boot\/initrd-$(uname -r).img $(uname -r)<\/div>\n<div><\/div>\n<div>\n<div>&#8211; Exit from shell:<\/div>\n<div># exit<\/div>\n<div><\/div>\n<div>&#8211; Exit from Linux rescue:<\/div>\n<div># exit<\/div>\n<\/div>\n<div><\/div>\n<div>&#8211; Remove the CD and boot the server.<\/div>\n<div><\/div>\n<div>Once your server logins, check the VG name, it would be successfully changed.<\/div>\n<div># df -h | grep vg_pcmk2<\/div>\n<div>\n<div>\/dev\/mapper\/vg_pcmk2-rootvg<\/div>\n<div>\/dev\/mapper\/vg_pcmk2-home<\/div>\n<div>#<\/div>\n<\/div>\n<div><\/div>\n<div>NOTE: If no proper entries in root volume being made,<b> kernel gets PANIC and will not sync and kills init process.<\/b><\/div>\n<div><\/div>\n<div><\/div>\n<div>\n<p>Since this is a new blog, I\u2019ve 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\u2026. \u00a0We\u2019ve all been that poor slob at one time ;-&gt;<\/p>\n<p>Even if you\u2019re 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\u2019s discussed.<\/p>\n<h2>Why Rename a VG?<\/h2>\n<p>Generally, you should NEVER rename LVM Volume Groups unless you like pain. Running \u2018<b>vgrename\u2019<\/b>\u00a0will change the name of the Volume Group- EXCEPT where it matters most: \u2018<b>initrd\u2019<\/b>\u00a0. 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.<\/p>\n<p>A client asked me to rebuild a KVM Hypervisor several years ago. \u00a0Part of the brief was to migrate the VM\u2019s on it which were running as <em>.img<\/em> files in <em>\/var\/lib\/libvirt<\/em> to LVM partitions on the KVM Hypervisor itself. \u00a0Unfortunately for me, the previous sysadmin had used the default \u201c<em>VolGroupXX<\/em>\u201d naming convention inside all the VMs. \u00a0When 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. \u00a0However, when the VMs\u2019 filesystems were squirted into LVM partitions on the KVM host, that\u2019s where the conflict between shared VG names arose.<\/p>\n<p>As a consequence, assuming the KVM Hypervisor Volume Group is itself not named\u00a0<em>VolGroupXX<\/em>too, every VM you migrate will have a conflict with other VM\u2019s <em>VolGroupXX<\/em> naming scheme unless you change them . \u00a0Good grief Charlie Brown. \u00a0 This can all be avoided by naming the Volume Group after the hostname it lives on to ensure its\u2019 uniqueness. But that wasn\u2019t an option and I had to rename the Volume Groups.<\/p>\n<h2>Rename the Volume Group of a VM<\/h2>\n<p>This example entails migrating a named \u201c<em>myVM.img<\/em>\u201d running from a file to an LVM partition on the Hypervisor hosting it.<\/p>\n<p>1. Create LVM partition on the Hypervisor where we can dd the VM into:<\/p>\n<pre>lvcreate  -L 10G -n myVM  KVMhypervisorVolGroup00<\/pre>\n<p>2. Unmount the running VM, \u201c<em>myVM.img<\/em>\u201d running from \/var\/lib\/libvirt\/images\/:<\/p>\n<pre>unmount \/var\/lib\/libvirt\/images\/<\/pre>\n<p>3. Squirt the VM\u2019s image file into the LVM partition \u201c<em>myVM<\/em>\u201d just created on the Hypervisor. In this example, the VM file we\u2019re moving to the partition resides in the default folder for KVM images. As a general practice when using dd,\u00a0<b>ALWAYS<\/b>\u00a0double check you haven\u2019t flip-flopped the input and output parameter values before hitting the return key.<\/p>\n<pre>dd if=\/var\/lib\/libvirt\/images\/myVM.img of=\/dev\/KVMhypervisorVolGroup00\/myVM<\/pre>\n<p>4. Create device maps for the new partition where the VM has been moved so Device Mapper can find it:<\/p>\n<pre>kpartx -av \/dev\/KVMhypervisorVolGroup00\/myVM<\/pre>\n<p>5. Scan and rebuild Volume Group caches:<\/p>\n<pre>vgscan<\/pre>\n<p>6. Determine the UUID of the of \/dev\/KVMhypervisorVolGroup00\/<em><b>myVM<\/b><\/em>\u00a0(the LV which the VM was migrated into):<\/p>\n<pre>vgdisplay<\/pre>\n<p>If you\u2019re trying to identify two hosts sharing the same Volume Group name, you need to do this by UUID. \u00a0It is CRUCIAL that you identify correctly the UUID of <em>VolGroup00<\/em> belonging to the VM you want to modify. Check the space of the \u201cVG Size\u201d details in the output of the vgdisplay command to differentiate between which UUID belongs to which VM.<\/p>\n<p>7. Rename the Volume Group\u00a0FROM \u201c\/dev\/<em>VolGroup<b>00<\/b><\/em>\u201d TO \u201c\/dev\/VolGroup<b>MyVM<\/b>.\u201d By using the convention of replacing \u201c<b>00<\/b>\u201d in the Volume Group name with the VM\u2019s hostname, we can ensure that the VG name is unique and we won\u2019t bump into the problem of duplicate Volume Group names if we move this VM somewhere else in the future.<\/p>\n<p>Triple check that you are specifying the UUID of the VM\u2019s <em>VolGroup00<\/em> you believe that you are altering before pulling the trigger! The reason we\u2019re feeding the \u2018<b>UUID\u2019<\/b>\u00a0in lieu of the Volume Group name \u2018<b><em>VolGroup00<\/em>\u2018<\/b>\u00a0to the\u00a0<i>vgrename\u00a0<\/i>command is that the UUID is the only way to accurately distinguish between the two \u201c<em>VolGroup00<\/em>\u201d \u2018s where several are shown.<\/p>\n<pre>vgrename <em><b>UUID-goes-here<\/b><\/em> \/dev\/<em><strong>VolGroupMyVM\r\n<\/strong><\/em><\/pre>\n<p>8. \u00a0<em>vgrename<\/em> is only capable of renaming the Volume Group- it doesn\u2019t 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. \u00a0Let\u2019s change this so the VM is absolutely unique from the VM we are migrating away from:<\/p>\n<pre>vgimportclone -n <em>myVM<\/em> \/dev\/<b>mapper<\/b>\/<em>myVM\r\n<\/em><\/pre>\n<p>9.\u00a0\u00a0Update any references to the VM\u2019s UUID: Since we\u2019ve changed the UUID, anywhere this appears, ie the VM\u2019s fstab, this must also be updated.<\/p>\n<p>10. Mount the VM to enable working on it\u2019s filesystem:<\/p>\n<pre>mkdir \/mnt\/<em>myVM<\/em>\r\nmount \/dev\/mapper\/<em>myVM<\/em> \/mnt\/<em>myVM\r\n<\/em><\/pre>\n<p>11. Edit the VM\u2019s grub configuration to reflect the change in the Volume Group name:<\/p>\n<pre>vi \/mnt\/<em>myVM<\/em>\/boot\/grub\/grub.conf<\/pre>\n<p><b>FROM:<\/b><\/p>\n<pre>kernel \/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=\/dev\/mapper\/<em><b>VolGroup00<\/b><\/em>-LogVol00 rd_LVM_LV=<em><b>VolGroup00<\/b><\/em>\/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<\/pre>\n<p><b>TO:<\/b><\/p>\n<pre>kernel \/vmlinuz-2.6.32-220.7.1.el6.x86_64 ro root=\/dev\/mapper\/<em><b>VolGroupMyVM<\/b><\/em>-LogVol00 rd_LVM_LV=<b>VolGroupMyVM<\/b>\/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<\/pre>\n<h2>Modify initrd<\/h2>\n<p>12. Edit Volume Group specified in the VM\u2019s\u00a0<b>initrd<\/b>\u00a0(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:<\/p>\n<pre>mkdir \/mnt\/myVM\/initrd_edited<\/pre>\n<p>Copy the initrd image to our work directory:<\/p>\n<pre>cp -p \/mnt\/myVM\/boot\/initrd_image_to_edit.img \/mnt\/myVM\/initrd_edited\/<\/pre>\n<p>Change the name of the original initrd image to\u00a0<b>.OLD<\/b>:<\/p>\n<pre>mv \/mnt\/myVM\/boot\/initrd_image_to_edit.img  \/mnt\/myVM\/boot\/initrd_image_to_edit.img<b>.OLD<\/b><\/pre>\n<p>Change directories to where we copied the initrd image to work on it:<\/p>\n<pre>cd \/mnt\/myVM\/initrd_edited\/<\/pre>\n<p>Decompress the initrd image so it can be edited:<\/p>\n<pre>cat initrd-*|gzip -d|cpio -i<\/pre>\n<p>Delete the compressed copy in THIS directory:<\/p>\n<pre>rm initrd-*<\/pre>\n<p>Change the Volume Group in init FROM:\u00a0<em><b>VolGroup00<\/b><\/em>\u00a0TO:\u00a0<em><b>VolGroupMyVM<\/b><\/em><\/p>\n<pre>vi init<\/pre>\n<p>Finally, compress the modified initrd back into an image and squirt the compressed image back to the VM\u2019s\u00a0<i>\/boot<\/i>\u00a0directory.<\/p>\n<p><b>*!!!DANGER WILL ROBINSON, DANGER!!*:<\/b>\u00a0Ensure that you pipe this to the correct directory to avoid overwriting the Hypervisor\u2019s initrd!!!<\/p>\n<pre>find|cpio -H newc -o|gzip&gt;..\/originalInitrdName.img<\/pre>\n<p>13. Edit the VM\u2019s fstab to change references of\u00a0<em><b>VolGroup00<\/b><\/em>\u00a0TO\u00a0<em><b>VolGroupMyVM<\/b><\/em>\u00a0so everything will mount correctly:<\/p>\n<pre>vi \/mnt\/myVM\/etc\/fstab<\/pre>\n<p>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\u2019ll be dropped into a maintenance prompt:<\/p>\n<pre>Enter root password at maintenance prompt\r\nmount -o remount -rw \/\r\nvi \/etc\/fstab\r\nMake your changes to fstab, save them and finally:\r\nshutdown -r now<\/pre>\n<p>15. Unmount the LVM volume that you mounted to work on the VM:<\/p>\n<pre>umount \/mnt\/myVM<\/pre>\n<p>Done. Repeat for each VM you\u2019re dropping into a partition on the Hypervisor with the Volume Group \u201c<em><strong>VolGroup00<\/strong><\/em>\u201d \u2026<\/p>\n<p>Think that about does it. \u00a0 Hope somebody found this useful to alleviate the pain I had correcting the mess. \u00a0If you find working through the steps that I\u2019ve made any\u00a0omissions\/transpositions errors, lemme know and I\u2019ll update the blog post.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<div class=\"article-header\">\n<h1 class=\"title entry-title\"><a href=\"http:\/\/alinuxworld.blogspot.com\/2012\/07\/rename-volume-group-in-red-hat.html\" rel=\"bookmark\">Rename a Volume Group in Red Hat Enterprise Linux 6 (RHEL6)<\/a><\/h1>\n<\/div>\n<div class=\"article-content entry-content\">\n<div>WARNING:\u00a0 Perform this at your own risk and double check LVM documentation!<\/div>\n<div>* As always this will work perfectly well in CentOS 6.<\/div>\n<div><\/div>\n<p>As I was preparing a new VMware guest host to be my template master I realized AFTER the\u00a0 RHEL6 install that I failed to rename the default volume group from <b>vg_hostname<\/b>-lv_root to something more generic for a VM template server.<\/p>\n<p>This was surprisingly simple and straight forward, even booted up onto the guest host&#8217;s boot drive &#8211; no need to boot into rescue or emergency mode &#8211; just don&#8217;t muk it up.\u00a0 Simply do the following (and be careful):<\/p>\n<div>\n<div>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.<\/div>\n<div># cp \/etc\/fstab \/etc\/fstab.orig<\/div>\n<div># cp \/boot\/grub\/grub.conf \/boot\/grub\/grub.conf.orig<\/div>\n<div><\/div>\n<p>Rename your volume group (vg)<\/p>\n<div><\/div>\n<div># vgrename \/dev\/vg_OLDname \/dev\/vg_NEWname<\/div>\n<\/div>\n<p>Now change all instances of the old volume group in the following files:<\/p>\n<p>\/etc\/grub.conf\u00a0 (which is a symbolic link to \/boot\/grub\/grub.conf)<\/p>\n<div>\/etc\/fstab<\/div>\n<p>mv \/boot\/initramfs-$(uname -r).img \/boot\/initramfs-$(uname -r).img.backup<\/p>\n<p>dracut -v \/boot\/initramfs-$(uname -r).img $(uname -r)<\/p>\n<\/div>\n<div class=\"article-content entry-content\">\u00a0dracut<\/div>\n<div class=\"article-content entry-content\"><\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4062"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4062"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4062\/revisions"}],"predecessor-version":[{"id":4065,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4062\/revisions\/4065"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4062"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4062"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4062"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}