Install Windows Xp Upon Kvm

Windows XP를 kvm 위에 설치하는 과정의 기록

Windows Desktop on kvm

Setup WindowsXP SP2 VM

Configuration

first, create and register configuration:

sio4@jangseung:/box/vms$ ./create-vm.sh
name of vm: xpsp2_t
size of ram: 640
number of cpus: 2
path of cdrom: /box/isos/winxp-skcc.iso
disk size of sys: 10
disk size of opt: 5
Formatting '/box/vms/xpsp2_t/xpsp2_t-sys.img', fmt=raw, size=10485760 kB
Formatting '/box/vms/xpsp2_t/xpsp2_t-opt.img', fmt=raw, size=5242880 kB
Connecting to uri: qemu:///system
Domain xpsp2_t defined from /box/vms/xpsp2_t/xpsp2_t.xml

sio4@jangseung:/box/vms$

"create-vm.sh" is in-house script for simplify initial processes of vm creation.

#!/bin/sh
 
VM_ROOT=/box/vms
 
vn_net="nat-1"
vn_mod="virtio"
 
vm_name=mercury
vm_mem=1024
vm_cpus=2
vm_mac=`echo "52:54:00$(hexdump -e '/1 ":%02x"' -n 3 /dev/urandom)"`
 
echo -n "name of vm: "; read vm_name
vm_home=$VM_ROOT/$vm_name
 
echo -n "size of ram: "; read vm_mem
echo -n "number of cpus: "; read vm_cpus
echo -n "path of cdrom: "; read vm_cdrom
echo -n "disk size of sys: "; read size_sys
echo -n "disk size of opt: "; read size_opt
 
mkdir -p $vm_home
qemu-img create $vm_home/$vm_name-sys.img -f raw ${size_sys}G
qemu-img create $vm_home/$vm_name-opt.img -f raw ${size_opt}G
 
cat > $vm_home/$vm_name.xml <<EOF
<domain type='kvm'>
  <name>$vm_name</name>
  <uuid>$vm_uuid</uuid>
  <memory>$(( $vm_mem * 1024 ))</memory>
  <currentMemory>$(( $vm_mem * 1024 ))</currentMemory>
  <vcpu>$vm_cpus</vcpu>
  <os>
    <type>hvm</type>
    <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <source file='$vm_home/$vm_name-sys.img'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <disk type='file' device='disk'>
      <source file='$vm_home/$vm_name-opt.img'/>
      <target dev='hdb' bus='ide'/>
    </disk>
    <disk type='file' device='cdrom'>
      <target dev='hdc' bus='ide'/>
      <source file='$vm_cdrom'/>
      <readonly/>
    </disk>
    <interface type='network'>
      <mac address='$vm_mac'/>
      <source network='$vn_net'/>
      <model type='$vn_mod'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
  </devices>
</domain>
EOF
 
virsh define $vm_home/$vm_name.xml

generated files are:

sio4@jangseung:/box/vms$ ls xpsp2_t
xpsp2_t-opt.img  xpsp2_t-sys.img  xpsp2_t.xml
sio4@jangseung:/box/vms$ du -sh xpsp2_t/*
0    xpsp2_t/xpsp2_t-opt.img
0    xpsp2_t/xpsp2_t-sys.img
4.0K    xpsp2_t/xpsp2_t.xml
sio4@jangseung:/box/vms$ qemu-img info xpsp2_t/xpsp2_t-sys.img 
image: xpsp2_t/xpsp2_t-sys.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 0
sio4@jangseung:/box/vms$

and

<domain type='kvm'>
  <name>xpsp2_t</name>
  <uuid></uuid>
  <memory>655360</memory>
  <currentMemory>655360</currentMemory>
  <vcpu>2</vcpu>
  <os>
    <type>hvm</type>
    <boot dev='cdrom'/>
  </os>
  <features>
    <acpi/>
  </features>
  <clock offset='utc'/>
  <on_poweroff>destroy</on_poweroff>
  <on_reboot>restart</on_reboot>
  <on_crash>destroy</on_crash>
  <devices>
    <emulator>/usr/bin/kvm</emulator>
    <disk type='file' device='disk'>
      <source file='/box/vms/xpsp2_t/xpsp2_t-sys.img'/>
      <target dev='hda' bus='ide'/>
    </disk>
    <disk type='file' device='disk'>
      <source file='/box/vms/xpsp2_t/xpsp2_t-opt.img'/>
      <target dev='hdb' bus='ide'/>
    </disk>
    <disk type='file' device='cdrom'>
      <target dev='hdc' bus='ide'/>
      <source file='/box/isos/winxp-skcc.iso'/>
      <readonly/>
    </disk>
    <interface type='network'>
      <mac address='52:54:00:cc:b6:8b'/>
      <source network='nat-1'/>
      <model type='virtio'/>
    </interface>
    <serial type='pty'>
      <target port='0'/>
    </serial>
    <console type='pty'>
      <target port='0'/>
    </console>
    <input type='mouse' bus='ps2'/>
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
  </devices>
</domain>

Installation

ok, general installation process in brief is:

$ virt-viewer -c qemu:///system xpsp2_t --wait &
$ virsh start xpsp2_t
... (do OS specific install process, and finally reboot. maybe fall into CD boot again, so...)
$ virsh destroy xpsp2_t
$ sed -i "s/dev='cdrom/dev='hd/" xpsp2_t/xpsp2_t.xml
$ virsh define xpsp2_t/xpsp2_t.xml 
$ virt-viewer -c qemu:///system xpsp2_t --wait &
$ virsh start xpsp2_t

when install Windows XP, step 1 of above process failed for unknown reason. (or step 2 cannot be proceeded.) so we need a work-around like this:

sudo kvm -m 640 -hda xpsp2_t/xpsp2_t-sys.img -cdrom /box/isos/winxp-skcc.iso -boot d

If we call kvm binary directly instead of calling virsh or something, It can be done without problem. what is the key? some problem with xml? multiple disks? smp? acpi? usb? networking? or other kvm parameters?
we need more test but not now.

finally we got this:

sio4@jangseung:/box/vms$ ls -lh xpsp2_t/*
-rw-r--r-- 1 sio4 sio4 5.0G 2009-09-20 00:34 xpsp2_t/xpsp2_t-opt.img
-rw-r--r-- 1 sio4 sio4 8.0G 2009-09-22 13:19 xpsp2_t/xpsp2_t-sys.img
-rw-r--r-- 1 sio4 sio4 1.3K 2009-09-20 00:34 xpsp2_t/xpsp2_t.xml
sio4@jangseung:/box/vms$ du -sh xpsp2_t/*
0    xpsp2_t/xpsp2_t-opt.img
1.4G    xpsp2_t/xpsp2_t-sys.img
4.0K    xpsp2_t/xpsp2_t.xml
sio4@jangseung:/box/vms$ file xpsp2_t/*
xpsp2_t/xpsp2_t-opt.img: data
xpsp2_t/xpsp2_t-sys.img: x86 boot sector, Microsoft Windows XP MBR, Serial 0x36563656; partition 1: ID=0x7, active, starthead 1, startsector 63, 16755732 sectors
xpsp2_t/xpsp2_t.xml:     ASCII text
sio4@jangseung:/box/vms$ qemu-img info xpsp2_t/xpsp2_t-sys.img 
image: xpsp2_t/xpsp2_t-sys.img
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: 1.3G
sio4@jangseung:/box/vms$

ok, backup here!

sio4@jangseung:/box/vms$ tar -z -c -v -S -f xpsp2_t-installed.tar.gz xpsp2_t
xpsp2_t/
xpsp2_t/xpsp2_t.xml
xpsp2_t/xpsp2_t-sys.img
xpsp2_t/xpsp2_t-opt.img
sio4@jangseung:/box/vms$ ls -lh *.tar.gz
-rw-r--r-- 1 sio4 sio4 732M 2009-09-22 13:22 xpsp2_t-installed.tar.gz
sio4@jangseung:/box/vms$

oops! I miss something important! I need install paravirtual network driver for windows guest.
see following steps:

sio4@jangseung:/box/vms$ sed -i "s/dev='cdrom/dev='hd/" xpsp2_t/xpsp2_t.xml 
sio4@jangseung:/box/vms$ sed -i "s,file=.*\.iso,file='/box/isos/NETKVM-20081229.iso," xpsp2_t/xpsp2_t.xml
sio4@jangseung:/box/vms$ virsh define xpsp2_t/xpsp2_t.xml
Connecting to uri: qemu:///system
Domain xpsp2_t defined from xpsp2_t/xpsp2_t.xml

sio4@jangseung:/box/vms$ virt-viewer -c qemu:///system xpsp2_t --wait &
[1] 21795
sio4@jangseung:/box/vms$ virsh start xpsp2_t
Connecting to uri: qemu:///system
Domain xpsp2_t started

sio4@jangseung:/box/vms$

more details are:

we can cloning it and use here, but most use cases of windows xp is for documentation tasks. so we now install MS Office on template it self.

Cloning

rename it:

sio4@jangseung:/box/vms$ virsh undefine xpsp2_t
Connecting to uri: qemu:///system
Domain xpsp2_t has been undefined

sio4@jangseung:/box/vms$ mv xpsp2_t xpsp2o12_t
sio4@jangseung:/box/vms$ cd xpsp2o12_t/
sio4@jangseung:/box/vms/xpsp2o12_t$ rename "s/xpsp2/xpsp2o12/" *
sio4@jangseung:/box/vms/xpsp2o12_t$ sed -i "s/xpsp2_/xpsp2o12_/g" xpsp2o12_t.xml
sio4@jangseung:/box/vms/xpsp2o12_t$ sed -i "s,file=.*\.iso,file='/box/isos/win-office-skcc.iso," xpsp2o12_t.xml 
sio4@jangseung:/box/vms/xpsp2o12_t$ virsh define xpsp2o12_t.xml 
Connecting to uri: qemu:///system
Domain xpsp2o12_t defined from xpsp2o12_t.xml

sio4@jangseung:/box/vms/xpsp2o12_t$

then,

sio4@jangseung:/box/vms$ virt-viewer -c qemu:///system xpsp2o12_t --wait &
[1] 26689
sio4@jangseung:/box/vms$ virsh start xpsp2o12_t
Connecting to uri: qemu:///system
Domain xpsp2o12_t started

sio4@jangseung:/box/vms$

finally, backup again (xpsp2o12_t-install.tar.gz) and,

sio4@jangseung:/box/vms$ virsh undefine xpsp2o12_t
Connecting to uri: qemu:///system
Domain xpsp2o12_t has been undefined

sio4@jangseung:/box/vms$ mv xpsp2o12_t xpsp2o12-work
sio4@jangseung:/box/vms$ cd xpsp2o12-work/
sio4@jangseung:/box/vms/xpsp2o12-work$ rename "s/xpsp2o12_t/xpsp2o12-work/" *
sio4@jangseung:/box/vms/xpsp2o12-work$ sed -i "s/xpsp2o12_t/xpsp2o12-work/g" xpsp2o12-work.xml 
sio4@jangseung:/box/vms/xpsp2o12-work$ virsh define xpsp2o12-work.xml 
Connecting to uri: qemu:///system
Domain xpsp2o12-work defined from xpsp2o12-work.xml

sio4@jangseung:/box/vms/xpsp2o12-work$
따로 명시하지 않는 한에서 이 사이트의 모든 콘텐츠는 다음의 라이선스를 따릅니다: Creative Commons Attribution-NonCommercial 3.0 License