Tuesday, December 11, 2012

Dual boot: Windows 7 and Ubuntu with UEFI

This post is in English because I wanted to improve my English writing skills.

A couple of months ago I bought a new laptop, a Vaio S 15. I needed to have both Windows and Linux (Ubuntu 12.04 was fine) installed. I prefer the Windows 7 interface and also I need it for electronic circuits simulations, but Linux is also necessary to some subjects such as Computer Architecture and to use a speech recognition set of programs called Alize.

Anyway, the fact is that I needed dual boot with Windows 7 and Ubuntu, and using a virtual machine wasn't an option because of its limitations. At first I thought it would be easy, as it had been when I did it in my desktop computer, but it turned out that I was completely and absolutely WRONG. That's the result of a very bad combination which I guess it is UEFI + Sony product (please correct me if I'm wrong).

The problem is that Windows would always boot if installed, ignoring everything else. It's like if the boot system looks up for a Windows installation, and if it finds it, it is launched no matter what else is found. However, if Windows wasn't installed but Ubuntu was, Ubuntu would boot up nicely. Using programs to modify the Windows boot loader menu such us EasyBCD proved to be a waste of time.

To make sure you have UEFI, press F2 a few times when the first screen appears right after you switched on your computer. It’s usually F2, but in other computers it may be other key. That will make the system configuration menu appear. If you search for boot configuration, the boot mode selected should be UEFI.

So after a week of desperate efforts to make it work, I finally made it combining several steps I had seen in some posts (links at the bottom). So this is what you must do:

  1. I assume you have a legitimate Windows 7 copy, probably the one that came installed with your computer. At the back of its case there should be a sticker with your Product Key. If you have this number, you can freely format the disk and install Windows again. If you can't find it, you should read this post about how to find it before continuing.

    If you don't have a Windows installation disk, which was also my case, 
    download the disk image from this link, where you can find both 32 bits and 64 bits versions of W7 Home, Professional and Ultimate. Choose the one you had before, otherwise I don't think it'll work.

    If you have a pirate copy of Windows, I guess it'll be the same steps from now on, but I can't tell for sure.


  2. After you've downloaded it, burn a DVD and boot from it. You may need to change the boot priority in the system configuration menu to boot up from the external optical drive. To go to that menu press F2 when the first screen appears right after switching on the computer. It’s usually F2, but it can be a different key depending on your model.

    Install Windows with the custom installation option. When asked where you want to install Windows, you must create a partition with the space you want Windows to occupy. In my laptop, I have 500 GB of hard drive and I used 185 GB for Windows, so I made a new partition of this size. If you have UEFI, Windows will probably warn you that more system partitions will be made.

    Make sure the partition in which you want to install Windows is selected when pressing Next. Then wait until the Windows installation is finished.


  3. While installing Windows, the computer should restart and everything should work fine: Windows will get ready for its first use and after a couple of configuration steps, you should be shown your desktop.

    Don’t install any drivers or updates for now, it’s best to see if the dual boot works before wasting time on that.


  4. Now it’s time to prepare the Ubuntu installation. It’s probably the same if you want another Linux “distribution”, but I can’t tell for sure.

    Download the ISO file from the Ubuntu website. If you don’t want to waste more DVDs, I would recommend using an USB flash drive to launch the installation. For that, you can use ISO to USB or any other similar tool.

    You may need to change the boot priority to try booting up from an external device before than from the internal hard disk.


  5. Now  install Ubuntu from your USB flash drive or DVD. When you're asked "How do you want to  partition the disk?" choose Manual partitioning. If you need help with this step, take a look at this detailed guide of disk partitioning.

    I recommend you to make a partition for root (" / ") of 30 GB or more if you have a lot of hard disk capacity. That's what I would do because I hate running out of space, but I don't think you'll need that much. Then make a (" /home ") partition with the rest of the hard disk space you have in your computer except for 3-6 GB. Use this 3 to 6 GB to make a swap partition. It's size should be equal or higher than your RAM size.

    In my computer I also created a 50 GB partition called Shared Disk, to save and access data from both OS.

  6. After installing Ubuntu, Windows will continue booting up ignoring the other OS. That's because the computer automatically looks up for a file in your system that launches Windows. You'll rename that file, so it isn't found that during the booting process. After doing that, Ubuntu will launch, not Windows.

    Insert the Windows DVD you used before. Don't use it to install Windows, but to open the command prompt. Type diskpart to enter the diskpart application. Now type the following commands:

    >select disk 0
    >select partition 1
    >assign letter b
    >exit

    With these steps, you have assigned a letter to a hidden partition, so now you can take a look to its folders and files. This partition should be the one where the booting information is stored. It's one of the partitions that Windows created when installed. Let's check that it's the correct one, type these commands:

    >b:
    >dir


    The output should reveal 0 files and 1 directory called EFI. If that is not correct, repeat the process of assigning a letter but try with other partition numbers, and choose other letters instead of B or C. If yo can't find a partition where dir reveals a folder called EFI, then you may not have UEFI at all

    Assuming everything went ok, let's continue typing:

    >cd EFI/Microsoft/Boot
    >rename bootmgfw.efi bootmgfw.efi.old


    This file we are renaming is the responsible for making Windows launch in our computer without looking for more OS. By renaming it, it won't be found and Ubuntu will launch.

    You can close the command prompt, restart your computer and remove the Windows DVD. Let Ubuntu launch to check that everything is working fine.
  7. The next step is to modify the Ubuntu booting up menu called grub to add an entry for Windows. Download the program Grub Customizer from the Ubuntu Software Center.

    To set the timeout, open it and go to the general settings tab. You need to activate show menu and look for other operating systems. Write the timeout you want in seconds, for example, 30.

    There's surely another way to do this without Grub Customizer, but I don't know about it.
  8. Now open a terminal and type the following. Write your root password when asked.

    $ sudo gedit /etc/grub.d/11_Windows

    In the text file copy and paste the following code:
    #!/bin/sh -e
    echo "Adding Windows 7">&2
    cat << EOF
    menuentry "Windows 7"{
    set root='(hd0,gpt1)'
    chainloader /EFI/Microsoft/Boot/bootmgfw.efi.old
    }
    EOF


    Save the file and close the text editor.
  9. Now write the following commands in the terminal:

    $ sudo chmod a+x /etc/grub.d/11_Windows
    $ sudo update-grub


    In the output, you should be able to find a line with "Adding Windows 7". Don't pay attention to "Adding Windows (2)" in the image, that is explained later.
  10. And that should be all. Now restart your computer and a menu should appear letting you choose between both Ubuntu and Windows 7. With Grub Customizer you can change the order of the entries as well as the timeout.
Final important comment: there's a Windows update that will create again the bootmgfw.efi file. That will make Windows to launch directly. When this happens, repeat the step 6 but using the command prompt of your Windows installation, it's not necessary to use the DVD anymore. Simply delete the file or rename it to something else. I also think that you'll only need to use diskpart to execute the assign letter command, but after that the explorer will let you access the partition and delete the file without having to use commands.

Another consideration to keep in mind is that if you have an external hard disk connected to your computer, it's unlikely that Windows will launch when you choose it in the menu list.

In that case, you must unplug the external hard drive when turning on your computer to avoid this. Another option is to create another file in Ubuntu called 12_Windows changing "hd0" for "hd1". This way, if one entry doesn't work because there's an external hard drive connected, the other one will do.

I hope this will help.
If anyone is able to follow these steps successfully, please let me know about it!


These are the two posts that helped me reach the final solution:




9 comments:

  1. A raw onion maу be rubbеd on unbroκen chilblaіns with supеrіοr
    end results. Τhe publican requeѕted Daisy, his barmaid, to bring some сelеbratοry
    combineԁ beverages. Τhe landfill prolonged thе plaсe so іt can be used
    to geneгate on.

    Here is my blog old stone oven

    ReplyDelete
  2. Thank you for the comment! I'm very happy to know that it's useful to you :)

    ReplyDelete
  3. Excellent material!!!! I was around 3 days trying to solve this issue and I finally found your article!! Thank you very much!!! Just a point: to make it works, instead "chainloader /EFI/Microsoft/Boot/bootmgfw.old" I used "chainloader /EFI/Microsoft/Boot/bootmgfw.efi.old"

    ReplyDelete
    Replies
    1. I'm happy it was helpful! Just like you, I went through a lot of pain to figure this out
      By the way, thanks for telling me about the mistake. I just corrected it.

      Delete
  4. i have hp g6 pavilion laptop and i am facing this problem. I had pre-installed win 7 and then i installed the ubuntu 12.4 LTS. I am unable to boot ubuntu. will this method which you have provided will work for my hp laptop or it only works for sony.

    ReplyDelete
    Replies
    1. I don't know, I haven't tried it in an HP laptop

      Delete