Kernel Virtual Machine Guest
Introduction
- Using Ubuntu Karmic Koala 9.10 as host.
- Using 32 bit kernel, so limiting guests to 32 bit kernels and 2GB ram.
- Will be using bridge support on host.
KVM Guest configuration
- The configuration of the guests are defined by xml files stored in /etc/libvirt/qemu/.
- The xml file is defined in detail here: http://libvirt.org/formatdomain.html
- The define or create commands imports the xml file into virsh.
- The xml files can be generated by virsh or ubuntu-vm-builder or edited manually.
Creating a guest with virt-install
Create a sparse disk image
- Create a disk image for the root install:
sudo qemu-img create -f qcow2 disk0.qcow2 10G
Running virt-install
- Run virt-install for ubuntu guest:
sudo virt-install --connect qemu:///system -n guestName -r 512 \ -f /vm/guestName/disk0.qcow2 -s 12 -c /vm/ubuntu-9.10-server-i386.iso \ --vnc --noautoconsole --os-type linux --accelerate --network=bridge:br0
- For OpenBSD guest:
sudo virt-install --connect qemu:///system -n guestName -r 512 \ -f /vm/guestName/disk0.qcow2 -s 12 -c /vm/install46.iso \ --vnc --noautoconsole --os-variant openbsd4 --accelerate --network=bridge:br0
Connecting over VNC
- Check the vnc port in virsh:
sudo virsh vncdisplay guestName
- The output will be the vnc port number to connect to on the host server.
- Use ssh to tunnel into the server and make the vnc port available locally.
- If the output from vncdisplay was :0:
ssh -L 5910:127.0.0.1:5900 hostName
- If the output from vncdisplay was :4:
ssh -L 5910:127.0.0.1:5904 hostName
- Use Chicken of the VNC on OS X or RealVNV VNC Viewer Free Edition on Windows.
| Use port 5910 is used to avoid collision with Screen Sharing on OS X. If not using OS X (or not running a local VNC server), port 5900 is safe to use. |
| If using Chicken of the VNC, don't specify the full port only the display.
Eg If the port is 5900, the display is 0. |
- Once connected over vnc, install as normal.
| Occasionally the Ubuntu install would hang on the at about 43% Scanning disks... partitioning screen and reboot was required.
No clear reason why this was happening and it was happening inconsistently. |
- Reference:
https://help.ubuntu.com/community/KVM/CreateGuests
http://scie.nti.st/2009/10/4/running-openbsd-4-5-in-kvm-on-ubuntu-linux-9-04
Updates to virsh xml
- These should not be necessary, but can be useful if cloning guests.
- Change interface to:
<interface type='bridge'> <mac address='52:54:54:bb:f9:14'/> <source bridge='br0'/> </interface>
- To generate a new mac address:
$ MACADDR="52:54:$(dd if=/dev/urandom count=1 2>/dev/null | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\).*$/\1:\2:\3:\4/')"; echo $MACADDR 52:54:54:bb:f9:14 $
- To generate a new UUID number:
$ uuidgen 41B72951-AA21-4BF2-BAF8-D0D7E70D5344 $
- Remove any graphics reference
<graphics type='vnc' port='-1' listen='127.0.0.1'/>
- Remove any input mouse references:
<input type='mouse' bus='ps2'/>
- Add device:
<serial type='pty'> <target port='0'/> </serial> <console type='pty'> <target port='0'/> </console>
Finish Ubuntu guest install
- To have ubuntu guest respond to the shutdown command, install apcid:
sudo apt-get install acpid
- Run updates, upgrade and dist-upgrade:
sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade
- Setup static ip address, instructions.
- Install the grub serial and console code.
Grub 2 - setting up serial console
- The following is the complete replacement for the grub file.
- On guest run:
sudo cp /etc/default/grub $HOME/grub.bak sudo vi /etc/default/grub
# If you change this file, run 'update-grub' afterwards to update # /boot/grub/grub.cfg. GRUB_DEFAULT=0 # EDITED: #GRUB_HIDDEN_TIMEOUT=0 #GRUB_HIDDEN_TIMEOUT_QUIET=true # ADDED: GRUB_HIDDEN_TIMEOUT_QUIET=false GRUB_TIMEOUT="10" GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian` #GRUB_CMDLINE_LINUX_DEFAULT="quiet splash" # ADDED: GRUB_CMDLINE_LINUX_DEFAULT="console=tty0 console=ttyS0,115200n8" GRUB_CMDLINE_LINUX="" # Uncomment to disable graphical terminal (grub-pc only) #GRUB_TERMINAL=console # ADDED: GRUB_TERMINAL=serial GRUB_SERIAL_COMMAND="serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1" # The resolution used on graphical terminal # note that you can use only modes which your graphic card supports via VBE # you can see them in real GRUB with the command `vbeinfo' #GRUB_GFXMODE=640x480 # Uncomment if you don't want GRUB to pass "root=UUID=xxx" parameter to Linux #GRUB_DISABLE_LINUX_UUID=true # Uncomment to disable generation of recovery mode menu entrys #GRUB_DISABLE_LINUX_RECOVERY="true"
- Update grub with the new settings:
sudo update-grub
- Ubuntu already has ttyS0 in /etc/securetty.
- Setup ttyS0 to start:
sudo cp /etc/init/tty1.conf /etc/init/ttyS0.conf sudo vi /etc/init/ttyS0.conf
- Content should be:
# ttyS0 - getty # ... exec /sbin/getty -L 115200 ttyS0 vt102
- Reference:
http://linux.xvx.cz/188/debian-with-grub2-and-serial-connection/
https://wiki.ubuntu.com/Grub2
http://ubuntuforums.org/showthread.php?t=1341462
Finish OpenBSD guest install
Disable mpbios
First boot
- After installation, reboot the guest vm and quickly reconnect the vnc client.
- At the boot> prompt type:
boot> bsd -c ... UKC> disable mpbios 54 mpbios0 disabled UKC> quit ...
- If the guest vm has already started to boot it will hand and you will have to use virsh to destroy the vm.
Configure kernel
- The change made during boot will no persist, editing the kernel config is required.
- Login as root and type:
# config -ef /bsd ... ukc> disable mpbios ... ukc> quit
Networking
- There are recommendations to change the network card type to e1000 to avoid hang ups and performance problems.
- Using --os-variant openbsd4 in the virt-install resulted in the following config:
<interface type='bridge'> <mac address='54:52:00:5b:1d:6d'/> <source bridge='br0'/> <model type='pcnet'/> </interface>
- The code was updated to:
<interface type='bridge'> <mac address='54:52:00:5b:1d:6d'/> <source bridge='br0'/> <!--model type='pcnet'/--> <model type='e1000'/> </interface>