1

I would like to migrate standard root partitions (Centos 7 with xfs filesystem) to the LVM partition, unfortunately every attempt fails and after reboot the system won't start (I suspect problem with grub2). Below is a list of steps and commands that have been executed.

  1. Attach new disk and create new LVM partition with the same filesystem and equal size like as orginal root partition.

  2. Mount in new directory

    mount /dev/mapper/vg-root /mnt/nroot

  3. Dumping partition using xfsdump

    xfsdump -0uf /mnt/nroot.dump /dev/vda1

  4. Restoring partition to the temp directory

    xfsrestore -f /mnt/nroot.dump /mnt/nroot

  5. Remount root partition

    umount /mnt/nroot

    mount /dev/mapper/vg-root /

    mount -o rw,remount /

  6. Edit fstab /etc/fstab and changing old UUID to new root UUID

  7. Rebuild grub.cfg file

    grub2-mkconfig -o /boot/grub2/grub.cfg (UUID and moount point is changing)

  8. Reboot

After that root partition is mounted from old disk or OS won't start with the grub error.

I would ask for help and possibly errors.

kudlaty
  • 41
  • be careful with lvm it is still recommanded to keep separated little /boot partition and a swap partition out of the lvm mount points /dev/mapper/VGSYS-root 999320 55704 874804 6% / /dev/mapper/VGSYS-usr 13352008 8229988 4518448 65% /usr /dev/sda1 253871 188634 52130 79% /boot for example – francois P Jan 25 '18 at 19:13
  • From one of the attempts, i migrate boot partition to a new separate partition, but the problem still exists. My goal is migrating all data from one standard root partition to separate partitions (/root, /boot, /var, /usr, /home etc.) in according with best practices. – kudlaty Jan 26 '18 at 12:48
  • Do you have GRUB2 setup to use LVM? See https://unix.stackexchange.com/questions/136614/how-does-grub2-load-the-kernel-from-an-lvm-volume#136617 – Emmanuel Rosa Jan 27 '18 at 02:45
  • It is important to append rd.lvm.lv=vg00/root to GRUB_CMDLINE_LINUX variable in /etc/default/grub, and then regenerate grub.cfg. – Martian Jan 30 '18 at 08:24
  • Thanks for response, I made all changes and rebuild grub file but unfortunately Centos still starts with mounted old partition (RO state). At the moment file grub.cfg include line which looks: "linux16 /boot/vmlinuz-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca root=/dev/mapper/vg00-root ro rd.lvm.lv=vg00/root console=tty0 crashkernel=auto console=ttyS0,115200 " – kudlaty Jan 30 '18 at 11:16

1 Answers1

1
  1. Maybe I will start at the beginning, so I've OS Centos 7.3 with below state

Result of executing df -Th command

Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      xfs        30G  942M   30G   4% /
devtmpfs       devtmpfs  901M     0  901M   0% /dev
tmpfs          tmpfs     920M     0  920M   0% /dev/shm
tmpfs          tmpfs     920M   17M  904M   2% /run
tmpfs          tmpfs     920M     0  920M   0% /sys/fs/cgroup
tmpfs          tmpfs     184M     0  184M   0% /run/user/1000

and the file grub.cnf

[...]
menuentry 'CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.16.1.el7.x86_64-advanced-29342a0b-e20f-4676-9ecf-dfdf02ef6683' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  29342a0b-e20f-4676-9ecf-dfdf02ef6683
        else
          search --no-floppy --fs-uuid --set=root 29342a0b-e20f-4676-9ecf-dfdf02ef6683
        fi
        linux16 /boot/vmlinuz-3.10.0-514.16.1.el7.x86_64 root=UUID=29342a0b-e20f-4676-9ecf-dfdf02ef6683 ro console=tty0 console=ttyS0,115200n8 crashkernel=auto console=ttyS0,115200 LANG=en_US.UTF-8
        initrd16 /boot/initramfs-3.10.0-514.16.1.el7.x86_64.img
}
menuentry 'CentOS Linux (0-rescue-8bd05758fdfc1903174c9fcaf82b71ca) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca-advanced-29342a0b-e20f-4676-9ecf-dfdf02ef6683' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        set root='hd0,msdos1'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='hd0,msdos1'  29342a0b-e20f-4676-9ecf-dfdf02ef6683
        else
          search --no-floppy --fs-uuid --set=root 29342a0b-e20f-4676-9ecf-dfdf02ef6683
        fi
        linux16 /boot/vmlinuz-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca root=UUID=29342a0b-e20f-4676-9ecf-dfdf02ef6683 ro console=tty0 console=ttyS0,115200n8 crashkernel=auto console=ttyS0,115200
        initrd16 /boot/initramfs-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca.img
}

[...]
  1. In the next step I migrate /boot partition from /dev/vda1 to separate partition (acoording to https://docs.hytrust.com/DataControl/Admin_Guide-4.0/Content/Books/Admin-Guide/Linux-Root-Swap-Drive-Encryption/Creating-Boot-Partition-RHEL-CentOS-7.htm)
Filesystem     Type      Size  Used Avail Use% Mounted on
/dev/vda1      xfs        30G  1.1G   29G   4% /
devtmpfs       devtmpfs  901M     0  901M   0% /dev
tmpfs          tmpfs     920M     0  920M   0% /dev/shm
tmpfs          tmpfs     920M   17M  904M   2% /run
tmpfs          tmpfs     920M     0  920M   0% /sys/fs/cgroup
/dev/vdc1      xfs      1020M  144M  877M  15% /boot
tmpfs          tmpfs     184M     0  184M   0% /run/user/1000

It's working properly and grub.cnf from /boot/grub2 looks like:

[...]
menuentry 'CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.16.1.el7.x86_64-advanced-29342a0b-e20f-4676-9ecf-dfdf02ef6683' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod xfs
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  b526cf02-6566-4a91-8027-13b3800d177f
        else
          search --no-floppy --fs-uuid --set=root b526cf02-6566-4a91-8027-13b3800d177f
        fi
        linux16 /vmlinuz-3.10.0-514.16.1.el7.x86_64 root=UUID=29342a0b-e20f-4676-9ecf-dfdf02ef6683 ro console=tty0 crashkernel=auto console=ttyS0,115200 
        initrd16 /initramfs-3.10.0-514.16.1.el7.x86_64.img
}
menuentry 'CentOS Linux (0-rescue-8bd05758fdfc1903174c9fcaf82b71ca) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca-advanced-29342a0b-e20f-4676-9ecf-dfdf02ef6683' {
        load_video
        insmod gzio
        insmod part_msdos
        insmod xfs
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root  b526cf02-6566-4a91-8027-13b3800d177f
        else
          search --no-floppy --fs-uuid --set=root b526cf02-6566-4a91-8027-13b3800d177f
        fi
        linux16 /vmlinuz-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca root=UUID=29342a0b-e20f-4676-9ecf-dfdf02ef6683 ro console=tty0 crashkernel=auto console=ttyS0,115200 
        initrd16 /initramfs-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca.img
}
if [ "x$default" = 'CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)' ]; then default='Advanced options for CentOS Linux>CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)'; fi;
[...]
  1. Finnaly I create and migrate to LVM root, all used commands I pasted earlier.

Extra commands

$ mount /dev/mapper/vg00-root /
$ mount -o rw,remount /
$ cp /boot/initramfs-$(uname -r).img /boot/initramfs-$(uname -r).img.$(date +%m-%d-%H%M%S).bak
$ dracut -f -v
$ grub2-mkconfig -o /boot/grub2/grub.cfg

So df -hT command displays:

Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/vg00-root xfs        30G  2.1G   28G   7% /
devtmpfs              devtmpfs  901M     0  901M   0% /dev
tmpfs                 tmpfs     920M     0  920M   0% /dev/shm
tmpfs                 tmpfs     920M   17M  904M   2% /run
tmpfs                 tmpfs     920M     0  920M   0% /sys/fs/cgroup
/dev/vdc1             xfs      1020M  179M  842M  18% /boot
tmpfs                 tmpfs     184M     0  184M   0% /run/user/1000

and in file grub.cnf directives changes to:

menuentry 'CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-514.16.1.el7.x86_64-advanced-c81176da-6e61-44f0-afbc-93df72820140' {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod lvm
        insmod xfs
        set root='lvmid/T33gzF-WKVs-rUjx-Pieh-rZIU-pna5-JXF6bF/f0wezp-3C1o-03mr-CfaC-ZlAY-LyKH-Zcx8fg'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='lvmid/T33gzF-WKVs-rUjx-Pieh-rZIU-pna5-JXF6bF/f0wezp-3C1o-03mr-CfaC-ZlAY-LyKH-Zcx8fg'  c81176da-6e61-44f0-afbc-93df72820140
        else
          search --no-floppy --fs-uuid --set=root c81176da-6e61-44f0-afbc-93df72820140
        fi
        linux16 /boot/vmlinuz-3.10.0-514.16.1.el7.x86_64 root=/dev/mapper/vg00-root ro console=tty0 crashkernel=auto console=ttyS0,115200 
        initrd16 /boot/initramfs-3.10.0-514.16.1.el7.x86_64.img
}
menuentry 'CentOS Linux (0-rescue-8bd05758fdfc1903174c9fcaf82b71ca) 7 (Core)' --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca-advanced-c81176da-6e61-44f0-afbc-93df72820140' {
        load_video
        insmod gzio
        insmod lvm
        insmod xfs
        set root='lvmid/T33gzF-WKVs-rUjx-Pieh-rZIU-pna5-JXF6bF/f0wezp-3C1o-03mr-CfaC-ZlAY-LyKH-Zcx8fg'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint='lvmid/T33gzF-WKVs-rUjx-Pieh-rZIU-pna5-JXF6bF/f0wezp-3C1o-03mr-CfaC-ZlAY-LyKH-Zcx8fg'  c81176da-6e61-44f0-afbc-93df72820140
        else
          search --no-floppy --fs-uuid --set=root c81176da-6e61-44f0-afbc-93df72820140
        fi
        linux16 /boot/vmlinuz-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca root=/dev/mapper/vg00-root ro console=tty0 crashkernel=auto console=ttyS0,115200 
        initrd16 /boot/initramfs-0-rescue-8bd05758fdfc1903174c9fcaf82b71ca.img
}
if [ "x$default" = 'CentOS Linux (3.10.0-514.16.1.el7.x86_64) 7 (Core)' ]

but now when i restart server system starts with old /root partition and it's in RO state. Any ideas?

kudlaty
  • 41
  • It seems you've made some progress; I would recommend editing this Answer into your Question, as you still have an unresolved issue. (If others had answered your existing question, I would have said to open a new question.) – Jeff Schaller Feb 04 '18 at 16:37