XenServer doesn't allow us to do this kinda shrinking so we better recreate the vm copying all the files and recreating grub (boot) files.
- Create a Virtual Disk with the final desired size (eg our running vm disk has currently 100G and we want to shrinkg it to 80G so this new disk is gonna be 80G)
- Attach the new disk to the running VM. (For this we'll need to shutdown the vm for a brief moment and power up it back again)
- Under the VM terminal we format the new disk:
fdisk /dev/xvdb #(n, p, ...) DON'T FORGET TO CREATE THE SWAPP PARTITION!!!
mkfs.ext4 /dev/xvdb1
mkswap /dev/xvdb2
- Now we copy the files to the new partition
mount /dev/xvdb1 /mnt
rsync -ahPHAXx --delete --exclude={/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} / /mnt
- Edit /mnt/etc/fstab like this: [Note that now we changed the HD reference from B to A]
/dev/xvda1 / ext4 errors=remount-ro 0 1
/dev/xvda2 none swap sw 0 0
- Alternative: Theorically you could jump to Step 3 (Instal GRUB) and run those commands here, without the need of a Live CD, BUT I tried that and it didn't work. Of course you'll need to go to Step 2 after Step 3 in this case.
- Shutdown the VM to detach the disk and optionally you could power up it back again (for SLA purposes)
- Under XenCenter, create a new VM, choose any ISO and a minimum size for the Storage eg 1G. (This storage will be deleted anyways). UNMARK the "automatic power on after setup" option.
- Attach our disk
- Delete the existing disk (that of 1G)
- Click on Properties under the disk and change Device Position from 1 to 0.
- Start the VM with a live CD
- Install grub through these commands:
mount /dev/sdXY /mnt
mount --bind /dev /mnt/dev
mount --bind /dev/pts /mnt/dev/pts
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
grub-install /dev/sdX
grub-install --recheck /dev/sdX
update-grub
exit
umount /mnt/sys
umount /mnt/proc
umount /mnt/dev/pts
umount /mnt/dev
umount /mnt
- Insert the boot repair disk on the Virtual DVD Drive
- Start the VM
- Setup network (we need internet in this process)
- Proceed with automatic boor repair
- Power off, take off the DVD, power up it back again...
Thanks, this really helped me.
Some comments:
In either case, you need to mount and copy kernels from existing /boot if it was a separate partition on the existing machine.
Cheers, John