Installing Xen on an Apple iMac

3 minute read



This is a guest post by my colleague Antonio Cunei, who battled an iMac long enough to manage installing Xen (and Ubuntu as Dom0) on top of it. Kudos to him !

If you install Ubuntu on an iMac, it will install it by default in EFI mode.

On some machines — for instance on a Macbook Air—, it will also tweak the EFI firmware in order to boot through EFI-grub. However, on the iMac, you need to boot into OSX, usually from an external USB key (e.g. by installing OSX on said USB — a shortcut would also be to boot from Apple installation media).

Then, you should got to the terminal and bless the grub EFI file.

Blessing an EFI file

Generic Macs :

You can use the bless command from within Mac OS X to set grubx64.efi as the default boot option. You can also boot from the Mac OS X install disc and launch a Terminal there if you only have Linux installed. In the Terminal, create a directory and mount the EFI System Partition:

# cd /Volumes
# mkdir efi
# mount -t msdos /dev/disk0s1 /Volumes/efi

Then run bless on grub.efi and on the EFI partition to set them as the default boot options.

# bless --folder=/Volumes/efi --file=/Volumes/efi/efi/arch_grub/grubx64.efi --setBoot
# bless --mount=/Volumes/efi --file=/Volumes/efi/efi/arch_grub/grubx64.efi --setBoot

Do not try to use bless --info. It’s broken and may corrupt the disk, reportedly. Also, you may have to reboot resetting the PRAM multiple times (switch it on while pressing ⌘-Option-P-R until it chimes and reboots), otherwise the security “features” will ignore attempts to overwrite the firmware info using bless.

Here you can find a version of the Xen.efi file, for version 4.4.x.

You can use just xen.efi, and install the rest in Ubuntu, installing the regular xen-hypervisor-xxx package, as per the manual pages.

In xen.cfg, you can put something like:


options=console=vga,com1 com1=115200 loglvl=all noreboot
kernel=vmlinuz-3.14-2-amd64 ignore_loglevel  root=/dev/mappe/clava-root ro quiet #earlyprintk=xen



options=console=vga loglvl=all noreboot
kernel=vmlinuz-3.16.0-24-generic root=/dev/sda2 rw ignore_loglevel     ramdisk=initrd.img-3.16.0-24-generic

depending on your exact target kernel and dsired options.

Here’s how to do chainloading, in case you want to go through grub:

menuentry "Xen EFI" {
    insmod part_gpt
    insmod search_fs_uuid
    insmod chain
    chainloader (hd0,gpt1)/EFI/XEN/xen.efi

Grub Woes and more details on the above

Grub, in EFI Mode, in the default installation of Xen provided by Ubuntu, will not load Xen properly.

The standard Ubuntu Xen package is designed for BIOS boot. In order to boot Xen in EFI mode, there are two ways. In both cases, you need a Xen.EFI file, which is not provided by Ubuntu. So you can either compile it from source, or find it on the Internet (see above).

The Xen.efi needs to be aligned with the version of Xen installed from the Ubuntu package.

This Xen.efi needs to be placed in the EFI boot partition (usually /boot/EFI/EFI/ubuntu/xen.efi).

You can boot xen.efi by either blessing from OSX that specific file, or using a feature of grub called chain-loader. Chain-loading is the only way to boot on Ubuntu without Xen.

Together with xen.efi, you need to place a xen.cfg file in the EFI boot partition. In there, you need to specify the root as a kernel parameter, and the ramdisk location.

The trick is : the Xen loader (xen.efi) is unable to look into a different partition, so that if you have your EFI partition mounted at /boot/EFI, the kernel is unreachable. Hence you need to mount it at /boot.

Last detail

Since the Xen loader does not boot anything but what it can find on its own partition, you also need to copy the kernel image there !