Ubuntu 6.06.2 - Xen virtualization recipe ========================================= Public domain ******************************************************************************** --------Xen 3.0.2-2 / Ubuntu 6.06.2 Installation Progress ------------------------------------------ 1. Install Ubuntu server 6.06.2 (Dapper Drake) with 3 partitions : /dev/hda1 512MB swap /dev/hda2 10GB / /dev/hda3 30GB /xen-images 2. [Optional] Copy previously downloaded ubuntu ( Insert Packages CD ) : $ sudo -i # mount /cdrom # cd /var/cache/apt # tar zxvf /cdrom/archives.tar.gz # eject /cdrom 3. Update the server : $ sudo -i # apt-get update # apt-get upgrade 4. Install SSH server for remote access : # apt-get install ssh 5. Install additionall packages ( Insert Ubuntu Installation CD ): # apt-get install \ bridge-utils \ build-essential \ bzip2 \ debootstrap \ gcc \ gs \ iproute \ libc6-dev \ libcurl3 \ libcurl3-dev \ libncurses5 \ libncurses5-dev \ module-init-tools \ ncurses-term \ netpbm \ openssl \ python \ python-dev \ python-twisted \ tetex-base \ tetex-extra \ transfig \ zlib1g \ zlib1g-dev 6. Download Xen 3.0.2-2 : # cd /usr/src # wget http://www.cl.cam.ac.uk/research/srg/netos/xen/downloads/xen-3.0.2-2-src.tgz [optional] OR copy previously downloaded source (Insert Packages CD): # mount /cdrom # cp /cdrom/xen-3.0.2-2-src.tgz /usr/src # eject /cdrom 7. Install Xen 3.2.2-2 : # cd /usr/src/ # tar zxvf xen-3.0.2-2-src.tgz # cd xen-3.0.2-2 [optional] copy previously downloaded Linux kernel 2.6.16 (Insert Packages CD): # mount /cdrom/ # cp /cdrom/linux-2.6.16.tar.bz2 /usr/src/xen-3.0.2-2 # eject /cdrom # make world && make install # depmod -a 2.6.16-xen 8. Add this line to FILE "/etc/mkinitramfs/modules" ( Increase loop divices ) : loop max_loop=64 9. Make initial RAMFS : # cd /boot # mkinitramfs -o initrd.img-2.6.16-xen 2.6.16-xen 10. Add to FILE "/boot/grub/menu.lst" before first kernel title ( BootLoader Config ) : title Xen 3.0 / XenLinux 2.6 kernel /boot/xen-3.gz module /boot/vmlinuz-2.6-xen root=/dev/hda2 ro module /boot/initrd.img-2.6.16-xen 11. Xen startup configuration : # update-rc.d xend start 30 2 3 4 5 . stop 31 0 1 6 . # update-rc.d xendomains start 31 2 3 4 5 . stop 30 0 1 6 . 12. Disable Thread-Local Storage : # mv /lib/tls /lib/tls.disabled 13. Fixing Xen udev rule : # mv /etc/udev/rules.d/xen-backend.rules /etc/udev/rules.d/92-xen-backend.rules 14. Add this to FILE "/etc/init.d/xend" after "/proc/xen/capabilities" check : if [ ! -d /var/run/xend ] ; then mkdir -p /var/run/xend fi if [ ! -d /var/run/xenstored ] ; then mkdir -p /var/run/xenstored fi 15. Chaging LOCKFILE location in "/etc/init.d/xendomains" : LOCKFILE=/var/lock/xendomains 16. Bootup Xen kernel : # reboot 17. After reboot verifying Xen : $ sudo -i # xm list Name ID Mem(MiB) VCPUs State Time(s) Domain-0 0 217 1 r----- 12.1 --------Xen 3.0.2-2 / Ubuntu 6.06.2 Configuration Progress ----------------------------------------- 1. Create baseimage : # mkdir /xen-images/mnt # dd if=/dev/zero of=/xen-images/guest_base.img bs=1024k count=1000 # dd if=/dev/zero of=/xen-images/guest_base-swap.img bs=1024k count=500 # chmod 640 /xen-images/guest_base* 2. Format images : # mkfs.ext3 /xen-images/guest_base.img # mkswap /xen-images/guest_base-swap.img 3. Install Ubuntu Dapper into images : # mount -o loop /xen-images/guest_base.img /xen-images/mnt [Optional] Copy Previously downloaded base packages (Insert Package CD ) : # mount /cdrom # mkdir -p /xen-images/mnt/var/cache/apt # cd /xen-images/mnt/var/cache/apt # tar zxvf /cdrom/base-packages.tar.gz # cd - # eject /cdrom # debootstrap --arch i386 dapper /xen-images/mnt http://archive.ubuntu.com/ubuntu/ (other mirror: http://swtsrv.informatik.uni-mannheim.de/pub/linux/distributions/ubuntu/ ) 4. Configure APT : # cp /etc/apt/sources.list /xen-images/mnt/etc/apt/ 5. Copy kernel modules : # cp -dpR /lib/modules/2.6.16-xen /xen-images/mnt/lib/modules/ 6. Disable Thread-Local Storage : # mv /xen-images/mnt/lib/tls /xen-images/mnt/lib/tls.disabled 7. Add these lines to Network Configuration FILE in "/xen-images/mnt/etc/network/interfaces" : # The loopback network interface auto lo iface lo inet loopback # The primary network interface #auto eth0 #iface eth0 inet static # address 192.168.0.101 # netmask 255.255.255.0 # broadcast 192.168.0.255 # gateway 192.168.0.1 # dns-nameservers 192.168.0.1 8. Create hosts FILE in "/xen-images/mnt/etc/hosts" : 127.0.0.1 localhost localhost.localdomain 127.0.0.1 guest # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts 9. Configure HOSTNAME : # echo guest > /xen-images/mnt/etc/hostname 10. Configure mount points FILE in "/xen-images/mnt/etc/fstab" : proc /proc proc defaults 0 0 /dev/hda1 / ext3 defaults,errors=remount-ro 0 1 /dev/hda2 none swap sw 0 0 11. Unmount baseimage : # umount /xen-images/mnt 12. Create baseimage config FILE in "/etc/xen/baseimage" : # -*- mode: python; -*- kernel = "/boot/vmlinuz-2.6.16-xen" ramdisk = "/boot/initrd.img-2.6.16-xen" memory = 33 name = "baseimage" vif = ['bridge=xenbr0'] disk = ['file:/xen-images/guest_base.img,hda1,w','file:/xen-images/guest_base-swap.img,hda2,w'] ip = "192.168.0.101" netmask = "255.255.255.0" gateway = "192.168.0.1" hostname = "baseimage" root = "/dev/hda1 ro" extra = "4" 13. Starting baseimage : # xm create baseimage -c 14. Login as root and set root password : # passwd # shadowconfig on 15. Create a backup of "/etc/network/interfaces" : # cp /etc/network/interfaces /etc/network/interfaces.bak 16. Edit "/etc/network/interfaces" and connect to internet : # vi /etc/network/interfaces # /etc/init.d/networking restart 17. Install base packages : # apt-get update # apt-get install ubuntu-base openssh-server ( Other Mirror : sed -i /etc/apt/sources.list -e 's,http://us.archive.ubuntu.com/ubuntu/,http://swtsrv.informatik.uni-mannheim.de/pub/linux/distributions/ubuntu/,' ) 18. Disable Thread-Local Storage : # mv /lib/tls /lib/tls.disabled 19. Restore "/etc/network/interfaces" backup : # /etc/init.d/networking stop # mv /etc/network/interfaces.bak /etc/network/interfaces 20. Shutdown baseimage : # poweroff 21. Make a copy of baseimages for first guest domain : # cp /xen-images/guest_base.img /xen-images/guestdom1.img # cp /xen-images/guest_base-swap.img /xen-images/guestdom1-swap.img # mv /etc/xen/baseimage /etc/xen/guestdom1 22. Change FILE "/etc/xen/guestdom1" for first guest domain : name = "guestdom1" disk = ['file:/xen-images/guestdom1.img,hda1,w','file:/xen-images/guestdom1-swap.img,hda2,w'] hostname = "guestdom1" 23. Mount first domain image : # mount -o loop /xen-images/guestdom1.img /xen-images/mnt/ 24. Change hostname of first domain : # echo FirstDomain > /xen-images/mnt/etc/hostname 25. Edit FILE "/xen-images/mnt/etc/hosts" and change hostname : 127.0.0.1 FirstDomain 26. Change Network Settings in FILE "/xen-images/mnt/etc/network/interfaces" 27. Unmount first domain image : # umount /xen-images/mnt 28. Automatic startup for first guest domain : # ln -s /etc/xen/guestdom1 /etc/xen/auto/ 29. Manually start first guest domain : # xm create guestdom1 30. List Virtual Machins : # xm list 31. Attach to Domain : # xm console 6 32. Further Documents : http://www.cl.cam.ac.uk/Research/SRG/netos/xen/documentation.html ---------------------------------------------------------------------------------------- ******************************************************************************** _BY: Pejman Moghadam_ _TAG: xen, virtualization, fstab_ _DATE: 2009-05-27 17:37:00_