Disks/Images layout in VMs

This is a layout I've starting using on my VMs. I use this scheme to waste as little space on the host as possible and to allow me easy “rollback” to a clean system.

The process I follow is:

  • Create initial set of images
  • Set them up in virt-manager, if the guest supports virtio, use it as device type for max performance
  • Install OS, do first boot, shutdown VM after first boot is completed
  • Snapshot clean installation.
  • Re-create system image (this allows it to be recompressed)

Writes should be kept at a minimum before compressing so that no ghost data needs to be recompressed.
I install, exit the VM, snapshot, re-create the clean installation, compressed (compression requires re-creation/copy); create a linked image to be used instead of the clean image (this linked image will store the changes to the base image) and then start using the VM.
This allows me to use the same base image for different set-ups since changes will be written to a separate image (maybe could run even simultaneously although I'm not sure about the performance penalty).

Additionally I use a separate image for swap so that swapped data doesn't get written to the other images (hindering compression).

Finally I use a third image for /home so that I can rollback the OS without affection homes. I set it up as an LVM volume to allow future expansion with even more images :-P

Initial image creation

  • First disk image: (System, base image) os.qcow2
      $ qemu-img create -f qcow2 os.base.qcow2 10G
      $ qemu-img snapshot -c empty os.base.qcow2
      $ ln -s os.base.qcow2 os.qcow2
  • Second disk image: (Swap) swap.qcow2
      $ qemu-img create -f qcow2 swap.qcow2 2G
      $ qemu-img snapshot -c empty swap.qcow2

    Optionally move to /dev/shm for faster guest swap.

  • Third disk image: (Home) home.qcow2
      $ qemu-img create -f qcow2 home.qcow2 8G
      $ qemu-img snapshot -c empty home.qcow2

Post-installation

  • Snapshot 1)
      $ qemu-img snapshot -c clean-install swap.qcow2
      $ qemu-img snapshot -c clean-install home.qcow2
  • Layered/linked system image
      $ qemu-img convert -c -O qcow2 os.base.qcow2 os.base.compressed.qcow2
      $ mv os.base.compressed.qcow2 os.base.qcow2
      $ qemu-img snapshot -c clean-install os.base.qcow2 # Optional
      $ qemu-img create -b os.base.qcow2 -f qcow2 os.delta.qcow2
      $ rm os.qcow2
      $ ln -s os.delta.qcow2 os.qcow2
1) Note snapshotting takes a *lot* of time
virt-manager/layout.txt · Last modified: 2010/03/04 23:39 by Toni Corvera
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki