Creating a new EFI partition on another disk in order to maintain original Windows Boot

7,122

The last I heard, there was a bug in the Ubuntu installer that caused it to always place GRUB on the EFI System Partition (ESP) on the first disk (usually /dev/sda), even if you tried to force it onto another ESP (say, one on /dev/sdb). This fact can make separating your Windows and Ubuntu installations a little trickier than you might like. Also, the way Ubuntu configures GRUB, it's reliant on both files on the ESP and a grub.cfg configuration file in the Ubuntu /boot/grub directory, which is not on the ESP. Thus, if you install Ubuntu and then delete it by deleting the Ubuntu partition(s), GRUB will remain behind, but with its grub.cfg file gone, the computer will hang at a grub> prompt when you boot. This problem can be overcome by manually deleting the GRUB files from the ESP or by tweaking the boot order using efibootmgr in Ubuntu or EasyUEFI in Windows before deleting the Ubuntu partitions.

Alternatively, you could follow this procedure to install Ubuntu:

  1. Download the USB flash drive or CD-R version of my rEFInd boot manager.
  2. Write the rEFInd image to a USB flash drive or CD-R, as appropriate.
  3. Boot the Ubuntu installer in its "try before installing" mode. This results in a normal Ubuntu desktop.
  4. Open a Terminal window.
  5. Type ubiquity -b. This launches the installer, but the -b option tells it to not install GRUB.
  6. In the installer (or before you run the installer, if you prefer), set up your partitions, and be sure to include an ESP on the second disk (the one to which you're installing Ubuntu).
  7. When you're done with the installation, reboot using the rEFInd disk. You should see the rEFInd menu appear. (A caveat: The rEFInd disk images I distribute do not support Secure Boot. Thus, if Secure Boot is active, you'll need to either disable it or modify the rEFInd image to include Shim. You can re-enable Secure Boot later, but you may need to jump through some extra hoops at that time. Windows 7 does not support Secure Boot, so you shouldn't run into this problem. I mention it in case somebody wants to do something similar with a Windows 8 or later installation.)
  8. Using the rEFInd menu, boot Ubuntu. (A caveat: If you use a separate /boot partition, you'll need to hit F2 or Insert twice and add a ro root={rootfs} option, where {rootfs} is a pointer to the root (/) filesystem, such as /dev/mapper/lvm-root. This is normally only necessary if you use LVM or software RAID.)
  9. In Ubuntu, check and, if necessary, alter /etc/fstab so that it mounts the ESP in Ubuntu's directory tree at /boot/efi. If you need to change this detail, be sure to unmount anything that's already mounted there and mount the Ubuntu disk's ESP at /boot/efi before proceeding.
  10. Install your preferred boot loader.
    • If you want to use GRUB 2, install the grub-efi package. You may also need to run sudo grub-install and/or sudo update-grub.
    • If you want to use rEFInd, install the rEFInd Debian package or PPA. If you're asked if you want to copy rEFInd to the ESP, be sure to respond affirmatively.

At this point, when you reboot you should see GRUB or rEFInd appear and you should be able to boot either Windows or Ubuntu. If you want to go back to a stock factory installation, you can wipe all the partitions from the Ubuntu disk, including the ESP, and the computer should skip over the now-invalid entry for GRUB or rEFInd and go straight to booting Windows. (If you use rEFInd, it should continue booting Windows even if you delete all the Ubuntu partitions but leave the ESP on which rEFInd resides intact.)

Share:
7,122

Related videos on Youtube

David
Author by

David

Updated on September 18, 2022

Comments

  • David
    David over 1 year

    I'm installing ubuntu on my computer at the office. Since I never installed ubuntu alongside with an existing windows on a UEFI system, I want to avoid all possible problems. I already read all the available documentation but still have a short question. In my computer I have two SSDs, one for windows 7, the other will be entirely dedicated to ubuntu. If I want to be sure to be able to get back to the initial state, can I just create a new EFI partition on the second disk and set this disk as boot priority? Will then be windows 7 automatically found by GRUB? And, if I'm running into problems, can I just switch boot priority in my setup and I will boot windows?

    • Zeiss Ikon
      Zeiss Ikon about 7 years
      Before installing anything on your office computer, make sure your IT department is on board; you could be terminated for computer tampering if you install anything without authorization.
    • David
      David about 7 years
      I have authorization. They just do not have time for supporting linux
    • Admin
      Admin about 7 years
      OK then. Yes, it can be done and has the advantage of being able to boot that drive standalone even in a different UEFI enabled machine later on. But there's no problem in using the default installation that will add the Ubuntu entries to the ESP of the first drive regardless of where Ubuntu is installed. That can be easily "reset" if/when you decide to remove the second drive/Ubuntu, directly from Windows or the UEFI itself.
    • David
      David about 7 years
      @CelticWarrior Ok, thank you! So actually there should be anything to worry about choosing as booting partition the EFI partition of the Windows disk. If I decide to create a new partition in the second disk (this still remains my favourite, since so I could just remove the disk and all will be just like before) the Windows partition should be found without problems by the grub, right?
    • Admin
      Admin about 7 years
      Yes, it should but sometimes it doesn't (this is irrespective of the method). Just disable Fast Startup in Windows and shutdown (reboot often reverses the changes). Then boot Ubuntu and run sudo update-grub.
    • David
      David about 7 years
      Ok, thanks. Since I have Win7 I also don't have to disable fast startup ;)
    • Admin
      Admin about 7 years
      Indeed. And now that you mentioned it, are you sure the Windows 7 is installed in UEFI mode? It can be done with a USB flash drive prepared with Microsoft's official tool, Rufus or similar. With a DVD it can only be installed in legacy.
    • David
      David about 7 years
      Indeed this morning I simply assumed it was installed in Legacy. I then ran into grub problems (doh!) and found that it was UEFI. I then also checked via windows cmd and I'm therefore now 100% sure it is UEFI
    • oldfred
      oldfred about 7 years
      UEFI/gpt partitioning in Advance: askubuntu.com/questions/743095/… The boot files are the same, so you can just copy from one drive to another drive's ESP. But UEFI entry is different as that uses GUID of ESP. If an external drive you also must copy to /EFI/Boot and rename shimx64.efi to bootx64.efi. I do always do this as another boot entry anyway. External drives only boot using /EFI/Boot/bootx64.efi, but internal drives can use it as a fallback or hard drive boot entry.
    • mook765
      mook765 about 7 years
      if Win7 is in legacy-mode, install ubuntu in legacy-mode. Use something else-option from installer and install ubuntu on second drive and install grub2 on second drive as well. first drive will be untouched. change boot-order in BIOS to second drive to boot to Grub where you can choose to start Ubuntu or Windows.