Wednesday, August 14, 2013

Dual boot Debian 7 Wheezy on existing Win8 UEFI machine

I don't want to bother giving a lengthy background or info... So I'll just try to make this post a short mash up of what you need to know.

Prelude: Dual-booting a laptop/machine wherein there is an existing Windows 8 installed in a UEFI boot-up environment

First off, you'll probably need to do some shrinking of existing partitions. In my case, I just shrank my Windows8 drive C: using the disk manager build-in under the "Computer Management".

Afterwards, you'll need to use a UEFI-bootable linux image. For me, I used a PXE bootable Debian 7 Wheezy-stable image and created a root, swap, and home partition from the unused space. Do take note that you need to use the new GPT partitioning (for those with fresh hard drives); this option is usually asked or selected when using the "advanced mode" when installing.

Now here is the tricky part... after you proceed to install GRUB, that grub instance will not work later after finishing the installation. You will need to use an external USB linux image or disk that can boot as UEFI. This is not necessarily need to be a Debian USB image as I used a Kubuntu 13.04 image and placed it in a USB stick.

Use the USB stick to boot the machine up and use its GRUB rescue to manually boot the already installed Debian. For those a bit lost on using the GRUB rescue command line, below are the lines I used.

set prefix="(hdX,gptX)/boot/grub"
set root="(hdX,gptX)"
insmod normal

Note that the prefix is just to denote the location of the grub installation folder, so the value might change depending on your partition layout. On the example I gave, I only have a root partition so I had to specify the "boot" folder. If your case is that you created a separate "/boot" partition, the prefix would probably look like...

set prefix="(hdX,gptX)/grub"

Once you have managed to boot-up to your installed Debian partition, log-in to your root (or use sudo if that's your preference) and install the following packages:

# apt-get install grub-efi-amd64 efibootmgr

We then have to mount temporarily the partition containing the already existing EFI loader of Windows. This is usually around 250-300MB in partition size and contains files and folders with names like "Boot" and "EFI". I'll leave it up to you which or what partition number that may be.

# mkdir /boot/efi
# mount /dev/sdaX /boot/efi

Next is loading the driver/module for the EFI support, which will then aid with the re-install and detection of GRUB of the existing EFI Windows 8 partition and creating a Debian EFI entry.

# modprobe efivars
# grub-install /dev/sda
# update-grub

Kindly check if there is a new EFI entry present on the output displayed upon executing the "update-grub". Also, check inside /boot/efi if there is a new folder or entry that matches in terms of the name of the EFI entry listed a while back.

If all goes well, you will see a new UEFI boot priority inside your BIOS apart from the UEFI Windows Boot Manager.

Hope this helps!

Other resources that you might find useful: