Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I shrink the virtual drive of XenServer image?.

I gave 300Gb of space for one image (domU) and that was mistake. Now I want to shrink it. How can I do that?

The system is already set up and configured, I can't just start a new server. (But if there is no other way, I will.)

share|improve this question
up vote 2 down vote accepted

Don't worry, I do this all the time! I'm always making huge VMs and then wanting to shrink them later. :)

For starters you will need to resize the partition inside of Mint. Follow this excellent guide for resizing ext3: http://www.howtoforge.com/linux_resizing_ext3_partitions

You do not need to run this command: tune2fs -O ^has_journal /dev/sda1; resize2fs now has full support for ext4 so you're good to go.

After you have resized the guest partition, shut down the VM. Attach a new disk to the VM with the smaller size you want. Boot the VM with a Linux boot CD, I'm a big fan of "Trinity Rescue Kit 3.4"

In Trinity lets assume you have the following:

/dev/hda    (good large disk)
/dev/hdb    (empty small disk)

At this point hda will have a smaller partition because you followed the guide above

Run fdisk -l to list all known partitions. Then run fdisk /dev/hdb and create a partition table identical to /dev/hda. Run dd if=/dev/hda1 of=/dev/hdb1 for every partition that you have.

Now the final stage is to install the boot loader. Follow the guide here: http://tipstricks.itmatrix.eu/?p=291

After you are done, shut down the VM. Eject the live CD ISO. Detach but don't delete the large disk. Click properties for the smaller disk, and choose the bottom menu item on the left. For device position, change it from 1 to 0. Boot the VM and make sure that all your data is there. For a final check you can run sudo touch /forcefsck; sudo shutdown -r now which will reboot the VM with a forced disk check at startup. If everything is ok, delete your large disk image.

If you have any problems with these steps, let me know. After you are done you should feel like a boss (cuz you are!).

share|improve this answer
Super! Will perform this operation on this weekend. – bakytn Aug 17 '11 at 16:41
This goes without saying, but you should snapshot your disk before you start this! Always have a separate copy of your data when doing stuff like this! Good luck! Let me know if you have issues! – portforwardpodcast Aug 17 '11 at 21:25

NOTE: do a backup first.

It depends on a number of things:

1. Is it an LVM ? (lots of if's)

1.1 If it is a logical volume, and DOES NOT contain partitions (just a filesystem), and that FS is an ext[2-4] family, do an e2fsck -f <device> (without mounting it) to ensure filesystem consistency.

1.2 run resize2fs <device> <new size>

1.3 run lvreduce or lvresize on the logical volume to shrink it.

If the logical volume has partitions, then you'll have to play with fdisk/parted etc. AFTER you resized the FS with resize2fs and BEFORE lvresize or lvreduce. For a phisical disk, it is the same story, without the LVM commands. If you have another filesystem, look for the tools in your distro to resize it.

share|improve this answer
It is not LVM (I think, btw, how can I check?) just a standard Linux Mint 11 64 Bit (Debian based). It is ext4. – bakytn Aug 16 '11 at 7:39
When you say "Drive of xenServer image", you mean the hipervisor (dom0) or a guest (vm) ? what is the device called ? – Torian Aug 16 '11 at 11:56
Sorry, I meant the guest image (domU) – bakytn Aug 16 '11 at 11:59
@bakytn no problem :). What is the device name ? (asigned into the disk parameter on /etc/xen/<domu cfg file>) ? That will give you an idea, or post it in here. – Torian Aug 16 '11 at 12:29
that's interesting..because there is no /etc/xen folder neither in XenServer itself nor in domU – bakytn Aug 16 '11 at 12:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.