Step 1 Install Xen and Image
I started with installation of “Debian-Squeeze”, but did not use the -amd64, so have to reinstall it. I use eth0, and first harddisk for the installation, machine name is rome. I installed sudo and add myself into the /etc/sudoers, so that I can use sudo later. Installation of Xen goes straight forward, no error, no problem with the following command.
vic@rome:~$ sudo apt-get install xen-hypervisor-4.0-amd64 linux-image-xen-amd64 xen-qemu-dm-4.0
This installs the Xen hypervisor (64bits), the image used to boot the dom0 (also 64bits) and the qemu utility which is needed. After the installation is done, I checked by running the following command
vic@rome:~$ uname -rv 2.6.32-5-xen-amd64 #1 SMP Wed Jan 12 05:46:49 UTC 2011
Step 2 Configure Xen
I checked the xend-config.sxp file and edited the following lines
- (logfile /var/log/xen/xend.log) #write log to the xend.log
- (network-script network-bridge) #use the original script to bridge network traffic
- (vif-script vif-bridge) #default option. The default interface will serve as the bridge.
- (dom0-min-mem 196) #min memory level of dom0
- (enable-dom0-ballooning yes) #use together with the command above, when memory low dom0 will balloon out.
- (vnc-listen '0.0.0.0') #vnc server listens to the port defined, this let VNS listens to every port, not very secure for now but easy for debugging
- (vncpasswd '***') #vnc password
- (vnc-tls 1) #enable TLS for vnc
Errors
Error 1
Xend did not start, found out that wrong image was loaded. There are five booting entries in the boot manager after the installation, the default one is the the proper Xen image for us. We have to use image-xen-4.0 instead of image-xen which by uname -rv looks the same. I changed the booting order by using the following command. It switches the grub configuration file template and re-compile it to generate the proper configuration file.
sudo mv -i /etc/grub.d/10_linux /etc/grub.d/50_linux sudo update-grub2
Error 2
Now I can see modules were loaded and Xend started properly. But I cannot “xm create” , It says hardware hvm support not enabled. I restarted through the virtual console hit F2 and enabled it in the BIOS.
Now xm started successfully, check with xm list. can create hvm now. next step to install dhcp, config it and create bridges.
vic@rome:~$ sudo xm list Name ID Mem VCPUs State Time(s) Domain-0 0 4654 8 r----- 1209.1
Error 3 How to clean apt index
cd /var/lib/apt/lists rm 192.168.2.15*
Step 3 Setup bridges
With the following commands, I first add one interface, eth2, to be used as the gateway for VMs. Then give it IP address and bring it up. In order to let the routing function work on dom0, ip_forward must be set to 1. But sudo does not work here, so have to use su then change this setting.
sudo brctl addbr eth2 sudo /sbin/ifconfig eth2 145.100.106.81 netmask 255.255.255.240 broadcast 145.100.106.95 up su echo "1" > /proc/sys/net/ipv4/ip_forward
After the configure I have the following lines in my interface list
vic@rome:~$ sudo /sbin/ifconfig eth0 Link encap:Ethernet HWaddr b8:ac:6f:8b:7c:b3 inet addr:145.100.104.58 Bcast:145.100.104.63 Mask:255.255.255.224 inet6 addr: 2001:610:158:1041:baac:6fff:fe8b:7cb3/64 Scope:Global inet6 addr: fe80::baac:6fff:fe8b:7cb3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:201425 errors:0 dropped:0 overruns:0 frame:0 TX packets:124024 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:33101441 (31.5 MiB) TX bytes:242763925 (231.5 MiB) eth2 Link encap:Ethernet HWaddr 0a:c7:71:f3:4b:36 inet addr:145.100.106.81 Bcast:145.100.106.95 Mask:255.255.255.240 inet6 addr: fe80::c46d:1ff:fe0c:ebfe/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:32914 errors:0 dropped:0 overruns:0 frame:0 TX packets:19887 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1733765 (1.6 MiB) TX bytes:24488364 (23.3 MiB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:16 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:1232 (1.2 KiB) TX bytes:1232 (1.2 KiB) peth0 Link encap:Ethernet HWaddr b8:ac:6f:8b:7c:b3 inet6 addr: fe80::baac:6fff:fe8b:7cb3/64 Scope:Link UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1 RX packets:203985 errors:0 dropped:0 overruns:0 frame:0 TX packets:276889 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:37521631 (35.7 MiB) TX bytes:252389635 (240.6 MiB) Interrupt:16 Memory:da000000-da012800
After the restart the interface eth2 is gone hence the DHCP server and the networks on VMs will not work anymore. So have to put the configuration into script and auto start.
I choose to put it in the /etc/init.d/isc-dhcp-server . The reason for this is this file is for DHCP and I am very sure my configuration will execute before the system tries to bring up the DHCP server which is vital for the service to start working properly.
Step 4 Configure DHCP
1 install DHCP server
vic@rome:~$ sudo apt-get install dhcp3-server
2 configure DHCP assigning interfaces
DHCP server has two configuration files this is the first one, it controls on which interface DHCP will serve.
sudo nano /etc/default/isc-dhcp-server INTERFACES="eth1 eth2" #eth1 is the future use physical interface and eth2 is the virtual interface which connect to eth2 of domU
3 configure DHCP assigning network scheme
In the following setting I defined one “xen” class and a subnet associated with it. Only MAC address matches the rule will be served with one address. And two hosts with dedicated address and MAC address also defined. One is for ubuntu VM and the other one for win2k3 VM.
sudo nano /etc/dhcp/dhcpd.conf # option definitions common to all supported networks... option domain-name "rome.studlab.os3.nl"; option domain-name-servers 145.100.96.11, 145.100.96.22; default-lease-time 600; max-lease-time 7200; subnet 145.100.104.00 netmask 255.255.255.224 { } class "xen" { match if ((substring(hardware, 1, 3)=00:16:3E)); } subnet 145.100.106.80 netmask 255.255.255.240 { pool { allow members of "xen"; range 145.100.106.82 145.100.106.94; option routers 145.100.106.81; } } host ubuntu { hardware ethernet 00:16:3E:00:00:01; fixed-address 145.100.106.82; option routers 145.100.106.81; } host win2k3 { hardware ethernet 00:16:3E:00:00:02; fixed-address 145.100.106.83; option routers 145.100.106.81; }
Error
DHPC did not work until I manually set the ip address of one VM and remove it. Then the DHCP server starts giving out IP addresses accordingly and correctly. It seems like either I have to “awake” the dhcp server or the slight change to the isc-dhcp-server worked (only eth2 now is giving out IP addresses).
Step 5 Create disk image
I use dd to create disk image for both VMs.
vic@rome:~$ sudo dd if=/dev/zero of=win2k3.img bs=4096 seek=15M count=1
- if: choose /dev/zero as the input instead of the standard input
- of: write to win2k3.img instead of the standard output. This is the disk image I am going to use
- bs: block size in bytes. it is now 4k
- seek: skip 15MB before write.
- count: copy one 1 block
This is the result
vic@rome:~$ ls -la ubuntu.img -rw-r--r-- 1 root root 64424513536 Feb 1 09:48 ubuntu.img ##### I created 60 GB for ubuntu ##### vic@rome:~$ du -s ubuntu.img 3503520 ubuntu.img ##### but it only using 3.5GB #####
Step 6 Create VMs (configuration files)
kernel = "hvmloader" #kernel to be used builder='hvm' #builder memory = 1024 # memory allocated, this will overwrite the default value in dom0 name = "ubuntu" #name of the VM must be unique acpi=1 # ACPI set to yes apic=1 # APIC set to yes vif = ['type=ioemu, bridge=eth2, mac=00:16:3E:00:00:01'] #vif is the virtual in$ disk = ['file:/home/vic/ubuntu.img,hda,w','file:/home/vic/ubuntu-10.04.1-deskto.iso,ioemu:hdc:cdrom,r'] device_model = '/usr/lib/xen/bin/qemu-dm' #define the device model boot="cd" # boot sequence, c = disk, d = cd vnc=1 #enable VNC vncdisplay=0 #VNC port is 5900 + vncdisplay on_poweroff = 'destroy' #on VM power off behaviour on_reboot = 'restart' #on VM reboot behaviour on_crash = 'restart' #on VM crash behaviour usbdevice='tablet'
Error
vncdisplay=0 seems not important. But The VM frequently hangs before it is in the configuration file. The VNC client needs a clearly defined port number.
Step 7 VM running and OS install
I start both of the VMs, and the OS installation goes easy and straight.
vic@rome:~$ sudo xm create ubuntu vic@rome:~$ sudo xm create win2k3
We can verify by
vic@rome:~$ sudo xm list Name ID Mem VCPUs State Time(s) Domain-0 0 4654 8 r----- 1408.9 ubuntu 13 1024 1 r----- 6.4 win2k3 2 3072 1 -b---- 1262.3
r means the VM is running. b means it is waiting. p means it is paused.
So now, the VMs run well. Go to the Answer to the questions