Can't boot to windows after installing Ubuntu in UEFI

30,233

Depending on exactly what the warnings said, and what exact choices you made when installing Ubuntu, the installation process may have done one of a few things:

  • It may have converted the partitioning from MBR to GPT style to install UEFI-style, keeping (or resizing) the existing partitions. This is the best option: you'll just need to install a UEFI-style bootloader and you can then get back to Windows. Once the Windows UEFI bootloader is on the disk, Ubuntu might even detect it automatically the next time you run sudo update-grub and add it to the GRUB boot menu for you.

  • It may have just set up a UEFI-style bootloader on a MBR-partitioned disk. This is a problem, since while Linux can do this, Microsoft says Windows won't support this combination. However, returning to legacy-style Windows-only boot should be fairly easily doable in this case.

  • It may have taken the entire disk for Ubuntu, so your Windows installation was overwritten and no longer exists. This is the worst-case scenario: if you want Windows back, you'll need to fully reinstall it and your existing Windows files will be gone.

Identifying your situation

In Linux, run sudo fdisk -l /dev/sda. If your system disk is something other than /dev/sda, replace that with the appropriate device name. For example, on a new system with a NVMe SSD, it might be /dev/nvme0n1 instead.

The output should look similar to this:

$ sudo fdisk -l /dev/sda
Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 2B05CCE8-92BC-4308-B770-174CE63D044F

Device       Start       End   Sectors  Size Type
/dev/sda1     2048   1050623   1048576  512M EFI System
/dev/sda2  1050624   1550335    499712  244M Linux filesystem
<... other partitions listed here...>

If your version of Linux fdisk isn't too old, the output should include a line that says either

Disklabel type: gpt

or

Disklabel type: mbr

This identifies the partitioning style that is currently in use on your system disk.

GPT-partitioned system disk - installing a Windows UEFI bootloader

Since the Linux installer has set up a UEFI bootloader for us, there should also be an EFI system partition (ESP for short) on the disk. In the fdisk -l output, it is the partition that has its Type listed as EFI System and its size would typically be something in between 100M and 512M. In Linux, it might be mounted at /boot/efi. You might want to run sudo ls -l /boot/efi or take a peek at it with some GUI file manager so that you'll recognize the contents of this partition - you'll be seeing it at Windows command prompt for a bit. Typically, if ESP is mounted at /boot/efi, there should be a sub-directory like /boot/efi/EFI/ubuntu that contains the actual UEFI bootloader of Ubuntu.

Now, get yourself a Windows 10 installation media. You won't need the license code. Boot your computer from that installation media. Since your Ubuntu installed in UEFI mode, your computer will probably boot the Windows installer in UEFI mode automatically too, but in case you see two boot options for the installation media, only one of those options boots it in UEFI mode, and that's the one you should pick. (Hopefully the boot menu will say which is which - it depends on your system's UEFI firmware.)

When the Windows installer displays the initial screen with an "Install now" button in the middle of the screen, select instead "Repair your computer" near the bottom.

From the next menu, choose "Troubleshoot" and then "Command Prompt".

Now, type in these commands:

diskpart
list vol

This should display a list of partitions. Find the partition that has FAT32 in the "Fs" column - it should be your ESP you saw in Linux before. Note its volume number (Volume ### in the leftmost column) and assign an unused drive letter (like X:) for it. For example, if ESP is listed as Volume 2:

sel vol 2
assign letter=x:

It should say DiskPart successfully assigned the drive letter or mount point. at this time. Then type exitto quit the DiskPart utility.

Switch to the EFI directory on the ESP:

cd /d x:\EFI
dir

If you see the ubuntu directory, you're in the right place.

Now create a directory or two for the Windows UEFI bootloader:

mkdir Microsoft
cd Microsoft
mkdir Boot
cd Boot

Install the Windows UEFI bootloader to the ESP and re-create the Windows BCD registry:

bcdboot c:\Windows /l en-us /s x: /f UEFI /addlast

If you want the Windows bootloader to use a language other than English, replace en-us in the command above with the appropriate Windows language code.

Now type exit, remove the Windows installation media and reboot your system. It should come up in Ubuntu just as before. Run sudo update-grub to update the GRUB boot menu. If all goes well, it should now auto-detect the presence of UEFI Windows bootloader and add it to the GRUB boot menu.

Also now in the BIOS boot order menu, there should be a item named "Windows Boot Manager". If you want to remove Ubuntu and go back to Windows-only system, just switch this one as the primary boot option, and the system should skip GRUB and boot into Windows by default. Then you can remove the Linux partitions using Windows Disk Management. Do not remove the EFI System partition, as now Windows also needs it for booting.

(Work in progress - I'll add the MBR restoration option later)

Share:
30,233

Related videos on Youtube

Azhar
Author by

Azhar

Updated on September 18, 2022

Comments

  • Azhar
    Azhar almost 2 years

    I'm trying to install an Ubuntu dual boot on my windows 10 laptop. Windows 10 used the legacy BIOS setting.

    When I start the Ubuntu installation I get a warning about BIOS and UEFI, other operating systems becoming unbootable, only proceed if sure, etc. But since no alternative is offered (other than simply giving up and not installing Linux) I decided to proceed, and found that after install, GRUB only offered a Linux option.

    Is there a way for me to boot from Windows again? I don't mind to uninstall ubuntu

    • Philip Couling
      Philip Couling about 5 years
      This is really a windows question.. But which Windows? Do you know if windows was booting from Legacy or UEFI? Under Linux do try sudo update-grub
    • Azhar
      Azhar about 5 years
      Windows is booting from legacy and it's windows 10
  • Azhar
    Azhar about 5 years
    Thank you for your information
  • Mohsin Bukhari
    Mohsin Bukhari over 4 years
    Mine shows Disklabel type: dos
  • donkey
    donkey about 4 years
    c:\windows isn't a directory for me, neither was it a root directory in the iso what am I missing?
  • Mike Tsubasa
    Mike Tsubasa almost 3 years
    Works 100%.Thanks.In my case,the efi partition was already listed as F drive .so used it instead of naming it a separate letter like X
  • cajomar
    cajomar over 2 years
    My hero. Botched windows when installing arch linux, so glad a I didn't have to reinstall windows.