TvE 2100

At 2100 feet above Santa Barbara

Creating a Debian Xen Virtual Machine

This is brief note on how to create a Debian Sarge Xen VM on a Gentoo box. I’m using file-based disk images because it’s so flexible. I don’t believe the partition based ones are actually significantly faster. Inspiration for some of this came from this wiki page.

First I created a 30G LVM volume to hold disk images, created an XFS file system, and mounted it. Then I created a 4GB root image for Debian using XFS as well. I like XFS because it allows me to shrink and expand the filesystem and it also allows me to take snapshots.

hydra xen # lvcreate -L 30G vg1 -n images
 Logical volume "images" created
hydra xen # mkdir /etc/xen/images
hydra xen # cat >>/dev/fstab
/dev/vg1/images  /etc/xen/images xfs  noauto,noatime  0 2

hydra xen # mkfs.xfs /dev/vg1/images 
meta-data=/dev/vg1/images        isize=256    agcount=16, agsize=491520 blks
         =                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=7864320, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096  
log      =internal log           bsize=4096   blocks=3840, version=1
         =                       sectsz=512   sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
hydra xen # mount /dev/vg1/images
hydra xen # df -h /dev/vg1/images
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg1-images
                       30G   13G   18G  41% /etc/xen/images
hydra ~ # dd if=/dev/zero of=/etc/xen/images/debian.root bs=1024k count=4096
4096+0 records in
4096+0 records out
4294967296 bytes (4.3 GB) copied, 129.508 seconds, 33.2 MB/s
hydra xen # mkdir /mnt/xen/debian.root
hydra xen # mkfs.xfs /xen/xen/images/debian.root 
meta-data=/big/xen/debian.root   isize=256    agcount=8, agsize=131072 blks
         =                       sectsz=512   attr=0
data     =                       bsize=4096   blocks=1048576, imaxpct=25
         =                       sunit=0      swidth=0 blks, unwritten=1
naming   =version 2              bsize=4096  
log      =internal log           bsize=4096   blocks=2560, version=1
         =                       sectsz=512   sunit=0 blks
realtime =none                   extsz=65536  blocks=0, rtextents=0
hydra xen # mount -o loop /etc/xen/images/debian.root /mnt/xen/debian.root
hydra xen #

Now we’re ready to install Debian Sarge:

hydra xen # emerge debootstrap
Calculating dependencies ...done!
>>> emerge (1 of 2) app-arch/dpkg-1.10.28 to /
...
>>> emerge (2 of 2) dev-util/debootstrap-0.2.45-r1 to /
...
hydra xen # debootstrap --arch i386 sarge /mnt/xen/debian.root http://ftp.us.debian.org/debian
I: Retrieving debootstrap.invalid_dists_sarge_Release
I: Validating debootstrap.invalid_dists_sarge_Release
I: Retrieving debootstrap.invalid_dists_sarge_main_binary-i386_Packages
I: Validating debootstrap.invalid_dists_sarge_main_binary-i386_Packages
I: Checking adduser...
...
I: Base system installed successfully.
umount: /mnt/xen/debian.root/dev/pts: not mounted
umount: /mnt/xen/debian.root/dev/shm: not mounted
umount: /mnt/xen/debian.root/proc/bus/usb: not mounted
hydra xen # 

Now we configure the new system:

hydra xen # chroot /mnt/xen/debian.root/
hydra:/# cd /etc
hydra:/etc# cat >fstab
/dev/sda1     /     ext3     defaults     0     1
/dev/sda2     none  swap     sw                    0     0
proc          /proc proc     defaults              0     0
hydra:/etc# mv /lib/tls /lib/tls.disabled
hydra:/etc# exit

Here’s my Xen config file, note that I have a DHCP server with static leases based on the mac address, that’s why I specify it carefully.:

hydra xen # cat debian 
kernel = "/boot/vmlinuz-2.6.16-r1-xenU"
memory = 128
name = "debian"
vif = [ 'mac=00:16:3E:00:00:24' ]
disk = ['file:/etc/xen/images/debian.root,sda1,w', 'file:/etc/xen/images/debian.swap,sda2,w']
root = "/dev/sda1 ro"
hydra xen # 

Let’s start the virtual machine!

hydra xen # umount /mnt/xen/debian.root/