2

I have Ubuntu 18.04 as a guest os and I needed to resize the partition with virt-resize:

#:/var/lib/uvtool/libvirt/images# virt-resize --shrink /dev/sda1 guest1.qcow guest1-shrunk.qcow
[   0.0] Examining guest1.qcow
**********

Summary of changes:

/dev/sda14: This partition will be left alone.

/dev/sda15: This partition will be left alone.

/dev/sda1: This partition will be resized from 17.9G to 5.5G.  The 
filesystem ext4 on /dev/sda1 will be expanded using the 'resize2fs' method.

**********
[   3.3] Setting up initial partition table on guest1.qcow
[  11.7] Copying /dev/sda14
[  11.7] Copying /dev/sda15
[  11.8] Copying /dev/sda1
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
[  29.9] Expanding /dev/sda1 (now /dev/sda3) using the 'resize2fs' method

Resize operation completed with no errors.  Before deleting the old disk, 
carefully check that the resized disk boots and works correctly.

I checked if everything was ok with:

#:/var/lib/uvtool/libvirt/images# virt-df -h guest1-shrunk.qcow 
Filesystem                                Size       Used  Available  Use%
guest1-shrunk.qcow:/dev/sda2       104M       3.6M       101M    4%
guest1-shrunk.qcow:/dev/sda3       5.3G       4.6G       612M   89%

However, when I try to start it virsh start guest1-shrunk, I cannot log into the server with ssh or even with virsh console guest1-shrunk. No errors are shown and virsh list --all shows the guest is running. However, it's not possible yo shut it down with virsh shutdown and I have to use virsh destroy. Obviously, it's not booting properly and my suspicion is this is because partitions were re-arranged. There's a similar question here: KVM .img can not boot after resized by virt-resize although in that case the person can see the error explicitly.

How do I go about fixing the partition table?

snitko
  • 193
  • 1
  • 11

1 Answers1

3

Found the answer here: https://askubuntu.com/questions/795504/grub-boot-error-on-cloned-virtual-machine

Just to clarify the steps, I had to:

  1. run virt-rescue quest1-shrinked.qcow
  2. and then run the following commands:
mkdir /mnt
mount /dev/sda3 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
grub-install /dev/sda

After that, the system boots normally.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
snitko
  • 193
  • 1
  • 11