Creating a Windows XP image file for OpenNebula Rel 3.4, using Virtual-shell script in a Ubuntu 11.10 64 bit server

Creating a Windows XP image file for OpenNebula Rel 3.4, using Virtual-shell script in a Ubuntu 11.10 64 bit server

All,welcome to my blog

Let’s discuss on how to create a Windows XP image file for OpenNebula Rel 3.4, using Virtual-shellscript in a Ubuntu 11.10 64 bit server

Normally we use KVM to create image files as it is a command line process. Let’s see how we can create an image file using a small virtual-shell script.

The advantage of using a “virsh” script is it more manageable and easy to understand. Further kvm command line process requires frequent edits/changes while creating a Windows XP image. With virtual-shell scripts, at least we can minimize the number of changes.

Just have libvirt-bin , qemu-kvm and ubuntu-vm-builder installed to run the virtual shell script (or in libvirt language-to create a domain)

sudo apt-get install qemu-kvm libvirt-bin ubuntu-vm-builder

(install bridge-utils only if you need a network bridge)

Just edit /etc/libvirt/qemu.conf and uncomment the line having the text vnc_listen = “0.0.0.0”

Then restart libvirt

sudo service libvirt-bin restart

Let’s move to the process now,

Assume the Windows XP SP3 ISO file and the destination image file are stored in a folder /srv/cloud/one/images]

[Iam just using my OpenNebula images folder. You can have your own path.]

Create a 15 GB RAW image file using qemu-img-create command.

qemu-img create -f raw win-xp.img 15G

In a editor create a file named “deployment.1” and copy the following script in to it. Save the script in a folder. Mine is “/srv/cloud/one/var/images “

File : /srv/cloud/one/var/images/deployment.1

 domain type=’kvm’ xmlns:qemu=’http://libvirt.org/schemas/domain/qemu/1.0′&gt;<name>win-50</name><memory>1048576</memory><os><type arch=’i686′>hvm</type><boot dev=’hd’/><boot dev=’cdrom’/></os><on_reboot>restart</on_reboot><on_crash>restart</on_crash> <devices><emulator>/usr/bin/kvm</emulator><disk type=’file’ device=’disk’><source file=’/srv/cloud/one/images/win-xp.img’/><target dev=’hda’/><driver name=’qemu’ type=’raw’ cache=’default’/></disk> <disk type=’file’ device=’cdrom’><driver name=’qemu’ type=’raw’/><target dev=’hdc’ bus=’ide’/><readonly/><source file=’/srv/cloud/one/images/Win_XP_original.iso’/><address type=’drive’ controller=’0′ bus=’1′ unit=’0’/></disk> <controller type=’ide’ index=’0′><address type=’pci’ domain=’0x0000′ bus=’0x00′ slot=’0x01′ function=’0x1’/></controller> <!–use one network –><interface type=’network’><source network=’default’/></interface><graphics type=’vnc’ port=’5950’/</devices><features><acpi/></features></domain>

Let me not explain the script in detail now as content is self explanatory. I can explain it in detail, on request .

Providing the boot sequence “hd” first and “cdrom” next will help us to avoid one edit to the script.

<boot dev=’hd’/>

<boot dev=’cdrom’/>

(i.e)On first execution of the script , libvirt finds that “hd” is not bootable, and boots from “cdrom”

and on first reboot, the script automatically boots from the “hd”

To execute the script, on the unix shell prompt type virsh and press enter.

Once you get the “virsh #” prompt, type the below and press enter.>

create /srv/cloud/one/var/images/deployment.1

You will get an output stating -> “Domain Win-50 created from [path-of-file] “

Some possible failures while creating a domain through virtual shell:

  • Note: if you get an error:

Failed to create domain from /srv/cloud/one/var/images/deployment.1 err

  • Check if service libvirt-bin is running, else start it and try above command now. Else,
  • With “ifconfig” command check the existence of a bridge named virbr0 or virbr<n> {n will be 0 or a greater number} in VMHost.
  • If not,check if dnsmasq is running in that machine. If yes, stop it and remove dnsmasq from the machine (apt-get remove dnsmasq) restart.
  • >else reinstall libvirt-bin
  • You will be able to see the bridge virtual bridge now.

Another method:[I donot recommended]

  • check ifconfig for the virbr0 or anyother virtual bridge service.
  • If not available replace virbr%d with the active bridge in your network, in the “default” n/w definition file /etc/libvirt/qemu/networks/default.xml
  • restart libvirt service.
  • Note: if you get below error:

 
error: Failed to create domain from /srv/cloud/one/images/deployment_1

error: internal error process exited while connecting to monitor: kvm: -drive file=/srv/cloud/one/images/win- xp.img,if=none,id=drive-ide0-0-0,format=raw: could not open disk image /srv/cloud/one/images/win-xp.img: Permission denied

  • May be, due to access right issues: Just provide rwx access to the img file using chmod command. (chmod 677 <filename>
    On the virsh # prompt type “list” to check the status of the domain. It should be “running” to proceed further.. If the status is running. Note the “ID”

    On the virsh # prompt type vncdisplay <ID>
    You will get the VNC listening port number. Just note it.

    connect to windows installation screen using a VNC client and complete installing windows.

e.g vncviewer 192.168.2.2:50 [50 is the VNC listening port]
Note: You will have a funny time using the mouse in a QEMU window. Just enjoy it.

Just be patient. The partition formatting etc will be little slower through virsh.

In my next article, let’s discuss about how to change the script to use Intel e-1000 driver and how to use it in OpenNebula.

Advertisements