1. Install More Packages via reinstallMyPkg
     $ sudo apt-get install dselect 
     $ sudo apt-get dselect-upgrade 
     $ cd /tmp 
     $ sudo ./reinstallMyPkg packages.txt
    
  2. Essential Parts of Virtualization
  3. UML Compilation

    Get it from as:

     ########################################################################### 
     # On gateway: 
     # $ scp as:/backup/tmp/uml-2016-05-15.tgz /tmp 
     ########################################################################### 
     # For the rest: $ scp 192.168.0.254:/tmp/uml-2016-05-15.tgz /tmp
     $ if [ ! -d  /usr/local/lib/uml ]
         then sudo mkdir /usr/local/lib/uml 
              sudo chown cloud:cloud /usr/local/lib/uml 
       else rm -rf /usr/local/lib/uml/*
       fi
     $ cd /usr/local/lib/uml
     $ tar -zxvf /tmp/uml-2016-05-15.tgz 
     $ sudo cp linux.uml /usr/local/bin 
     # Make sure linux.uml is executable
     $ linux.uml --version 
    

    Note: (05/17/2013)

    1. Last week, Su found out that UML console resizing caused it to coredump.
    2. Reason: SIGWINCH (signal 28) (Window Change) can't be handled (via interrupt 10) in Kernel 3.8. Verify this by logining av02 and av20 and
      hsu@av-02:~$ cat /proc/interrupts
                 CPU0       
        0:   16168825  SIGVTALRM  timer
        2:          0     SIGIO  console
        3:          0     SIGIO  console-write
        4:     324446     SIGIO  ubd
        5:     110484     SIGIO  eth0
        9:          0     SIGIO  mconsole
      -------------------------------------------------------
       10:          0     SIGIO  winch
      -------------------------------------------------------
       11:          0     SIGIO  write sigio
       14:          1     SIGIO  random
      
    3. Bad news is Kernel 3.8.13 was released, and it will no longer be maintained. We have no choice but get the newest kernel 3.9.2
    4. We also need to repair the UML root file systems created last week:
      • Shutdown uml via stop-uml-and-* shell script
      • sudo mount -o loop Dev1-Light.ext4 /mnt/tmp
      • sudo rm -rf /mnt/tmp/lib/modules/*
      • From another xterm:
          $ cd /usr/local/lib/uml/lib/modules
          $ ls -l  # Should be 3.9.2
          $ find . -print | sudo cpio -pdm /mnt/tmp/lib/modules
          $ ls -l /mnt/tmp/lib/modules
          $ sudo umount /mnt/tmp 
        
      • Back to the original xterm:
         $ sudo cp /usr/local/lib/uml/linux.uml /usr/local/bin
        
      • Use shell script startUML to restart it and login, make sure that everything is normal. And kernel is 3.9.2, etc. And shut it down.
      • Now, cp Dev1-Light.ext4 Dev1-Light-1.ext4
      • Config-UML-Rfs ./Dev1-Light-1.ext4 vm-2-b01 192.168.2.* eth0 1

        The last byte can be determined via "$ ifconfig eth0"

      • Start all the VMs in the background.
  4. Debian Jessie UML Root Filesystem

    Web Page UML Template Creation has all the details about UML Template Creation, and its contents has been tested numerous times.

    Usually, after Root Filesystem creation, we test it for some period. If it is stable and reliable, we compress and store the filesystem template in some server. When we need a root filesystem, we download it from our server. In order to save the bandwidth, we tend to create a template with just enough space to hold its software packages. Hence, resizing UML root filesystem is a critical virtualization technique to master: UML Resizing

  5. Now, get template and related tools from our server
      # We need SameSubnetP for testing whether VM and its host are in the same subnet.
      $ cd /tmp; mkdir SubnetTest; cd SubnetTest
      $ scp amdm:/backup/KVM-tool/SubnetTest/* .; make; make install
      $ cd /src3/UML 
      # If no such directory, execute the next few commands.
      # $ sudo mkdir /src3/UML 
      # $ sudo chown cloud:cloud /src3/UML;  cd /src3/UML 
      ########################################################################### 
      # On gateway, 
      # mkdir /tmp/UML; cd /tmp/UML; scp -r as:/backup/UML-tool/* .
      # wget http://140.120.7.21/uml-rfs/Dev1-Light.ext4.gz 
      # gunzip Dev1-Light.ext4.gz; mount it and chroot to /mnt/tmp
      # add user cloud and its passwd. Change root passwd.  Edit /etc/apt/sources.list
      # aptitude update; aptitude safe-upgrade 
      # exit chroot, umount /mnt/tmp.  Then gzip Dev1-Light.ext4
      ########################################################################### 
      # The rest: scp -r 192.168.0.254:/tmp/UML/* /src3/UML 
      # Config-UML-Rfs and Config-UML-Rfs-UmlSwitch are the same shell script with 
      # different names. Keep them consistent is important.
      # rm Config-UML-Rfs-UmlSwitch; ln -s Config-UML-Rfs Config-UML-Rfs-UmlSwitch
      $ gunzip Dev1-Light.ext4.gz 
      $ sudo mount -o loop Dev1-Light.ext4 /mnt/tmp 
      # Open a new xterm, and execute the next few commands from this new 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 
      # Check whether linux.uml and Dev1-Light.ext4 are working as expected
      $ linux.uml ubd0=Dev1-Light.ext4 mem=256M 
      # When seeing the login prompt: (1) Login as cloud, (2) su, (3) halt -f 
      # Our virtual machine will use subnet (192.168.1.*, 192.168.2.*, 192.168.3.*, etc.) 
      # different from our host 192.168.0.*.  Hence, we set our host as VM's router, and 
      # use it to reach out. In the /etc/rc.local of Vm, the line is added:
      # route add 192.168.0.33/32 dev eth0
    
  6. Configure and Test VM

    Note: (05/02/2014) If booting ever failed, we must modify phyical host's /etc/fstab as documented in UmlCompilation.

      # Need to come up with meaningful uml-hostname, UML-IP, the second and third students 
      # need to change TAP-No to 2 and 3 respectively.
      $ 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 ./Dev1-Light.ext4 av-02 140.120.*.* eth0 1 
      # 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, and in UML
      # First, check whether we can reach out and touch someone.
      $ ping -c 3 140.120.1.2
      $ 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; exit ;; shutdown and exit 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 av02 ;; check whether you can login or not.
                ;; After login, type exit.
    
  7. Login our virtual machine.
     $ xs av02
     $ df
    Filesystem           1K-blocks      Used Available Use% Mounted on
    /dev/ubd0              1007896    723248    233448  76% /
    tmpfs                     5120         0      5120   0% /lib/init/rw
    tmpfs                    49768        52     49716   1% /run
    udev                     10240         0     10240   0% /dev
    tmpfs                    99532         0     99532   0% /run/shm
     df /usr/local /src2
    Filesystem           1K-blocks      Used Available Use% Mounted on
    -                     14417392   3645152  10039876  27% /usr/local
    -                     28835836    339924  27031132   2% /src2
     # Notice that only 233MB free space left, system upgrade might fail!!
     # If anyone breaks into this VM, not too much space left, he/she can
     # not download too much stuff.  
     # Also, sizes of /usr/local and /src2 are much larger than 1GB, they 
     # are filesystems of the physical host.
     # Check system security, if the size of /var/log/auth.log is larger than 
     # 70K, we must watch out!
     $ ls -l /var/log/auth*
     # If sizeof(/var/log/auth.log) >= 1M, find out who had been attacking.
     $ which IpTracing.sh
     # Check whether fail2ban (security related) package is running.  No need to 
     # run this on the host, since we only allow a few IPs to login our hosts.
     $ ps alx | grep fail2ban
     # Get familiar with filesystems, inode number == 2.
     $ ls -lia /
     $ more /etc/rc.local 
     # Notice we export (physical) /usr/local and /src2 filesystems to VM (via hostfs).
     # Get familiar with useful commands
     $ hostname
     $ uname -a 
     # su 
     # aptitude update; aptitude safe-upgrade
     # aptitude clean
     ;; After binary package update, sometimes, some of the older binary packages 
     ;; become useless, i.e. orphaned.  We remove such packages so that we don't 
     ;; need to upgrade them anymore.  This saves a lot of bandwidth.  And, more 
     ;; importantly, keep our system clean, if we ever need to repair our system, 
     ;; or restore it from scratch, this will save us a lot of hassle.
     # deborphan
     ;; If there is output for the last command, then
     # dpkg -P `deborphan`
     ;; Repeat the last two commands until deborphan is quiet!
     # sync; sync
     ;; Leaving the super user mode 
     # exit
     # Quit from the network connection for av02
     $ exit
     # A useful shell script for keeping track of currently installed packages.
     # We can use it to restore our system in case of emergency, such as 
     # removing a seemingly useless package causes a lot of libraries to be 
     # removed, too. 
     $ pwd 
    /home/hsu/inet
     $ ShellScripts/PkgInstalled 
     $ more /tmp/dpkg.selections.txt 
     $ mv /tmp/dpkg.selections.txt . 
    
  8. Turn our virtual machine to a http server
      $ sudo apt-get install apache2 
      $ ls -l /var/www/html 
    
  9. Homework Due