Restore a partimage backup to loopback

  1. You need a file to mount as a HDD device - using DD, the following will instantly create a file of SIZE Gigabytes:
    • dd if=/dev/zero of=myharddisk.img bs=1000 count=0 seek=$[1000*1000*SIZE]
  2.  You need to make this file look like a block device (Choose a free /dev/loop device):
    • losetup /dev/loop0 myharddisk.img
  3. Start partimage manually from the command line, pointing to your loop device
    • partimage /dev/loop0 backupfile.000
  4. Remove the file from the loop device
    • losetup -d /dev/loop0
  5. Mount the new file on a directory
    • mount myharddisk.img /path/to/dir -o loop
  6. Enjoy the backup's files

Xen and the Art of QCows

I've been working on a special project.. one that requires the building of multiple virtual machines on the fly. My VM of choice (as seen in previous entries) is Xen.

Part of my requirements is the ability to have a base image of a root drive, then have each of the dynamic VMs have their own dynamic image based on the original. One, if they wanted to, and had the space - could just copy the drive image multiple times. And this would work.

Fortunately, there is a better way. Copy-on-write disks are disks that write changes from a base image to a separate file. Thus, reducing the overall usage. This is what I want.

Xen wiki has multiple solutions to doing this, however, I wanted something simple, and supported at the xen level. This left me with qcow files.

In order to save some people some time. I wanted to describe how I went about getting the images to work -- pain for me, means less pain for you in the long run.

To make a long story short:

  1. Created a image with dd (see previous posts)
  2. Made my changes to the image
  3. used "qemu-img convert -O qcow2 (base-img) (qcow-img)" to convert the image to a base qcow format
  4. built the actual qcow files with "create-qcow (image-size) (container-qcow) (qcow-img)"
Some notes:

  • When building your base image with dd - it CAN NOT be a spare file (meaning using the seek) it must be a full img
  • img2qcow does not work! (or at least it didn't for me)
Some errors you might see
  • Failed to write new L1 table  (Usually after: Converting image to big endian L1 table)
    • Your using qcow files, not qcow2 - probably because you used img2qcow or -O qcow with qemu-img
  • QCOW Open failed
    • You may have used qcow-create, but referenced a raw image - not a qcow image.
  • XENBUS: Waiting for devices to initialise
    • One of your devices didn't init in dom0 - look at /var/log/syslog to find the error in your ways

Tags

This will be shown to users with no Flash or Javascript.