Bootstrapping an Ubuntu guest for Xen
First, some empty disk space is needed. Let's create a logical volume for our new virtual machine:
root@xenserver1:~# lvcreate -n testlv -L 10G vg0 Logical volume "testlv" created
Create a filesystem on the new logical volume:
root@xenserver1:~# mke2fs -j /dev/vg0/testlv
mke2fs 1.40-WIP (14-Nov-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1310720 inodes, 2621440 blocks
131072 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 25 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
Create a mount point:
root@xenserver1:~# mkdir /mnt/test
Mount the new filesystem
root@xenserver1:~# mount /dev/vg0/testlv /mnt/test
Bootstrap the new system. For this, we will use a utility called "debootstrap", which can bootstrap a fresh Ubuntu installation easily:
root@xenserver1:~# apt-get install debootstrap root@xenserver1:~# debootstrap feisty /mnt/test
After the system is bootstrapped, kernel modules must be copied inside the guest system for it to be able to load them during startup:modules:
root@xenserver1:~# cp -a /lib/modules/2.6.19-4-server /mnt/test/lib/modules/
Guest system's /etc/fstab must be created:
root@xenserver1:~# nano -w /mnt/test/etc/fstab
proc /proc proc defaults 0 0 /dev/sda1 / ext3 defaults,errors=remount-ro 0 1
Give the guest a hostname:
root@xenserver1:~# echo "test" > /mnt/test/etc/hostname
Umount the filesystem so that we can boot from it:
root@xenserver1:~# umount /mnt/test/
Create a Xen configuration file:
root@xenserver1:/etc/xen/auto# nano -w /etc/xen/auto/test
kernel = "/boot/vmlinuz-2.6.19-4-server" # Your kernel image ramdisk = "/boot/initrd.img-2.6.19-4-server" # The initial ramdisk memory = 128 # Number of megabytes allocated name = "test" # Virtual machine name vcpus = 4 # Number of virtual CPUs the guest sees vif = [ 'mac=aa:00:00:00:13:13, bridge=xenbr0' ] # A network interface disk = [ 'phy:mapper/vg0-testlv,sda1,w' ] # The root disk root = "/dev/sda1 ro" # Root partition the kernel mounts first
Boot the machine:
root@xenserver1:~# xm create -c /etc/xen/auto/test Log in: Ubuntu 7.04 test tty1 test login: root
The root password is initially empty, which is not very secure. Change root password:
root@test:~# passwd Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Configure network:
root@test:~# vi /etc/network/interfaces
auto lo eth0 iface lo inet loopback iface eth0 inet dhcp
root@test:~# /etc/init.d/networking restart
Install some useful packages:
root@test:~# apt-get update root@test:~# apt-get install language-pack-fi root@test:~# apt-get install nano cron bash man root@test:~# apt-get install openssh-server
That's it! You now have a working virtual machine ready for use.