Decrease VM disk size in XenServer

In XenCenter go to the VM Storage tab and ‘Add’ new disk.
Set the size smaller than your existing disk.

Ssh into the vm and partition the disk and format as ext4

fdisk /dev/xvdb
mkfs.ext4 /dev/xvdb1
mount /dev/xvdb1 /mnt

Use rsync to copy your filesystem from original disk to new disk.
I also excluded /home/files/* from rsync here but the rest in this list is nessesary to exclude.

rsync -ahPHAXx --delete --exclude={/home/files/*,/dev/*,/proc/*,/sys/*,/tmp/*,/run/*,/mnt/*,/media/*,/lost+found} / /mnt

Remove all old disk mounts(xvda, swap etc) and add the new disk to /mnt/etc/fstab (not /etc/fstab):

/dev/xvdb1 /               ext4    errors=remount-ro 0       1

Install grub into new disk bootloader:

for i in /dev /dev/pts /proc /sys /run; do sudo mount -B $i /mnt$i; done
sudo chroot /mnt
sudo grub-install --recheck /dev/xvdb
sudo update-grub
exit
for i in /mnt/dev/pts /mnt/dev /mnt/proc /mnt/sys /mnt/run; do sudo umount $i; done
umount /dev/xvdb1

Detach disk in Xencenter

Create a new VM in Xencenter, remove the original disk, attach the disk we just made.

Start the VM.

If it starts ok then shut down the old VM and delete it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You must enable javascript to see captcha here!