Making a Virtual Machine image from a Live CD

The Live CD shipped with Fedora 18 is a perfectly serviceable virtual machine image, provided you give it some writeable disk space. It even ships with a tool to make this happen. All it needs is a block device.

First, lets give it a block device:

cd /home/ayoung/vms
qemu-img create -f raw f18root.img 8G
sudo mke2fs f18root.img
sudo losetup --find --show f18root.img

I realize vms was a very popular computer system, and the VMs would be a better name for the directory, but I eschew capitalization in directory naming. The vms directory contains my VM image files. Here is what each line above affects:

  1. qemu-create generates a new
    raw image file
    That will be the actual backing store.
  2. mke2fs initializes the ext2 (or later) file system.
  3. losetup creates a block device that maps to the raw file. the Live CD creator requires a block device. In this case, the device is /dev/loop1 but the actual value will vary per host, see the output of the losetup command to get the actual value.

Download the appropriate Live CD from: to your local filesystem. In my case, I have it in ~/Downloads/Fedora-18-Alpha-x86_64-Live-Desktop.iso.

sudo mount -o loop ~/Downloads/Fedora-18-Alpha-x86_64-Live-Desktop.iso /mnt/
sudo yum install livecd-tools
sudo /mnt/LiveOS/livecd-iso-to-disk /home/ayoung/Downloads/Fedora-18-Alpha-x86_64-Live-Desktop.iso /dev/loop1
  1. Mount the ISO to get access to the files
  2. livecd-tools has the applications required by the script
  3. Run the Live CD creator against the loopback device created above.

To deploy the VM:

sudo virt-install --vcpus=1  --name F18Alpha  --ram 1024  --import  --disk f18root.img

2 thoughts on “Making a Virtual Machine image from a Live CD

  1. Nice, thanks. Even more interesting was a blog post on how to create a cloud-deployable image out of a) a livecd iso and b) a qemu disk img – if you happen to know a nice way, that is :)

  2. Sandro: I think the missing piece would be cloud-init. Once you have the image above, you need to initialize the state of the node, and I guess you would do that via mounting the images file system and running a yum install on it. What else do you think would be required?

Leave a Reply

Your email address will not be published. Required fields are marked *