Ask Your Question

How to create a VM with a prepopulated volume

asked 2014-03-07 09:20:06 -0600

Adrian Smith gravatar image

I want to create a VM with a pre-populated volume attached at boot time.

To achieve this I've created a snapshot of the volume I want cloned for each VM and ran,

nova boot --image myimage --flavor myflavor --block-device-mapping vdb=861fd59d-cf85-4fcf-a62b-936a7f2ce628:snap::1 myvm

where 861fd59d-cf85-4fcf-a62b-936a7f2ce628 is the id of the snapshot.

Under the covers this uses the os-volumes_boot API.

Technically this works but the problem is speed. The volume being cloned is 60Gb. I'm using LVM and the process of cloning the snapshot is taking 30 minutes. I've tested this same process with a 1GB volume and the time taken to create the volume is negligible.

Am I going about this the right way or is there a better way to achieve what I want?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2014-04-16 06:23:37 -0600


The problem here, by the looks of it, is related to the clone operation done from a volume stored on top of LVM. Cinder will defer, in time, the clone, snapshot and other operations to the backend implementations, however, right now (Icehouse) the LVM code in cinder is using dd to copy the original volume to the new one:

The LV (the entire 60GB volume, even if the filesystem is only using say 2GB) is copied to your cloned LV. This can take the amount of time you've seen.

If you have a small enough disk usage on your original LV, you could try to create a qcow2 image and upload it to glance. The problem here is that when you create a new volume the image is downloaded every time from glance. Now, if your image is small (qcow2 compressed, do not use tar.gz or zip) it should take less time.

There are discussions to add image caching to Cinder, but who knows when this will happen (example: )

Fast cloning usually happens with CoW implementations where a very small piece of data is written to disk to create a new clone and the rest is referenced. LVM does not support this unless you are using the LVM thin target and even then, the Cinder code is still using dd to clone the original volume. Furthermore the LVM this is "lightweight" in features related to CoW, unlike other volume managers (the ones offered by ZFS or NetApp).

If you plan on sticking with LVM, try to reduce the original volume size as much as you can, and use the volume resize functionality after you create the clone (together with filesystem resize offered by cloud-init or other tools). This way, dd will only have a smaller amount of data to copy to the new volume.

edit flag offensive delete link more


As an addition to this comment, Ceph can currently do COW cinder snapshots and glance images. This makes it almost instant. I am unsure if any of the other backings support a COW clone, and as you addressed LVM does not.

SamYaple gravatar imageSamYaple ( 2014-04-16 11:47:16 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2014-03-07 09:20:06 -0600

Seen: 559 times

Last updated: Apr 16 '14