作業請參考 Lab 1 assignment

Lab 1: Virtual Technelogy: UML and KVM

實驗描述

本實驗示範如何運用 Paravirtualization (UML) 與 Full virtualization (KVM) 建立虛擬叢集環境.

實驗環境

資訊科學大樓 701 教室
  Real machines
CPU AMD Athlon(tm) 64 X2 5600+
Memory 1883M
Disk space 137G
O.S. Debian squeeze
理學大樓 821 機房
  CSIE-Cloud01
CPU 4 AMD Opteron(tm) Processor 6128 processors
(16 cpu cores)
Memory 8G
Disk space 500G*2
O.S. Debian squeeze
  CSIE-Cloud02
CPU 4 AMD Opteron(tm) Processor 6128 processors
(16 cpu cores)
Memory 8G
Disk space 500G*2
O.S. Debian squeeze

安裝實作

Remote Version

  1. 建立 User Mode Linux, UML, 虛擬機器.
    1. UML Compilation
    2. UML Template Creation


    1. Check whether you got linux.uml and its related module
    2.   $ ls -l /usr/local/lib/uml 
        # If you get No such file or directory 
        $ sudo apt-get install uml-utilities vde2
        $ sudo mkdir /usr/local/lib/uml 
        $ sudo chown cloud:cloud /usr/local/lib/uml 
        $ cd /usr/local/lib/uml 
        $ scp 701-teacher:/backup/tmp/uml-2011-08-01.tgz .
        $ tar -zxvf uml-2011-08-01.tgz 
        $ ls -l 
        $ rm uml-2011-08-01.tgz 
        # Later on, these files will be re-generated.
        $ sudo cp linux.uml /usr/local/bin
      
    3. Now, get template and related tools from our server
        $ cd /src3/UML 
        # If no such directory
        $ sudo mkdir /src3/UML 
        $ sudo chown cloud:cloud /src3/UML;  cd /src3/UML 
        $ rm -f *
        $ scp 701-teacher:/src2/uml-rfs/Config-UML-Rfs . 
        $ ln Config-UML-Rfs Config-UML-Rfs-UmlSwitch 
        $ scp -r 701-teacher:/src2/uml-rfs/DebianNetFiles . 
        $ scp 701-teacher:/src2/uml-rfs/DebianNet-*txt . 
        $ scp 701-teacher:/src2/uml-rfs/[Ru]* . 
        $ scp 701-teacher:/src2/uml-rfs/DebSqz-UltraLight.ext3.gz .  
        $ gunzip DebSqz-UltraLight.ext3.gz 
        $ sudo mount -o loop DebSqz-UltraLight.ext3 /mnt/tmp 
        # In another xterm
        $ sudo rm -rf /mnt/tmp/lib/modules/* 
        $ cd /usr/local/lib/uml/lib/modules/ 
        $ find . -print | sudo cpio -pdm /mnt/tmp/lib/modules/ 
        $ sync; sync 
        $ ls -l /mnt/tmp/lib/modules 
        # Back to the original xterm 
       $ sudo umount /mnt/tmp 
      
    4. Configure and Test VM
        $ Config-UML-Rfs
      ./Config-UML-Rfs root-fs-pathname uml-hostname UML-IP Ether-Card [TAP-No]
          TAP-No is optional, if need tap to be different from tap0.
        $ Config-UML-Rfs ./DebSqz-UltraLight.ext3 av-102 192.168.1.* eth0 
        # Hopefully, you get startUML, startUMLAsDaemon, stop-uml-restore-lan, 3 files.
        # The first script is for starting UML in foreground.  For system repairing
        # or maintenance reasons, from time to time, we need to start our VMs in 
        # the foreground.  For common usage, whether it be special server, compute
        # slave in some high performance cluster, usually, we start it as a daemon.
        # After halting a VM, it is our job to restore the system network state to 
        # its origin. Otherwise, next time, we will have hard time to get our VM's
        # virtual network working again.
        # Nowadays, the smallest graphical system needs at least 1GB.  Otherwise, 
        # it would be almost impossible to upgrade system safely.  How I hate it!
        $ startUML 
        # login UML as cloud, and in UML
        $ su 
        ;; The first time online, take care of cached share object library database
        ;; so that the system know where they are, especially, some libraries are 
        ;; are from /usr/local/lib.
        # ldconfig
        # aptitude update; aptitude safe-upgrade 
        # aptitude clean 
        # deborphan 
        ;; If anything shows up,
        # dpkg -P `deborphan` ;; Do these two commands until deborphan return nothing
        # halt ;; shutdown uml
        ;; We need to restore lan to its original state 
        $ ifconfig -a ;; You see tap0, a virtual ethernet card
        $ stop-uml-restore-lan 
        $ ifconfig -a ;; The tap0 virtual ethernet card should disappear 
        $ startUMLAsDaemon  
        $ ps -C linux.uml 
        ;; Wait for two or three minutes 
        $ xs av102 ;; check whether you can login or not.
        ;; After login, type exit.
      

  2. 建立 Kernel-based virtual machine, KVM, 虛擬機器.
  3. The procedures involved for starting and halting VMs are rather complicated, but the command lines need to accomplish the whole job are quite similar. If we are going to key-in all the commands by hands, it is rather error-prone. Our biggest contribution is that we unify the whole process, from starting to halting UML or KVM VMs, via rather similar procedures, such as startVM in foreground, startVM as daemon, stop-VM-restore-lan. And we write a shell script to prepare the above 3 scripts automatically.

    1. Kvm Compilation
    2. Kvm Template Creation


    1. Check hardware virtualization support, and then install KVM.
        $ egrep '(vmx|svm)' --color=always /proc/cpuinfo # Hardware Assisted Virtualization
        $ sudo aptitude update
        $ sudo aptitude install kvm qemu-utils vde2 socat
        $ sudo modprobe kvm_amd
        ## logout and relogin
        $ sudo adduser cloud kvm
      
    2. Prepare for VM.
        $ sudo mkdir /src4/KVM 
        $ sudo chown cloud:cloud /src4/KVM  
        $ cd /src4/KVM; mkdir Resize img 
        $ cp /backup/KVM-tool/KVM-tool-*.tgz . 
        # $ cp /backup/KVM-tool/Resize/Resize-*.tgz Resize 
        # $ cd Resize; tar -zxvf Resize-*.tgz; rm Resize-*.tgz 
        $ cd ..; tar -zxvf KVM-tool-*.tgz; rm KVM-tool-*.tgz 
      
    3. Create KVM root-filesystem.
        $ cd img 
        $ qemu-img create DebSqz-Mini.img 2G 
        $ kvm -cdrom ../Resize/debian-6.0.2.1-amd64-netinst.iso DebSqz-Mini.img -m 512M
      
      Partition the image as: /boot and /

      Give 512M to boot, turn on its boot flag, use ext2 filesystem format. The rest for / partition, use ext4 filesystem format. Install only the minimal packages offered by the installation menu, but must include openssh-server, since we need to login the VM via ssh.

    4. Configure VM
        $ cd ../bin 
        $ ls -lia Config-Kvm* 
        # Notice the three files are the same. When invoke them by different names,
        # we can configure image files for different OSes.
        # Also, as far as I remembered, newer Debian VM need to run the command
        # sudo ./recover70rules. Otherwise, next time eth0 is no longer available. 
        $ ./Config-Kvm 
        # We use this script to configure ../Resize/Debian-Gparted.img. 
        $ Config-Kvm ../img/DebSqz-Mini.img ak-102 192.168.1.? eth0 1
        $ start-ak*-1 
        # login KVM as cloud, and in KVM
        $ su
        # ./recover70rules 
        # halt 
        $ start-ak-*-1-AsDaemon
        $ xs ak102
        ;; After login, type exit.
        $ stop-ak-*-restore-lan-1

Lab 1: Assignment