O'Reilly logo

Ubuntu Hacks by Bill Childers, Kyle Rankin, Jonathan Oxer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #91. Create an Ubuntu/Xen Virtual Machine

Install Ubuntu into a virtual-machine image and boot it using Xen.

The previous hack showed you how to set up a Xen server [Hack #90]. To make use of your newly Xen-enabled host, you need to create some domU virtual machines to run on it. In this hack, you'll set up a basic Dapper virtual machine (VM).

Prepare VM Filesystems

The VM needs both root and swap filesystems. In a production environment, these would most likely be stored on some form of shared-access filesystem, such as a SAN or similar, but, to keep things simple, for now you should create them as loopback disk images on the local disk. So start by making a couple of directories to store them in:

$ sudo mkdir -p /vm/vm_base
$ sudo mkdir /vm/images

Root filesystem

The root filesystem will be a 2 GB image, so first use dd to create a disk image and then use mkfs to set up a filesystem in it. 2 GB should be enough space for initial testing, but if you want to vary the size, just change the count argument, which, when multiplied by the bs (block size) argument, determines the total disk size.

While mkfs is running, it will complain that vm_base.img is not a special block device and ask if you want to proceed anyway. Say y:

$ sudo dd if=/dev/zero of=/vm/images/vm_base.img bs=1024k count=2000
$ sudo mkfs.ext3 /vm/images/vm_base.img

Swap filesystem

You can create a 200 MB swap image in a similar way:

$ sudo dd if=/dev/zero of=/vm/images/vm_base-swap.img bs=1024k count=200
$ sudo mkswap ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required