Dual boot Win8 and Linux on Sony Vaio Pro

Let me start by saying that this was nothing short of epic. I am a total Linux newbie, so things were probably harder than they should have been. Anyhow, I am happy to report that it is possible, if a little tedious and fiddly.

There are a few resources out there already, I don’t claim any first dibs here. The onet that helped me the most was here: [http://www.slideshare.net/Tinydile/vaio-pro13-win8ubuntu1310uefi]. This blog post is my personal journey… so that I will know what to do next time.

Step 1: Bios settings
———————
You have to turn secure boot off, and preferably leave UEFI on.
Step 2: Live CD
—————
Boot the Live CD of your choice (I got Ubuntu working, but tried mint and Elementary to no avail). In order to boot with UEFI on, the flavour you opt for needs to have a signed EFI or something. They did that in Ubuntu so it works. It’s not strictly required though as I learned later, but it does make things somewhat easier.

Select to test the OS, and manually launch the installer and pass a parameter to avoid installing a boot loader. Ubiquity has a –no-bootloader flag. We don’t need a bootloader to start with, we’re going to use rEFInd.

Step 3:
——-
Once the install is complete, remain in the OS to “keep testing”. Now, the fun begins.

* The Vaio has a bunch of preinstalled partitions. /dev/sda3 is where the EFI bootloader is. What we need to do is add the required EFI bits to that partition so that the bootloader is aware of and can boot into Linux.

1 – mount the partition you installed to:
mount /dev/sda8 /mnt
sda8 in my case, you’ll need to check what yours is using gdisk:
apt-get install gdisk
gdisk -l /de/sda

2 – mount the boot partition:
mount /dev/sda3 /mnt/boot/efi

3 – Now you need to do some random shit that I don’t understand:
for i in /dev /dev/pts /proc /sys; do mount -B ${i} /mnt${i}; done
modprobe efivars
cp /etc/resolv.conf /mnt/etc

this is the magical bit:
chroot /mnt

What that does is make the actions following relevant only to only that mounted path, ie: the newly installed Linux. [http://en.wikipedia.org/wiki/Chroot]. If you don’t you’ll be doing everything to the temp livecd bootloader which is all going to get trashed… Then you’ll boot up and nothing you did will be there and many WTFs will follow… followed by a solid headslap.

4 – now install efi enabled grub:
api-get install grub-efi

fiddle with grub a little:
nano /etc/default/grub

and change:
GRUB_CMDLINE_LINUX_DEFAUL=”quiet splash”
to
GRUB_CMDLINE_LINUX_DEFAUL=”quiet splash libata.force=noncq”

update grub:
update-grub

5 – Second stage of magic is to install rEFInd [http://www.rodsbooks.com/refind/] which you can do by downloading the binary RPM: http://sourceforge.net/projects/refind/files/0.7.7/refind-0.7.7-1.x86_64.rpm/download

refind will do all kinds of things to make itself the default bootloadaer and whatnot. There are a few points to note here:

a – you will find a refind directory in /boot/efi/EFI
this is where refind lives and needs to be configured
b – refind config is actually not complicated, don’t let all the moving parts confuse you. You’ll find a refind.conf file in the refind dir in which there are 2 main points of interest:
i) you need to uncomment the line that tells refind to scan for linux efis: scan_all_linux_kernels

ii) there are a bunch of entries at the bottom of the file which demonstrate how you can manually add any OS entry to the list of avilable options when you boot. This is how we will boot windows.

c – the next config which matters is the refind_linux.conf file, which refind would have dropped in the root of the /boot partition.
this is where the linux loaders are defined for display as options during boot. Why? Well, refind is automatically scanning and looking for your linux kernels. The refind_linux.conf file is where the found options are made available for selection. Refind should have filled out all the details for you.

its well worth spending the time to understand a little about refind, the docs are great and you’ll be able to config this up loke a champ instead of hacking at it like this.

6 – Hack at the naughty sony bootloader
Sony has been really naughty in that they will only boot their known efi, which forcefully sidesteps refind to boot straght into windows. I have a story to tell here because initially, in one of my failed attempts I managed to foil this nonsense without the shananegans which follow… more on that later.

You need to make a copy of the full Microsoft folder in the EFI directory as a backup. Call it something random.

Now rename your refind directory to Microsoft and rename the refind_x64.efi file to bootmgfw.efi. Next time sony is booting they will load this file as per usual without knowing that it’s refind. From there we can boot into whatever we bloody want. Make sure you backup anything you replace first.

7 – Get windows booting
Uncomment the windows 7 entry in the example load scripts in the refind.conf file and point it at the renamed Microsoft folder’s bootmgfw.efi to provide the windows option during boot.
If you got this far, you should now have a dual boot which works. HOORAY!

Earlier I mentioned not having to do any of the random copying over stuff to fool the sony bootloader. Well, I had previously boooted into windows and run bcdedit to change the default {bootmgr} and ponted it at refind. In that scenario it actually booted from there as it shuld. However, when I tried that again the second time round it failed… so meh.

I’m going to do this all again to see if I can master what I think I now know…