I've tried to shrink the root partition of a KVM guest. I managed to shrink it without data loss (as far as we consider only the data inside it, that is), but now the system does not boot anymore.
It's a Debian system, root partition is /dev/mapper/vg0-root
(LVM). If I boot SystemRescueCD I can mount it and I can access all the contents.
In order to shrink it, I did the following while booted in a live SystemRescueCD:
e2fsck -f /dev/mapper/vg0-root
resize2fs /dev/mapper/vg0-root 25G
lvreduce -r --size 30G /dev/mapper/vg0-root
pvresize --setphysicalvolumesize 30G /dev/vda1
gdisk /dev/vda
Please note I'm writing those steps by memory, maybe that is not the exact syntax I used, but it gives a clue of what I've done.
In gdisk
I wanted to shrink the partition, and I did so by removing the existing partition and creating a new one with same starting sector (2048), same type (8E00 Linux LVM), but smaller size (30G instead of 200G). gdisk
was suggesting as starting sector 34 instead of 2048, but I didn't want to move the partition, so I entered 2048 manually.
Then I rebooted the system, but grub hung. Back in SystemRescueCD, I mounted the LVM root partition under /mnt/custom
and tried to reinstall GRUB:
mount /dev/mapper/vg0-root /mnt/custom
cd /mnt/custom
mount -o bind /dev dev
mount -o bind /proc proc
mount -o bind /sys sys
chroot . /bin/bash
grub-install /dev/vda
Here the result is:
Installing for i386-pc platform
Warning: not using lvmetad with older version.
Warning: not using lvmetad with older version.
Warning: not using lvmetad with older version.
grub-install: warning: this GPT partition label contains no BIOS Boot Partition; embedding won't be possible.
grub-install: error: embedding is not possible, but this is required for RAID and LVM install.
Now I suspect that using gdisk
instead of fdisk
above, it implicitly converted the partition table from MBR to GPT, I'm not sure but now I see a GPT partition table even with fdisk
, so it's very likely IMHO.
Is there a way to make it MBR again? Or, is there tutorial to upgrade a Debian system from grub-pc to grub-efi manually, from a live CD system and a chroot?