XenServer 5.6 thin provisioning with ext3
XenServer 5.6 allows admins a choice between 3 different kinds of volume management: LVM, LVHD or ext3. With the default in XenServer 5.6 of LVHD you gain quick snapshots and have thin provisioning of snapshots and suspended virtual machines, but running virtual machines have 100% of their disk allocation counted against the disk usage. In order to get thin provisioning of running VMs you need to build/rebuild your SRs as ext3 volumes. You lose rapid snapshots in the process. I also am not sure that this meets everyone’s definition of “thin provisioning” since this is just lazy allocation of blocks on ext3. If you fill up the disk on the VM and then delete a large amount of space, I don’t believe you will see the disk usage affected on your virtual machine. Still, with most server images in the Enterprise being nearly un-utilized, this should still be effective — particularly if you are good about log rotation and don’t let your partitions fill up.
In order to convert the default local storage volume on a XenServer 5.6 host you need to use the console xe utilities to destroy and recreate the SR. This is destructive to VMs on the host, so these instructions assume a newly build XenServer 5.6 — the adaption to adding a new drive to a host and creating a new SR with ext3 using ‘xe sr-create’ with these arguments is also straight forwards. If you’ve already got VMs on the SR you’ll need to migrate them off and migrate them back one way or another. Don’t try this for the first time on a VM host that you care about, particularly if you aren’t skilled with the command line.
First there’s a default template in XenServer 5.6 which needs to be removed from the storage:
# xe vbd-list
uuid ( RO) : f5c9f545-2019-7299-be87-fc7ef00be1e2
vm-uuid ( RO): e2ad0921-dea8-5a1a-77e8-d3257fdcf48d
vm-name-label ( RO): XenServer Transfer VM 5.6.0-31124p
vdi-uuid ( RO): c3a8d327-2036-4ce2-9946-f0522f7572f4
empty ( RO): false
device ( RO):
# xe template-uninstall template-uuid=e2ad0921-dea8-5a1a-77e8-d3257fdcf48d
The following items are about to be destroyed
VM : e2ad0921-dea8-5a1a-77e8-d3257fdcf48d (XenServer Transfer VM 5.6.0-31124p)
VDI: c3a8d327-2036-4ce2-9946-f0522f7572f4 (XenServer Transfer VM system disk)
Type 'yes' to continue
yes
All objects destroyed
If you really needed that template, you don’t have it anymore. You’ll have to figure out how to get it back. I’m not sure what the purpose of that is for. It is by default installed on all new XenServer 5.6 images, so you should be able to export it from a fresh install and re-import it to fix, but I’m not going to offer instructions on how to do that, and haven’t tested it.
Next, find the uuid of the Local Storage SR:
# xe sr-list name-label="Local storage"
uuid ( RO) : dacfea90-263e-0811-ab88-22f01b89b1b4
name-label ( RW): Local storage
name-description ( RW):
host ( RO): vmhost.example.com
type ( RO): lvm
content-type ( RO): user
Then find the PBD that is attached to that:
]# xe pbd-list sr-uuid=dacfea90-263e-0811-ab88-22f01b89b1b4
uuid ( RO) : daabdf71-641c-900b-3451-bd5c70675fab
host-uuid ( RO): 23d8a9a0-a317-47a5-a1e6-858ab120b57b
sr-uuid ( RO): dacfea90-263e-0811-ab88-22f01b89b1b4
device-config (MRO): device: /dev/disk/by-id/scsi-36001c230bd1017000e4f2ee6554b21c8-part3
currently-attached ( RO): true
Then unplug the PBD:
# xe pbd-unplug uuid=daabdf71-641c-900b-3451-bd5c70675fab
Now destroy the SR:
# xe sr-destroy uuid=dacfea90-263e-0811-ab88-22f01b89b1b4
Now you can create the SR. I’ve been using servers that have /dev/sda, so the storage partition is /dev/sda3. If you’re doing this on a SATA system (ick) you might have to use /dev/hda3 here, or on an HP probably /dev/cciss/c0d0p3. If you have FibreChannel or iSCSI-attached disk on a SAN you’re on your own to figure out what your block device is.
# xe sr-create content-type=user type=ext device-config:device=/dev/sda3 shared=false name-label="Local storage" 76ec3072-ae85-cd38-e363-34cf6b63d520
This command will take some time to return as it creates the SR.
You now probably want to tune the reserved space down on the ext3 partition to make more of it available. The filesystem reserves 5% of the storage to make block allocation and defragmentation more efficient, but you probably want to manage that yourself (set monitoring alarms at 95% and migrate VMs off if the storage gets above 95%).
The block device to tune is not /dev/sda3, but you can find it from df -k:
# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 4128448 3214896 703840 83% /
none 384512 0 384512 0% /dev/shm
/opt/xensource/packages/iso/XenCenter.iso
44410 44410 0 100% /var/xen/xc-install
/dev/mapper/XSLocalEXT--76ec3072--ae85--cd38--e363--34cf6b63d520-76ec3072--ae85--cd38--e363--34cf6b63d520
279556112 191652 265163836 1% /var/run/sr-mount/76ec3072-ae85-cd38-e363-34cf6b63d520
Use tune2fs against that really ugly block device name to set the reserve to 0%:
# tune2fs -m 0 /dev/mapper/XSLocalEXT--76ec3072--ae85--cd38--e363--34cf6b63d520-76ec3072--ae85--cd38--e363--34cf6b63d520 tune2fs 1.39 (29-May-2006) Setting reserved blocks percentage to 0% (0 blocks)
You should now be able to see the new “Local storage” device in XenCenter and can set it as the default storage location for new VMs. You will also see VHDs associated with your VMs showing up in the /var/run/sr-mount/[...etc...] directory.
I got this to work nicely in 5.6 on a single host via iSCSI thank you very much… But I do have a question regarding getting this same type of \Thin Provisioning\ in a pool with multiple hosts.
Is that even possible?
If so enlighten me :)
Thank you in advance
All I’ve done so far is do this against hosts with direct attached SCSI drives.
So far I don’t have any shared storage to play with. Right now I’ve only got corp IT (wikis, etc) that I’m reusing some old crappy hardware on. VM migration is somewhat painful with vm-export/vm-import to NFS for backups and when I have to move things around. So everything in my environment right now is a little bit ghetto — but this trick is helping me keep the disk space down.
I’m thinking of putting together some cheap Linux iSCSI + GNBD-replicated shared storage heads for pre-production use.
And at some point I’ll need proper shared storage for load and production.
For both of those, I’m just not there yet, though, and it’ll be a few months before I get there.