3

I'm struggling to update grub2 after using 'vgrename' on my root VG in Centos 7. I ran 'vgrename' successfully, then edited /etc/fstab with the VG name, then edited 'GRUB_CMDLINE_LINUX=' in /etc/default/grub with the new VG name, then attempted to run grub2-mkconfig. It's at this point I get the error:

# grub2-mkconfig
/usr/sbin/grub2-probe: error: failed to get canonical path of ‘/dev/mapper/centos_prod--stor01-root’.

This canonical path it's pointing to is the old VG name. I don't understand this as I assumed that updating the VG name in /etc/default/grub would have resolved that? Any help appreciated :)

Herman van Rink
  • 312
  • 2
  • 9
machinist
  • 171
  • 1
  • 4
  • 12

3 Answers3

3

I'm not sure if all the steps are necessary for centos, or if more are required, but I hope the following helps.

For SLES 12 SP1, I had to modify the following files after doing vgrename or lvrename:

  • /etc/default/grub
  • /etc/sysconfig/bootloader
  • /etc/fstab

In /etc/default/grub, I also added the following lines:

  • GRUB_DEVICE=/dev/VGname/LVname
  • GRUB_DEVICE_UUID=e35b6f76-15b7-44ef-8bea-cd2c1ef8a547

After that, you must remake the grub config using grub2-mkconfig; however, there seems to be an issue with this script if you are modifying the device path. I had to modify a line (159 for me, should be close) in it to say:

  • GRUB_DEVICE="`${grub_probe} --target=device /`" || true

The key difference is the true part. Otherwise, grub2-probe will throw an error, propagating up to grub2-mkconfig, because it finds the current device instead of where the new device will be.

Instead of just running grub2-mkconfig, I ran mkinitrd, which runs through that and dracut, which allows the kernel to load the proper filesystems to boot up.

Stephen
  • 51
  • 3
  • Thanks, in Debian stretch the same line is in /usr/sbin/grub-mkconfig and there was a second very similar line for /boot that needed the same change. I opted to replace it with `GRUB_DEVICE=/dev/VGname/LVname` there instead of adding the `|| true` – Herman van Rink Jun 07 '19 at 08:17
3

This annoyance is due to a bad assumption by grub.

If I ran vgrename centos7 vg_centos7 to change the name of the volume group, then:

# df -h /
Filesystem                Size  Used Avail Use% Mounted on
/dev/mapper/centos7-root  6.5G  1.3G  5.3G  20% /

# ls /dev/mapper
control  vg_centos7-root  vg_centos7-swap

The name of the mounted volume and the /dev/mapper symlink no longer match. In this scenario, grub2 uses the name of the currently mounted volume (centos7-root) and fails when it can't find it in /dev/mapper/ (as it was just renamed to vg_centos-root).

You can remount and chroot to work around this, as follows:

mount /dev/mapper/vg_centos-root /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys/ /mnt/sys
mount --bind /run/ /mnt/run
mount --bind /boot/ /mnt/boot

cat << EOF | chroot /mnt
grub-mkconfig --output=/boot/grub/grub.cfg
exit
EOF

umount /mnt/boot
umount /mnt/run
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev
umount /mnt
billyw
  • 388
  • 1
  • 5
  • 15
  • 1
    I still get error `cryptsetup: ERROR: Couldn't resolve device /dev/mapper/centos7-root` on `sudo update-initramfs -c -k all`. Any idea why ? – expert Jan 24 '23 at 19:02
-1

My way works well in CentOS 7 and 8.

Current vg and lvs

# vgs
  VG #PV #LV #SN Attr   VSize    VFree
  cl   1   4   0 wz--n- <325.97g 4.00m
# lvs
  LV      VG Attr       LSize    Pool
  root    cl -wi-ao----  <46.57g

Plan to change vg name from cl to vg_sys and change lv name form root to lv_root

rename vg and lv name

vgrename -v cl vg_sys
lvrename /dev/cl/root /dev/vg_sys/lv_root

Then modify /etc/fstab, /boot/grub2/grub.cfg, /etc/default/grub, /boot/grub2/grubenv

sed -i 's/cl-root/vg_sys-lv_root/g' /etc/fstab
sed -i 's/cl-root/vg_sys-lv_root/g' /boot/grub2/grub.cfg
sed -i 's/cl\/root/vg_sys\/lv_root/g' /boot/grub2/grub.cfg
sed -i 's/cl-root/vg_sys-lv_root/g' /etc/default/grub
sed -i 's/cl\/root/vg_sys\/lv_root/g' /etc/default/grub
sed -i 's/cl-root/vg_sys-lv_root/g' /boot/grub2/grubenv
sed -i 's/cl\/root/vg_sys\/lv_root/g' /boot/grub2/grubenv

Make sure all four files are modified correctly. After OS rebooted, it works as well as what you planed.

xmlredice
  • 49
  • 2