Author Archive

If you have a triple boot mac mini with OS X, Windows and Linux it might be useful to run OS X inside VirtualBox when Linux or Windows is running.

VirtualBox officially supports OS X Server as guest vm and runs as well other OS X versions as guest. – If Linux runs on a second (external) hard disk the first harddisk can be assigned to a virtualbox vm as raw device. And OS X should boot as guest (of type OS X server). However booting a vm with EFI instead of BIOS is still work in progress. With virtualbox 3.2.12:

  • limited screen resolutions
    (VBoxManage setextradata "VM name" VBoxInternal2/EfiGopMode N, N=0,1,2...4)
  • only first ide hard disk is bootable
  • overrides installed boot manager, e.g. rEFIt; and settings done by OS X start volume utility are completely ignored (missing virtualized hardware)
  • sometimes crashes in libata (ide disk access); maybe not related to efi boot

EFI boot can be disabled in system settings of the guest vm. But then you need a BIOS bootloader for the OS X kernel like Chameleon which seems to be a very active project.

  • chameleon could be installed to the disk containing OS X – but I prefer an unmodified disk
  • so chameleon should boot from cdrom

There are many cdrom iso images with chameleon online, but none met my needs:

  • boot leopard and snow leopard
  • boot from apple hardware but inside virtualbox
  • do not use hackintosh kext patches, except disabling native apple power management with Disabler.kext (else the guest uses 100% cpu)
  • screen resolution of guest vm be be selected in boot menu

The chameleon boot loader (2.0 RC4 r684) has lots of usage setups. But many of them are only documented by their source code.

  • the stage 2 loader of chameleon, boot, is in multiboot format
  • it can be chain loaded by syslinux mboot.c32
  • mboot.c in chameleon source reveals 3 command line arguments:
    biosdev=80 (or 81 for second hard disk, …)
    partno=2 (for second partition)
    timeout=5 (autostart after 5 seconds)
  • multi boot “kernels” may have “modules” (=initial ramdisk in case of linux kernel); chameleon uses a dmg image whith boot parameters and kext kernel modules
    – dmg format: compressed, with mbr partition, hfs+ filesystem in partition 1
    – /Extra/com.apple.Boot.plist defines boot parameters
    – /Extra/Extensions/ contains kext modules
  • isolinux.cfg example:
    kernel /mboot.c32
    append biosdev=80 timeout=1 partno=2 /boot --- /p800x600.dmg
  • com.apple.Boot.plist entry for Display resolution
    <key>Graphics Mode</key>
    <string>1280x1024x32</string>
  • com.apple.Boot.plist entry for verbose mode
    <key>Kernel Flags</key>
    <string>-v</string>
  • the dmg image can be opened inside OS X

Based on this information osxboot.iso is a bootable cdrom image with

  • boot menu (syslinux based) to choose between
    800×600, 1024×768, 1280×1024
    and, if set as custom resoltions in virtualbox guest vm,
    1400×1050, 1440×900, 1920×1050, 1920×1200
    (VBoxManage setextradata "vmname" CustomVideoMode1 1920x1200x32)
  • boot menu to select silent or verbose boot
    (chameleon allows to add other flags)
  • default boot from second partition of first hard disk
    (which can be edited during boot)
  • OS X 10.5, leopard, or OS X 10.6, snow leopard, on apple hardware, running as virtualbox guest:
    – only kext module Disabler.kext (part of chameleon distribution) is loaded (allows cpu sleep mode for vm guest)
    – leopard runs only inside a 64 bit version of virtualbox (tested with linux)
  • EFI has to be disabled in the system properties of the virtualbox guest
  • Seems to run stable if the hard disk inside the vm is attached to the virtual SATA hard disk controller
    (to access raw devices Use Host I/O Cache must be enabled for the SATA controller!)

The chameleon boot loader has been patched to set display resolution and verbosity as multiboot arguments:

  • resx=800 (defines horizontal resolution)
  • resy=600 (defines vertical resolution)
  • verbosity=0 / verbosity=1 (sets verbosity: -v flag)

Google, howto isolinux, should give answers how a bootable isolinux cdrom image can be created.

Known bug: “About this Mac” system information crashes.

Software used for this article: SPBLinux 2.4 live cd

In case you want to access usb attached storage media from a virtual machine (vm) running inside virtualbox there are 3 choices:

  1. Make the usb connection available to the vm.
  2. Make a shared folder to access data on the usb storage device.
  3. Give the vm direct access to the usb disk.

Using a shared folder has the advantage that configuration is straight forward (menu Device/Shared folder …). But

  • the host must handle the filesystem used on the usb storage device
  • the guest must have guest additions installed
  • performance is a bottleneck

Usb inside guest also has performance drawbacks.

So it is worth to fiddle with the command line to get direct access to disk partitions.

  • ls /dev/disk*
  • this displays all disk partions seen by OSX
  • in case finder displays the partition to be used by the vm (that is, OSX has automatically mounted this partition) you have to deactivate this partition with the OSX disk utility program
  • VBoxManage internalcommands createrawvmdk -filename yourpath/newdisk1.vmdk -rawdisk /dev/disk1
  • this creates a vmdk file which can be opened by virtualbox disk manager; this file gives access to disk1
    Use host I/o-Cache has to be enabled for the controller of this disk!

If the vm cannot be started because of disk access error the partitions of disk1 have to be deactivated again with the hard disk utility program.

The system disk /dev/disk0 would need root access rights; other disks can be accessed as user.

Time to put things together. Xen orchestra has now got a ‘vnc‘ link (like http://localhost/xo/htdocs/vnc.php?url=127.0.0.1:5901&name=w7b) which opens gtk vnc plugin (amd64 binary here). – This link is placed in section Misc of xen orchestra’s virtual machine detail window.

The configuration file of xen orchestra, xen-orchestra.conf, has got a section to control gtk vnc plugin. If a windows vm needs mouse grabbing, it can be set in this file. The handling of these settings is done in htdocs/vnc.php. If virtual machine w7b needs even more specific settings an additional file vnc_w7b.php can be used.

Compared to the description in this post vnc gtk plugin does now automatically grab the focus (keyboard immediately active after loading of html page; no need to click into vnc viewer window first) and a send keys menu has been added (0103-add_autofocus_and_sendkeys.diff).

(Build instructions remain the same except that after (updated) colortoolbar.patch.gz a second patch colortoolbar2.patch.gz has to be applied; updated amd64 debian archive: mozilla-gtk-vnc_0.3.10-6_amd64.deb).

There is one little additional patch to xen orchestra (03-add_vm_name_to_vnc_link.diff). The main changes are in vnc.php (compare previous post about xen orchestra). An updated zip archive with patched xen orchestra is here.

Xen virtual machines transmit their screen contents by vnc. A browser based viewer is the java vnc viewer plugin (see previous post). Advantage of java is that it runs on many platforms. However java tends to use a lot of RAM. On ubuntu 10.04 there is an alternative browser plugin which is gtk based: gtk viewer plugin.

The gtk vnc plugin offers only very basic functions: just an authentication dialog and the vnc viewer window. – This post adds a minimalistic toolbar to the plugin (test.html, gtk-vnc-plugin.so, libgtk-vnc-1.0.so.0.0.1).

Steps to build the plugin described above:

Looking for a graphical, browser based tool to manage xen 4.0 virtual machines I tried xen orchestra):

  • pro: needs only a web server with php (mysql optional); user interface not overloaded;  open source, well structured code.
  • con: only one detail window can be opened at the same time – needs patch; needs on ubuntu 10.04 a workaround for command xm new (see previous post).

The patch for multiple detail windows just had to replace some html tag id fields in htdocs/scripts/xo.js (01-xo.js.wId.diff).

Because I found it convenient to inspect my virtual machines with a browser based vnc viewer, I added a line to the detail window which displays the id and a link to vnc:
Domain id: 1 (vnc)
This patch uses the xen api to query the consoles of the virtual machine and looks up the ip address and the port of the vnc server connected to the console (02-add_vnc_link.diff, to be applied after 01-xo.js.wId.diff).

Patched version of xen orchestra: xen-orchestra-2010-03-22-patched.zip (local version of original file: xen-orchestra-2010-03-22.zip; local version of tightvnc java viewer: VncViewer.jar)

Minor, negligible bugs:

  • Network and Storage section of detail windows are empty.
  • If the machine running xen orchestra is too busy, xen orchestra displays an empty window; just press the refresh button of the browser to get the main window back.
  • ‘Login again’ button of java vnc viewer window does not reconnect (but refresh button of browser does).
  • Error messages are not displayed if a virtual machine fails to start (open a terminal and use the command xm start yourvm).
  • the vnc viewer window has a fixed hardcoded size (800×600 in htdocs/vnv.php); as workaround add &w=1024&h=798 to the browser address line to display a 1024×768 virtual machine.
  • non captured mouse does not work well in windows, unless graphics tablet mouse driver is installed (see next post about gtk-viewer plugin on linux).

Conclusion: I really appreciate the work of Olivier Lambert, the author of xen orchestra!

Virtual machines of xen can be created with xen-builtin command xm create which uses a config file in /etc/xen. There is a second command to create xen virtual machines: xm new

Virtual machines created with xm new are permanently added to xen (virtual machines created with xm create get removed from xen when the virtual machine is shut down). – Some xen monitoring tools, like xen orchestra, rely on permanently added virtual machines.

But xm new is broken in debian (and ubuntu) because xm uses an outdated xml python library. And the corresponding debian  bug report is closed with status ‘won’t fix’. Debian maintainers support  only xen create.

Using virsh as workaround for xen new:

  • xm create myvm (from file /etc/xen/myvm)
  • virsh dumpxml myvm > /etc/xen/myvm.xml
  • xm shutdown myvm
  • virsh define /etc/xen/myvm.xml

Debian sid has the source package of libvirt (currently 0.8.1-1), but package 0.8.1-1 does not work with xen 4.0.  However the build service of opensuse factory includes as well libvirt-0.8.1 and they have xen 4.0 patches included.

To get a libvirt package for ubuntu 10.04 which is compatible with xen 4.0 the patches of opensuse had to be combined with the debian sid package (patch: debian.diff; local copy of debian sources: libvirt_0.8.1.orig.tar.gz, libvirt_0.8.1-1.debian.tar.gz, libvirt_0.8.1-1.dsc).

Build process:

  • download sources and patch into new directory and open terminal in this directory
  • tar -xzf libvirt_0.8.1.orig.tar.gz
  • cd libvirt-0.8.1
  • tar -xzf ../libvirt_0.8.1-1.debian.tar.gz
  • patch -p0 < ../debian.diff
  • ./debian/rules binary

And to install the new packages (ubuntu amd64 packages: libvirt-bin_0.8.1-1_amd64.deb, libvirt0_0.8.1-1_amd64.deb, libvirt-dev_0.8.1-1_amd64.deb, libvirt-doc_0.8.1-1_amd64.deb, python-libvirt_0.8.1-1_amd64.deb, libvirt0-dbg_0.8.1-1_amd64.deb):

  • cd ..
  • dpkg -i libvirt0_0.8.1-1_amd64.deb libvirt-bin_0.8.1-1_amd64.deb python-libvirt_0.8.1-1_amd64.deb

The resulting virsh command seems to work with xen 4.0 (tested with subcommands dumpxml and define). – You should use Package/Force version in synaptic package manager to protect these manually installed packages.

  • Adding and removing of hard disks  and cdrom devices works fine
    (guest not running)
  • Acronis Trueimage works well inside hvm virtual machines
    (if empty block devices are not recognized as hard disks, e.g. /dev/sdb7:
    dd if=/dev/zero of=/dev/sdb7 bs=1M count=100
    echo ‘w’ |fdisk /dev/sdb7
    This zeros out the beginning of block device /dev/sdb7 and writes a new partition table into /dev/sdb7; all existing data in /dev/sdb7 is overwritten – you have been warned.)
  • Sometimes the window opened by virt-manager fails to display a running virtual machine (does not connect by vnc to the running vm).
    Closing both windows (that of the vm and virt-manager itself) and reopening them usually helps (the vm continues to run).

Found in xen wiki a remark of Jeremy Fitzhardinge about the performance of Xen 4.0 (Xen Summit at Intel Shanghai Nov 19-20, 2009, Slide 7):

Performance still needs attention

  • Seems to be ~10-20% hit vs 2.6.18-xen

… but you get a current 2.6.31/32/… Linux kernel.

Preparations to boot a Xen 4.0 dom0  kernel: 2.6.18-to-2.6.31-and-higher

Status of Xen features in Linux kernel: XenParavirtOps

Thanks to the detailed posts on http://bderzhavets.wordpress.com/ [A, B, C ] virt-manager is running xen 4.0 on ubuntu 10.04
(installation of ubuntu server plus apt-get install xubuntu-desktop).

Program virt-manager has to be started as root and switching with su to root shell does not work, the login version su – has to be used (to avoid error: Failed to contact configuration server).

To create a hvm virtual machine virt-install is used:

  • virt-install -connect xen:/// -n ti2010 –r 512 –hvm –vnc -f /dev/sdb -c /root/mnt/ti2010.iso –debug –force

Parameter –force is only neccessary if the block device used as hard disk is already part of another vm.

Once the new vm gets displayed in virt-manager all properties of this vm can be edited (click ‘Open’; ‘Add Hardware’, ‘Remove’, …).