Κυριακή 26 Αυγούστου 2012

Trying an ubuntu-server installation under EFI/GPT using Qemu/KVM and OVMF

Recently a friend of mine was having issues installing latest Ubuntu LTS server edition on a (U)EFI/GPT-based server. So I thought, let's see if it is possible to try the installation under qemu, since I don't have any real (U)EFI hardware to test (donations welcome :P).

After a small amount of messing around I got it to work and I thought that it could be generally useful (e.g., as a first step for trying out Secure Boot technology), hence this blog post detailing my steps:

Step 1. Ingredients

  • A laptop with kubuntu 12.04 (amd64)
  • qemu-kvm 1.0
  • GNU parted
  • OVMF (I used OVMF-X64-r11337-alpha.zip binary)  (get it from sourceforge)
  • A livecd of ubuntu server 12.04 (ubuntu-12.04-server-amd64.iso)

Step 2. Preparation

First, let's make a virtual hard disk:
qemu-img create -f raw gpt.img 6G
and initialize GPT:
parted -s gpt.img mklabel gpt
Now, let's prepare OVMF:
mkdir OVMF
cd OVMF
unzip ../OVMF-X64-r11337-alpha.zip
mv OVMF.fd bios.bin
mv CirrusLogic5446.rom vgabios-cirrus.bin
cp /usr/share/qemu/{linuxboot.bin,multiboot.bin,vapic.bin} . 

Step 3. Installation

kvm -m 512 -L OVMF -vga cirrus \
  -cdrom ubuntu-12.04-server-amd64.iso \
  -hda gpt.img -boot d
We will have to wait for a while and eventually we should see the starting screen. We choose "Install Ubuntu server" and press 'e' to edit kernel command line (this is important!!). From there we need to add "pci=nocrs nomodeset" to the kernel command-line parameters. Press F10 to start the boot.

It will probably take a while until you see the installer, don't worry about this, it is normal with (U)EFI apparently ...

Then proceed to install as usual (For this experiment I just chose the defaults).

Step 4. The first boot 

Similarly, when we boot for first time we will have to go to grub boot screen and press 'e' so that we can add the 'pci=nocrs' and 'nomodeset' options once more.

After you login, remember to edit grub to make these settings permanent:
sudo sed 's/\(GRUB_CMDLINE_LINUX_DEFAULT="\)/\1pci=nocrs nomodeset/' \
 -i /etc/default/grub
sudo update-grub

Step 5. The second boot

Now you can shut down the VM and boot without the cdrom:
kvm -m 512 -L OVMF -vga cirrus -hda gpt.img -net nic -net user
If the system boots successfully, then you have succeeded this process and you may now enjoy your virtual EFI/GPT-based server :)