Xen tips
- Details
- Category: Virtualization
- Written by Mahdi Bahmani Ciahmard
- Hits: 54
xen client config sample:
[root@vmemail ~]# cat /etc/xen/vmlist/win1
# Automtically generated by ConVirt
builder='hvm'</p> <p style="text-align: left;">maxmem='5000'</p> <p style="text-align: left;">memory='4091'</p> <p style="text-align: left;">vcpus=2</p> <p style="text-align: left;">name='win1'</p> <p style="text-align: left;">device_model ='/usr/lib/xen-3.2-1/bin/qemu-dm'</p> <p style="text-align: left;">kernel='/usr/lib/xen-3.2-1/boot/hvmloader'</p> <p style="text-align: left;">pae=1</p> <p style="text-align: left;">acpi=1</p> <p style="text-align: left;">apic=1</p> <p style="text-align: left;">localtime=0</p> <p style="text-align: left;">vif=['bridge=eth0xenbr94']</p> <p style="text-align: left;">#vif=['bridge=xenconsole0']</p> <p style="text-align: left;">boot='c'</p> <p style="text-align: left;">#boot='d'</p> <p style="text-align: left;">sdl=1</p> <p style="text-align: left;">vnc=1</p> <p style="text-align: left;">vncunused=1</p> <p style="text-align: left;">vncviewer=1</p> <p style="text-align: left;">serial='pty'</p> <p style="text-align: left;">on_poweroff='destroy'</p> <p style="text-align: left;">on_reboot='restart'</p> <p style="text-align: left;">on_crash='restart'</p> <p style="text-align: left;">#disk=['phy:/dev/VGVMlocal1/win1,ioemu:hda,w','file:/home/win2008.iso,hdc,r']</p> <p style="text-align: left;">disk=['phy:/dev/VGVMlocal1/win1,ioemu:hda,w', 'phy:/dev/loop1,ioemu:hdc:cdrom,r']</p> <p style="text-align: left;"> </p> <p style="text-align: left;">#disk=['phy:/dev/VGVMlocal1/win1,ioemu:hda,w','phy:/dev/hda,hdc,r']</p> <p style="text-align: left;"> </p> <p style="text-align: left;"> </p> <p style="text-align: left;">[root@vmemail ~]#</p> <p style="text-align: left;"> </p> <p style="text-align: left;">this config work on debian for centos run this cmds</p> <p style="text-align: left;"> </p> <p style="text-align: left;">mkdir -p /usr/lib/xen-3.2-1/boot</p> <p style="text-align: left;">mkdir -p /usr/lib/xen-3.2-1/bin/</p> <p style="text-align: left;"> </p> <p style="text-align: left;">ln -s /usr/lib/xen/boot/hvmloader /usr/lib/xen-3.2-1/boot/hvmloader</p> <p style="text-align: left;">ln -s /usr/lib64/xen/bin/qemu-dm /usr/lib/xen-3.2-1/bin/qemu-dm</p> <p style="text-align: left;">ln -s /etc/xen/vmlist /var/cache/convirt/image_store</p> <div style="text-align: left;"><hr /></div> <p style="text-align: left;"> </p> <p style="text-align: left;">Script that make virtualization interfaces</p> <p style="text-align: left;"> </p> <p style="text-align: left;">xen:~# cat /etc/init.d/setup_network.sh</p> <p style="text-align: left;">#!/bin/bash</p> <p style="text-align: left;"> </p> <p style="text-align: left;">VLANS="10 30 47 49"</p> <p style="text-align: left;">#Interfaces for virtualization"</p> <p style="text-align: left;">VIFList="eth0 eth1"</p> <p style="text-align: left;">#Interfaces for management</p> <p style="text-align: left;">VIFxenConsole="eth2"</p> <p style="text-align: left;">#interfaces for connecting xen to storage such az iSCSI storage</p> <p style="text-align: left;">VIFStorageiSCSI="eth3"</p> <p style="text-align: left;"> </p> <p style="text-align: left;"> </p> <p style="text-align: left;">function add_if()</p> <p style="text-align: left;">{</p> <p style="text-align: left;">ip link set up eth0</p> <p style="text-align: left;">ip link set up eth1</p> <p style="text-align: left;">ip link set up eth2</p> <p style="text-align: left;">ip link set up eth3</p> <p style="text-align: left;"> </p> <p style="text-align: left;">echo "Enable IP forwarding"</p> <p style="text-align: left;">echo 1 > /proc/sys/net/ipv4/ip_forward</p> <p style="text-align: left;"> </p> <p style="text-align: left;">echo "Set Ethernet parameters for Virtual Interfaces"</p> <p style="text-align: left;">for i in $VIFList</p> <p style="text-align: left;">do</p> <p style="text-align: left;">echo "ethtool -K $i eth0 rx off tx off tso off gso off"</p> <p style="text-align: left;">ethtool -K $i eth0 rx off tx off tso off gso off</p> <p style="text-align: left;">done</p> <p style="text-align: left;"> </p> <p style="text-align: left;">echo</p> <p style="text-align: left;">echo "Set Ethernet parameters for Virtual Interfaces"</p> <p style="text-align: left;">echo "ethtool -K $VIFxenConsole sg on rx on tx on tso on gso on"</p> <p style="text-align: left;">ethtool -K $VIFxenConsole sg on rx on tx on tso on gso on</p> <p style="text-align: left;"> </p> <p style="text-align: left;">echo "Create Vlans,Bridge and add vlan's to bridges"</p> <p style="text-align: left;">for i in $VIFList</p> <p style="text-align: left;">do</p> <p style="text-align: left;">for z in $VLANS</p> <p style="text-align: left;">do</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">echo "vconfig add $i $z"</p> <p style="text-align: left;">vconfig add $i $z</p> <p style="text-align: left;">echo "ifconfig $i.$z up"</p> <p style="text-align: left;">ifconfig $i.$z up</p> <p style="text-align: left;">echo "##################"</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">echo "brctl addbr $i"xenbr"$z"</p> <p style="text-align: left;">brctl addbr $i"xenbr"$z</p> <p style="text-align: left;">echo "brctl addif $i"xenbr"$z $i.$z"</p> <p style="text-align: left;">brctl addif $i"xenbr"$z $i.$z</p> <p style="text-align: left;">echo "ifconfig $i"xenbr"$z up"</p> <p style="text-align: left;">ifconfig $i"xenbr"$z up</p> <p style="text-align: left;">echo "*********************"</p> <p style="text-align: left;">done</p> <p style="text-align: left;"> </p> <p style="text-align: left;">done</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">brctl show</p> <p style="text-align: left;">}</p> <p style="text-align: left;"> </p> <p style="text-align: left;"> </p> <p style="text-align: left;">function rm_if(){</p> <p style="text-align: left;"> </p> <p style="text-align: left;"> </p> <p style="text-align: left;">for i in $VIFList</p> <p style="text-align: left;">do</p> <p style="text-align: left;">for z in $VLANS</p> <p style="text-align: left;">do</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">echo "brctl delif $i"xenbr"$z $i.$z"</p> <p style="text-align: left;">brctl delif $i"xenbr"$z $i.$z</p> <p style="text-align: left;">echo "vconfig rem $i.$z"</p> <p style="text-align: left;">vconfig rem $i.$z</p> <p style="text-align: left;">echo "ifconfig $i"xenbr"$z down"</p> <p style="text-align: left;">ifconfig $i"xenbr"$z down</p> <p style="text-align: left;">echo "brctl delbr $i"xenbr"$z"</p> <p style="text-align: left;">brctl delbr $i"xenbr"$z</p> <p style="text-align: left;">echo "#######################"</p> <p style="text-align: left;">echo</p> <p style="text-align: left;">done</p> <p style="text-align: left;"> </p> <p style="text-align: left;">done</p> <p style="text-align: left;">brctl show</p> <p style="text-align: left;">}</p> <p style="text-align: left;"> </p> <p style="text-align: left;">case "$1" in</p> <p style="text-align: left;">start)</p> <p style="text-align: left;">add_if</p> <p style="text-align: left;">echo "Interfaces's Configurations is done.";;</p> <p style="text-align: left;">stop)</p> <p style="text-align: left;">rm_if</p> <p style="text-align: left;">echo "Virtualization Interfaces is done."</p> <p style="text-align: left;">;;</p> <p style="text-align: left;">esac</p> <p style="text-align: left;">exit 0</p> <p style="text-align: left;">xen:~#</p> <div style="text-align: left;"><hr /></div> <p style="text-align: left;"> </p> <p style="text-align: left;"> </p> <h2 id="error.3ACDROMbootfailure" style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;">error: CDROM boot failure</h2> <p style="text-align: left;"> </p> <p class="line874" style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;">You get the error :</p> <ul style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;"> <li style="list-style-type: none;"> <pre style="border-width: 1pt; border-style: solid; border-color: #aebdcc; background-color: #f3f5f7; padding: 5pt; font-family: courier,monospace; white-space: pre-wrap; word-wrap: break-word;">CDROM boot failure code 0002 or CDROM boot failure code 0003 Boot from cd-Rom failed Fatal: Could not read the boot disk.</pre> </li> </ul> <p class="line862" style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;">That's because Xen can't boot from a cdrom iso image at the moment. i.e you can't have <tt>tap:aio:/path/to/mycd.iso,hdc:cdrom,r</tt> <em>or</em> <tt>file:/path/to/mycd.iso,hdc:cdrom,r</tt>.</p> <p class="line874" style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;">Workaround: use losetup to create a loopback device for the cdrom ISO image, then use it in Xen configuration file. for example :</p> <ul style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;"> <li style="list-style-type: none;"> <pre style="border-width: 1pt; border-style: solid; border-color: #aebdcc; background-color: #f3f5f7; padding: 5pt; font-family: courier,monospace; white-space: pre-wrap; word-wrap: break-word;">#First, check which loop device is free $losetup -f /dev/loop9 #Then create a loopback device $losetup -f /path/to/mycd.iso losetup /dev/loop9 /dev/loop9: [fe04]:3096598 (/path/to/mycd.iso)</pre> </li> </ul> <p class="line874" style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;">Now you can use /dev/loop9 in xen configuration file (/etc/xen/foobar.cfg) :</p> <ul style="color: #000000; font-family: Arial,'Lucida Grande',sans-serif; font-size: 16px; line-height: normal; text-align: left;"> <li style="list-style-type: none;"> <pre style="border-width: 1pt; border-style: solid; border-color: #aebdcc; background-color: #f3f5f7; padding: 5pt; font-family: courier,monospace; white-space: pre-wrap; word-wrap: break-word;">... disk = [ 'phy:/dev/vg1/xpsp3,ioemu:hda,w', 'phy:/dev/loop/0,ioemu:hdc:cdrom,r' ] ...
then boot/install the guest OS.
note: yo should switch back to the tap:aio:/path/to/mycd.iso,hdc:cdrom,r syntax after installation, since loop back have to be recreated after you reboot the host system.
Serial console access
To get output from grub, XEN, the kernel and getty (login prompt) via both vga and serial console to work, here's an example of the right settings when using Lenny kernels and Xen 3.2:
In /boot/grub/menu.lst:
serial --unit=0 --speed=9600 --word=8 --parity=no --stop=1 terminal --timeout=5 serial console [...] title Xen 3.2-1-amd64 / Debian GNU/Linux, kernel 2.6.26-2-xen-amd64 root (hd0,0) kernel /boot/xen-3.2-1-amd64.gz com1=9600,8n1 console=com1,vga module /boot/vmlinuz-2.6.26-2-xen-amd64 root=/dev/md0 ro console=tty0 console=hvc0 module /boot/initrd.img-2.6.26-2-xen-amd64
In contrast to the Etch configuration, there's no ttyS0 in the vmlinuz line!
In /etc/inittab you need at least these lines:
1:2345:respawn:/sbin/getty 38400 hvc0 2:23:respawn:/sbin/getty 38400 tty1 # NO getty on ttyS0!
The tty1 will show up at the vga output, and the hvc0 will show up at the serial console
rc.local
xen:~# cat /etc/rc.local
#!/bin/sh -e
#
#
echo 'hwcap 0 nosegneg' > /etc/ld.so.conf.d/libc6-xen.conf && ldconfig
xm mem-set 0 8091
ntpdate -s dc1
iscsiadm -m discovery -t st -p 192.168.200.5
iscsiadm -m node --targetname "iqn.1986-03.com.hp:storage.msa2312i.0938da0e3f" --portal "192.168.200.5:3260" --login
pvscan
vgchange -a y
#iscsiadm -m node --targetname "172.21.0.39:3260,1 iqn.2004-08.jp.buffalo:TS-RIGL333-001D73269333:Vol1" --portal "172.21.0.39:3260" --logout
#dd if=/dev/VGVMlocal/nodelwin2k3r2sp2_001 |ssh This e-mail address is being protected from spambots. You need JavaScript enabled to view it. "dd of=/home/msafizadeh/nodelwin2k3r2sp2_001.iso"
pvscan
vgchange -a y
#For smooth operation and good guest performance you need to make sure dom0 always gets enough CPU time to process and serve the IO requests for guests.
xm sched-credit -d Domain-0 -w 512
#ssh xen02 'lvcreate -L25G -n /dev/VGNetstorage01/DevelopTest'
#for i in `cat /etc/xen/vmlist/currentvm`; do xm create /etc/xen/vmlist/$i; done
#dd if=/dev/VGVMlocal/Deve |pv -s 25G |ssh root@xen02 "dd of=/dev/VGNetstorage01/Deve"
#dd if=/dev/VGVMlocal/nodelwin2k864_ |pv -s 51G |dd of=/dev/VGNetstorage01/Ola bs=8091
#dd if=/dev/VGVMlocal/nodelwin2k3r2sp2_001 |pv -s 52G |ssh root@xen04 "dd of=/dev/VGVMlocal/vmehrdev"
/bin/sh /root/.scripts/Dedicat_CPU_to_xen
mount -t ext3 -o acl,usrquota,grpquota /dev/VGNetstorage01/data /home/data
/etc/init.d/samba restart
/etc/init.d/winbind restart
/etc/init.d/nscd restart
exit 0
xen:~#
.
How to set the virtual guest clock
By default, the clocks in a Linux VM are synchronized to the clock running on the control domain, and cannot be independently changed (Any attempts to set or modify the time in a guest will fail). This mode is a convenient default, since only the control domain needs to be running the NTP service to keep accurate time across all VMs.
Paravirtualized guests may also perform their own system clock management:
-
Add the following lines to
/etc/sysctl.conf, and reboot the system:# Set independent wall clock time xen.independent_wallclock = 1
-
You can temporarily override the setting for the current session in the proc filesystem. For example, as root run the following command on the guest:
# echo 1 > /proc/sys/xen/independent_wallclock
-
Pass "independent_wallclock=1" as a boot parameter to the VM.

