HowTo Change The LVM Volume Group Name That Includes The Root Partition

From NST Wiki
Jump to: navigation, search

Overview

This page describes the steps needed to change an LVM (Logical Volume Manager) Volume Group name which includes the the Root partition ("/"). The problem is that the Root partition LVM Device Mapper is referenced in different configuration files and embedded in the Kernel initramfs.

We will demonstrate the LVM Volume Group name change from "nst_localhost" to "nst20".

State Before The LVM Volume Group Name Change

The Fedora System Storage Manager utility: ssm is used to display the current storage layout on the example system.

[root@localhost ~]# ssm list
-------------------------------------------------------------------
Device        Free      Used      Total  Pool           Mount point  
-------------------------------------------------------------------
/dev/sda                       30.00 GB                 PARTITIONED  
/dev/sda1                     500.00 MB                 /boot        
/dev/sda2  0.00 KB  29.51 GB   29.51 GB  nst_localhost               
-------------------------------------------------------------------
---------------------------------------------------------
Pool           Type  Devices     Free      Used     Total  
---------------------------------------------------------
nst_localhost  lvm   1        0.00 KB  29.51 GB  29.51 GB  
---------------------------------------------------------
----------------------------------------------------------------------------------------------------
Volume                   Pool           Volume size  FS      FS size       Free  Type    Mount point  
----------------------------------------------------------------------------------------------------
/dev/nst_localhost/root  nst_localhost     27.48 GB  ext4   27.48 GB   19.18 GB  linear  /            
/dev/nst_localhost/swap  nst_localhost      2.03 GB                              linear               
/dev/sda1                                 500.00 MB  ext4  500.00 MB  364.40 MB  part    /boot        
----------------------------------------------------------------------------------------------------

Steps To Change The LVM Volume Group Name

Step 1: Change Volume Group Name

The vgrename utility will be used to change LVM Volume Name from "nst_localhost" to "nst20":

[root@localhost ~]# vgrename -v nst_localhost nst20
    Checking for existing volume group "nst_localhost"
    Checking for new volume group "nst20"
    Archiving volume group "nst_localhost" metadata (seqno 5).
    Writing out updated volume group
    Renaming "/dev/nst_localhost" to "/dev/nst20"
    Loading nst_localhost-root table (253:0)
    Suppressed nst_localhost-root (253:0) identical table reload.
    Suspending nst_localhost-root (253:0) with device flush
    Loading nst_localhost-root table (253:0)
    Suppressed nst_localhost-root (253:0) identical table reload.
    Renaming nst_localhost-root (253:0) to nst20-root
    Resuming nst20-root (253:0)
    Loading nst_localhost-swap table (253:1)
    Suppressed nst_localhost-swap (253:1) identical table reload.
    Suspending nst_localhost-swap (253:1) with device flush
    Loading nst_localhost-swap table (253:1)
    Suppressed nst_localhost-swap (253:1) identical table reload.
    Renaming nst_localhost-swap (253:1) to nst20-swap
    Resuming nst20-swap (253:1)
    Creating volume group backup "/etc/lvm/backup/nst20" (seqno 6).
  Volume group "nst_localhost" successfully renamed to "nst20"
    Wiping cache of LVM-capable devices
    Wiping internal VG cache

Step 2: Update The File System Configuration File: "/etc/fstab"

Use an editor (e.g., vi) to change the LVM Volume Group Device Mapper name in the file system configuration file: "/etc/fstab" to the new "nst20" name for the "root" and "swap" Logical Volumes.

Before:

[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Dec 30 05:16:54 2013
#
# 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/nst_localhost-root /                       ext4    defaults        1 1
UUID=8c72887d-d7db-4a3d-9b09-0d619fc11d9c /boot                   ext4    defaults        1 2
/dev/mapper/nst_localhost-swap swap                    swap    defaults        0 0

After:

[root@localhost ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Mon Dec 30 05:16:54 2013
#
# 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/nst20-root /                       ext4    defaults        1 1
UUID=8c72887d-d7db-4a3d-9b09-0d619fc11d9c /boot                   ext4    defaults        1 2
/dev/mapper/nst20-swap swap                    swap    defaults        0 0

Step 3: Update The Grub2 Configuration File: "/boot/grub2/grub.cfg"

Use an editor (e.g., vi) to change the LVM Volume Group Device Mapper name in the file system configuration file: "/boot/grub2/grub.cfg" to the new "nst20" name for the "root" and "swap" Logical Volumes for all relevant entries.

Before (Note: Only one Grub2 menu entry is shown for example purposes. All relevant entries need to be changed.):

.
.
.
menuentry " ---------------------NST 20 (64 Bit) Boot Choices---------------------" {
  true
}

menuentry 'Console, Kernel: 3.12.5-302.fc20.x86_64' --class nst --class gnu-linux --class gnu --class os {
        savedefault
    load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  8c72887d-d7db-4a3d-9b09-0d619fc11d9c
        else
          search --no-floppy --fs-uuid --set=root 8c72887d-d7db-4a3d-9b09-0d619fc11d9c
        fi
        echo    'Loading Linux 3.12.5-302.fc20.x86_64 ...'
        linux   /vmlinuz-3.12.5-302.fc20.x86_64 root=/dev/mapper/nst_localhost-root ro rd.lvm.lv=nst_localhost/swap rd.lvm.lv=nst_localhost/root vconsole.font=latarcyrheb-sun16 crashkernel=auto systemd.unit=multi-user.target
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-3.12.5-302.fc20.x86_64.img
}
.
.
.

After:

.
.
.
menuentry " ---------------------NST 20 (64 Bit) Boot Choices---------------------" {
  true
}

menuentry 'Console, Kernel: 3.12.5-302.fc20.x86_64' --class nst --class gnu-linux --class gnu --class os {
        savedefault
    load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 --hint='hd0,msdos1'  8c72887d-d7db-4a3d-9b09-0d619fc11d9c
        else
          search --no-floppy --fs-uuid --set=root 8c72887d-d7db-4a3d-9b09-0d619fc11d9c
        fi
        echo    'Loading Linux 3.12.5-302.fc20.x86_64 ...'
        linux   /vmlinuz-3.12.5-302.fc20.x86_64 root=/dev/mapper/nst20-root ro rd.lvm.lv=nst20/swap rd.lvm.lv=nst20/root vconsole.font=latarcyrheb-sun16 crashkernel=auto systemd.unit=multi-user.target
        echo    'Loading initial ramdisk ...'
        initrd  /initramfs-3.12.5-302.fc20.x86_64.img
}
.
.
.

Step 4: Rebuild The Kernel initramfs File

The Kernel initramfs image needs to be rebuild to reflect the LVM Volume Group name change. The mkinitrd will be used to accomplish this task which uses the "dracut" tool.

Example for Kernel: 3.12.5-302.fc20.x86_64

[root@localhost ~]# ls -al /boot/initramfs-3.12.5-302.fc20.x86_64.img
-rw------- 1 root root 11435288 Jan  1 11:07 /boot/initramfs-3.12.5-302.fc20.x86_64.img
[root@localhost ~]# uname -r
3.12.5-302.fc20.x86_64 
[root@localhost ~]# mkinitrd -f -v /boot/initramfs-$(uname -r).img $(uname -r)
Creating: target|kernel|dracut args|basicmodules 
Executing: /usr/sbin/dracut -v -f /boot/initramfs-3.12.5-302.fc20.x86_64.img 3.12.5-302.fc20.x86_64
*** Including module: bash ***
*** Including module: i18n ***
*** Including module: ifcfg ***
*** Including module: drm ***
*** Including module: plymouth ***
*** Including module: dm ***
Skipping udev rule: 64-device-mapper.rules
Skipping udev rule: 60-persistent-storage-dm.rules
Skipping udev rule: 55-dm.rules
*** Including module: kernel-modules ***
*** Including module: lvm ***
Skipping udev rule: 64-device-mapper.rules
Skipping udev rule: 56-lvm.rules
Skipping udev rule: 60-persistent-storage-lvm.rules
*** Including module: resume ***
*** Including module: rootfs-block ***
*** Including module: terminfo ***
*** Including module: udev-rules ***
Skipping udev rule: 91-permissions.rules
*** Including module: biosdevname ***
*** Including module: systemd ***
*** Including module: usrmount ***
*** Including module: base ***
*** Including module: fs-lib ***
*** Including module: shutdown ***
*** Including modules done ***
*** Installing kernel module dependencies and firmware ***
*** Installing kernel module dependencies and firmware done ***
*** Resolving executable dependencies ***
*** Resolving executable dependencies done***
*** Pre-linking files ***
*** Pre-linking files done ***
*** Hardlinking files ***
*** Hardlinking files done ***
*** Stripping files ***
*** Stripping files done ***
*** Creating image file ***
*** Creating image file done ***
[root@localhost ~]# ls -al /boot/initramfs-3.12.5-302.fc20.x86_64.img
-rw------- 1 root root 11435512 Jan  1 14:20 /boot/initramfs-3.12.5-302.fc20.x86_64.img

Step 5: Reboot The System

After all the above changes have been made, use the systemctl utility to reboot your system:

[root@localhost ~]# systemctl reboot

State After The LVM Volume Group Name Change

The Fedora System Storage Manager utility: ssm is used to display the storage layout on the example system after changing the LVM Volume Group Name and a system reboot has occurred.

[root@localhost ~]# ssm list
-----------------------------------------------------------
Device        Free      Used      Total  Pool   Mount point  
-----------------------------------------------------------
/dev/sda                       30.00 GB         PARTITIONED  
/dev/sda1                     500.00 MB         /boot        
/dev/sda2  0.00 KB  29.51 GB   29.51 GB  nst20               
-----------------------------------------------------------
-------------------------------------------------
Pool   Type  Devices     Free      Used     Total  
-------------------------------------------------
nst20  lvm   1        0.00 KB  29.51 GB  29.51 GB  
-------------------------------------------------
------------------------------------------------------------------------------------
Volume           Pool   Volume size  FS      FS size       Free  Type    Mount point  
------------------------------------------------------------------------------------
/dev/nst20/root  nst20     27.48 GB  ext4   27.48 GB   19.18 GB  linear  /            
/dev/nst20/swap  nst20      2.03 GB                              linear               
/dev/sda1                 500.00 MB  ext4  500.00 MB  364.40 MB  part    /boot        
------------------------------------------------------------------------------------