Virtual Machines with Xen/UML and MLN
These notes may be of historic interest; I moved to QEMU, the notes for which are under Virtual Machines.
CentOS
Waiting until CentOS 4.5 and 5.0 are out; CentOS 4.4 doesn't have good support for being a Xen DomU.
Debian and Ubuntu
Debian and Ubuntu minimal images are pretty trivial to create with debootstrap
- An install log with some more good tips, including using linux32 when creating i386 images on x86_64 boxes
To create debian-based virtual machines, I created a simple script source:trunk/mln/templates/debootstrap.sh based on procedures in the above sites. It should take care of getting images into a state usable by MLN/UML. You can get get the script and supporting files via anonymous svn:
svn co svn://opensysadmin.com/trunk/mln/templates
Resizing a loopback linux filesystem
This is an edited version of the The Loopback Root Filesystem HOWTO, section 5.8.
You can enlarge or reduce the size of a ext2 or ext3 loopback linux filesystem using the ext2resize command. Be sure that that image is not mounted before using any of these procedures.
If you wish to be paranoid, inject this command before and after each step:
# e2fsck -f imagename.ext3
Enlarging
First get the size of the loopback linux fileystem image, for example imagename.ext3.
# du -m imagename.ext3 300 imagename.ext3
It says the size is 300mb; I want to add 100mb to it.
# dd if=/dev/zero of=imagename.ext3 bs=1M seek=300 count=100
- seek=300 means find the point that's 300mb into the image
- count=100 means add 100mb to that point, total 400mb
Run ext2resize on the enlarged 400mb image; it will resize the ext2 filesystem on it to fill the image.
# ext2resize imagename.ext3
Reducing
Run ext2resize on the image and have it rezize the 300mb ext2 filesystem on it to 200mb.
# ext2resize imagename.ext3 200m
Run dd on the 300mb image to reduce it to 200mb.
# dd if=/dev/zero of=imagename.ext3 bs=1M seek=200 count=0
- seek=200 means find the point that's 200mb into the image
- count=0 means add nothing to that point, total 200mb
The above is a little confusing, so you may want to make a backup of your image first. If you make a mistake you'll loose whatever is on the loopback linux filesystem image.
Migrate a VMware disk image to XEN
Install qemu (on Debian apt-get install qemu). You will need the qemu-img disk image manipulation tool.
vmware-vdiskmanager -r vmware_image.vmdk -t 0 temporary_image.vmdk qemu-img convert -f vmdk temporary_image.vmdk -O raw xen_compatible.img
You can now use xen_compatible.img with xen, or dd it to a block device. Alternatively, you can put directly the output of qemu-img to a block device, without generating an intermediate image file.
Above is from the Xen Wiki. There are more details here.
Managing a network of virtual machines
I use mln (Manage Large Networks) to manage and configure the virtual machines and networks. MLN can handle the same filesystem images under both wikipedia:User-mode_Linux User Mode Linux (UML) and wikipedia:Xen Xen.
Note that MLN automatically enlarges your disk image to the size you specify in the config file.
Lines for MLN's templates.list
mln register_template -m "This filesystem is CentOS 4.4 from jailtime.org/download:centos:v4.4, modified a bit for MLN" -t gnulinux-centos-44-i386.ext3
mln register_template -m "Debootstrap with minimal changes for MLN compatability - see opensysadmin.com/trac/wiki/VirtualMachines" -t gnulinux-debian-etch-i386.ext3
mln register_template -m "Debootstrap with minimal changes for MLN compatability - see opensysadmin.com/trac/wiki/VirtualMachines" -t gnulinux-debian-sarge-i386.ext3
mln register_template -m "Debootstrap with minimal changes for MLN compatability - see opensysadmin.com/trac/wiki/VirtualMachines" -t gnulinux-debian-sid-i386.ext3
mln register_template -m "This filesystem is Gentoo 2006.1 from jailtime.org/download:gentoo:v2006.1, modified a bit for MLN" -t gnulinux-gentoo-20061-i386.ext3
mln register_template -m "Debootstrap with minimal changes for MLN compatability - see opensysadmin.com/trac/wiki/VirtualMachines" -t gnulinux-ubuntu-dapper-i386.ext3
TODO
- Reduce MLN template sizes to minimal, since MLN seems to dynamically increase their size
- Set this up for the amd64 versions of the operating systems
- There is an alternative install method that might work.
- Add Gentoo
- Add/link to instructions on how to do CentOS from scratch
External Links