Creating Xen Hardware based Virtual Machines (HVM)

From Notes_Wiki
Revision as of 08:07, 22 January 2019 by Saurabh (talk | contribs)

<yambe:breadcrumb self="Creating Xen Hardware based Virtual Machines (HVM)">Xen|Xen</yambe:breadcrumb>

Creating Xen Hardware based Virtual Machines

A more updated lab is available at http://www.sbarjatiya.com/website/courses/2010/monsoon/system_and_resource_virtualization/labs/03-creating_xen_hvm_guests.pdf


We can create Xen HVM based virtual machines using following steps. Note that for HvM guests we need support from hardware.

Checking for hardware support for HVM

To check whether current processor supports HVM or not use:

  • On Intel based processors
grep vmx /proc/cpuinfo
  • On AMD based processors
grep svm /proc/cpuinfo


Boot into xen kernel

Install CentOS 64 bit on base machine and boot into xen kernel from grub menu. Also ensure that services:

  • libvirtd
  • xend
  • xendomains

are all running


Creating new Xen guest using HVM

  1. (normal user)Create raw disk image and download OS iso
    1. Go to partition where you have enough disk space (>=20GB)
    2. Create folder lab1
    3. Go inside folder lab1
    4. Create raw disk image of size 10GB using 'dd if=/dev/zero of=xenguest.img bs=1024k seek=10240 count=0'
    5. Download OS iso from local file share.
  2. (root) Configure HVM and start domain Lab1
    1. Go to '/etc/xen'
    2. Copy example HVM guest configuration file 'xmexample.hvm' to 'lab1.hvm'
    3. Edit 'lab1.hvm' and change following options
      1. Set 'memory=600' as GUI installation of many modern OS requires lot of RAM. After OS installation is over, we can configure guest to boot in runlevel 3 and then reduce RAM alloted to VM.
      2. Increase shadow memory - 'shadow_memory = 40'
      3. Give proper name to domain - 'name = "Lab1"'
      4. Ensure that network interface information is correct - 'vif = [ 'type=ioemu, bridge=xenbr0' ]'. Use 'ifconfig' to see that xenbr0 actually exists. If you are connected to LAN using eth1 and not eth0 then the bridge device could be xenbr1 and not xenbr0.
      5. Set proper paths for raw disk image and OS installation iso image - 'disk = [ 'file:<complete path to raw image>,hda,w', 'file:<complete path to OS iso file>,hdc:cdrom,r' ]
      6. Set proper boot order to boot from CD - 'boot="dc"'
      7. Disable snapshots if they are enabled - 'snapshot=0'
      8. Ensure that SDL is disabled ('sdl=0') and vnc is enabled ('vnc=1')
      9. For modern operating systems enable acpi and apic. ('apic=1' and 'acpi=1')
      10. For 32-bit OS we can leave 'pae=0', but for 64-bit OS make sure to enable pae using 'pae=1'.
      11. For Linux guests use - "usbdevice='mouse'" and For Windows guests use - "usbdevice='tablet'"
    4. Start domain Lab1 using command 'xm create lab1.hvm -c'. Here '-c' is used to attach console as soon as guest starts so that we can diagnose errors which occur during guest creation.
  3. (normal user)Start vnc session to created guest
    1. Use command 'ps -ef | grep vnc' to see what command line value was passed for '-vnc' to 'qemu-dm' In case multiple qemu-dm are running then you can check value of '-domain-name' option .
    2. Start vncviewer and connect to that screen. For example if argument to 'qemu-dm' was '-vnc 127.0.0.1:3', then use 'vncviewer 127.0.0.1:3' to connect to guest.
  4. Install guest OS. Remember to give sufficient swap space to guest OS.
  5. After installation is complete change boot order in 'lab1.hvm' file to 'boot="cd"' to boot first from harddisk.
    1. Normally OS reboot after installation and hence Guest would again boot from CD. So first destroy current guest using 'xm destroy Lab1'. Replace 'Lab1' with value of parameter 'name' that you have specified in configuration file.
    2. Edit configuration file to change boot order to 'boot="cd"'. We can also detach cdrom iso by not specifying any value for hdc - 'disk = [ 'file:<path to hdd image>,hda,w', ',hdc:cdrom,r' ]'
    3. Start domain again using 'xm create lab1.hvm -c'
    4. Again use 'ps' and 'vncviewer' commands to gain GUI access to newly created guest which now will boot from disk image.


Seeing list of running domains

We can use command 'xm list' to see list of running xen domains.


Lab task

  1. Try to install Windows XP on same raw hard-disk image where previously Cent OS 32 bit was installed.
    1. What problem, if any, did you face during installation?
    2. How was it rectified?
    The problem is that Windows installation CD will ask for key to be pressed to boot from CD, but before even we connect to VNC to press key, system starts booting from harddisk into previously installed OS. To solve the problem we can create new raw image using 'dd if=/dev/zero of=lab1.img bs=1024k seek=10240 count=0' so that all old information is lost. Now windows installation wont wait for key press as it would detect raw harddisk and installation will start.
  2. You will face serious mouse control problem with Windows OS, if you do not set "usbdevice='tablet'" option. How can you solve this problem to some extent without changing 'usbdevice' setting in HVM configuration file?
    You can enable remote desktop and use rdesktop to connect to Windows machine. This will solve the mouse coordination problem.


Tips

  • Pressing 'F8' in vncviewer gives pop-up vnc menu to send 'F8', 'Ctrl+Alt+Del' etc. to guest OS.
  • When guest reboots VNC window will get disconnected and also new VNC server will listen on another port. Use 'ps' command to find the new port and connect to guest again after it reboots.


Note

  • Installation of Windows 7 and Windows Server 2008 fails when using above steps with default version of applications that come with Cent OS 5.5. After complete updation of OS, kernel and all tools and subsequent reboot to use latest OS installation of Windows 7 works without any problem.


<yambe:breadcrumb>Xen</yambe:breadcrumb>