Install Windows after Ubuntu 32


As you know, the most common, and probably the most recommended way of dual booting Ubuntu and Windows is to install Windows first and then Ubuntu. But what if you want to install Windows second? … on a computer with Ubuntu/Linux already installed.

This guide assumes that you have Ubuntu already installed on your system, and will guide you through installing Windows 7/8/8.1/10 when you have a working Ubuntu/Linux partition.

The problem here is that the Windows installer tends to overwrite Grub bootloader or whatever making only the Windows installation bootable. But the good news is that your Linux partition is untouched, including the original bootloader and the other Grub configurations. So restoring or recovering the Grub is just a matter of slapping a few commands on the terminal.

Install Windows on a Separate Partition
If your Ubuntu installation occupies the entire hard drive, to be able to create free space for the Windows installation. you may have to shrink an existing partition using a disk utility like GParted. GParted comes preinstalled on Ubuntu LiveCD.

Boot into a Windows installation media and complete with the installation.
Once installed, because of Microsoft’s false assumption that there are no non-Microsoft operating systems you’ll be taken straight into Windows.

Restore / Reinstall Grub 2 with a Ubuntu Live Media

  • Now boot into a Ubuntu Live/USB or CD.
  • Open a terminal. (Ctrl + Alt + t)
  • Use lsblk, blkid commands or GParted to identify your Linux root, and boot partitions. You may or may not have a separate boot partition.
    Find Linux Partitions

    In my case
    `/dev/sda1` is the Linux boot partition
    `/dev/sda2` is the Linux root partition
    `/dev/sda3` is the Windows partition

Now we’ll be repairing our old grub bootloader in a chroot environment.

Setup a Chroot Environment

  • Mount your root filesystem under `/mnt`
    sudo mount /dev/sda2 /mnt/
    If you’re using BTRFS (New Linux B-Tree File System) instead of EXT4, the above command should change to
    sudo mount -t btrfs -o [email protected] /dev/sda2 /mnt/
    .. the subvolume name `‘@‘` may change
  • Run ls /mnt to verify that the correct partition is mounted. And it should list the content of your root.
  • Mount the boot partition (SKIP if you don’t have a separate boot partition).
    sudo mount /dev/sda1 /mnt/boot
  • If you have a EFI partition you should mount that also. It is basically a small FAT32 partition around 100mb. Please see the #example case 2
  • Bind the directories, so grub can detect other operating systems, like so.
    sudo mount --bind /dev /mnt/dev
    sudo mount --bind /dev/pts /mnt/dev/pts
    sudo mount --bind /proc /mnt/proc
    sudo mount --bind /sys /mnt/sys

Lets chroot into our existing Ubuntu/Linux system on the hard disk.
sudo chroot /mnt

Reinstall Grub.

grub-install /dev/sda (specify the disk `/dev/sdX`, not `/dev/sdaX`)
grub-install --recheck /dev/sdX
exit

Then restart the computer. On next reboot Grub will be the default bootloader and you’ll be presented with a list of operating systems to choose from (Ubuntu and Windows, of course).

Reinstalling Grub in an EFI Based System
Reinstalling Grub bootlaoder in an UEFI based computer is no different from installing Grub on a legacy Bios system. Here we also mount the EFI partition before chrooting, as we’d do with the boot partition.

Example Case #2

Grub install on EFI Partition Table

Here /dev/sda2 is the EFI partition and /dev/sda5 is the root.

  • sudo mount -t btrfs -o [email protected] /dev/sda5 /mnt/
    (For EXT4 filesystem: `sudo mount /dev/sda2 /mnt/` )
  • Mount efi partition under ‘/mnt/boot/efi’
    sudo mount /dev/sda2 /mnt/boot/efi
    Forgetting to do so will result in errors being thrown while trying to execute `grub-install`: “/boot/efi does not appear to be the efi partition”
  • As shown previously, bind the /dev, /dev/pts, /proc, and /sys directories.
  • Finally,
    sudo chroot /mnt
    grub-install
    exit

In some rare occasions Grub might not detect Windows. In that case just login to Ubuntu (installed one on the disk, not the bootable Live USB/CD) and execute,

sudo os-prober
sudo update-grub
sudo reboot

Happy Dual-Booting!


Leave a comment

Your email address will not be published. Required fields are marked *

32 thoughts on “Install Windows after Ubuntu

  • Djinn

    You can also do it from within Windows.

    1. Login to Windows
    2. Open an Admin Command Window
    3. Type mountvol S: /S (Unless you have an S: drive in which case choose a different letter)
    4. Change to S:
    5. Change to the EFI\ubuntu directory and do a dir.
    6. You should see grub64.efi and shimx64.efi. If you have Secure Boot enabled in your BIOS you want shimx64.efi, otherwise you want grubx64.efi.
    7. Type the following, change shimx64.efi to grubx64.efi if needed:
    bcdedit /set {bootmgr} path \EFI\ubuntu\shimx64.efi
    8. Reboot your computer and verify the Ubuntu boot manager starts

  • Karanja Mutahi

    “Bind the directories, so grub can detect other operating systems, like so.”

    What directories are you referring to?

    • reversiblean Post author

      I’m referring to /dev /proc and /sys filesystems which include information about processes and devices. You can bind them by single command sudo for dir in /dev /proc /sys; do mount --bind $dir /mnt/$dir ; done

        • Fabrício

          I’m having doubts about this part, brother:
          grub-install /dev/sda (specify the disk `/dev/sdX`, not `/dev/sdaX`)
          grub-install –recheck /dev/sdX
          exit
          what partition exactly should these commands refer to? the one in which windows boot manager is located? other?

          • reversiblean Post author

            So for example `/dev/sda` is a disk. `/dev/sda1` is a partition of that device. And you should be specifying the disk that you want to install grub into. Sorry I know it’s way too late to comment 🙂

  • Olla

    Thanks alot for this. It was a great help. ^_^

    For anyone with a Lenovo Z510:
    My case was as Example 2 and after installing windows on a linux, my grub was unaffected but it couldn’t detect windows, and I only needed to probe os and update my grub on the installed linux as mentioned in tutorial.

  • hida

    please help me, I cannot find ubuntu boot. I think the boot changed into /dev/sdb1 with the system is W95 FAT32, what should I do?

  • Paolo Brocco

    Hi there, in my case it was much easier. I just re-ordered the boot devices in the bios (I have a z170 motherboard but I guess any modern bios allows you to do that) and selected ubuntu first. So I could boot in ubuntu, no need to do the chroot. I just did these 2 commands and it was all done:

    grub-install (no need to specify device, it’s implied)
    update-grub (to add the windows entry)

    Cheers

    • rio chandra

      It’s work.. Just 2 lines command..
      I have do all step above.. And i just got grub boot without windows’s os.. Maybe in another case its worked for them..

      thanks a lot

  • Zan

    What format should I make the partition in for the Windows install? I tried NTFS and got errors during the install about having a MBR partition table instead of a GPT disk. I’m new to this so any help is much appreciated!

  • thornyrabbt

    Does this procedure work for installing Windows 7 to a second HDD?

    (I have Ubuntu 16.04 on a primary SSD; secondary HDD has Win7 from another computer so it is “broken” and needs to be reinstalled. My machine is an HP Pavilion laptop.)

    Thanks

    • Gayan Weerakutti Post author

      Reinstalling Windows 7 probably will overwrite the existing partition or may write new partition table into your second HDD (which I’m not sure). However when you reinstall grub as shown in the guide make sure you pick the correct device which is your SSD. And it should detect Win7 on HDD as well.

      • thornyrabbt

        Thank you for your reply Gayan. Once I resigned myself to the idea of spending countless hours trying all the different ways I could think of to get Win7 installed, I found a way.

        My laptop is an old HP Pavilion dv9000 with two drive bays. I don’t know what the BIOS is called but it seems to be managing the two drives independently before the OS knows which is which. The BIOS seems to look only at the primary when finding bootloader, so what I did is remove the Linux SSD from primary, place the HDD I wanted Win7 to go on in the primary slot (nothing in secondary), and installed Windows as if it had the whole system. After I installed and verified the security key for that installation of Windows 7, I removed the Win7 HDD and put it in the secondary drive slot, and replaced the Ubuntu SSD in primary. This way, GRUB was able to detect the presence of a Windows partition on secondary and corrected itself, offering a startup menu.

        I can now boot into Win7 without any problems. It seems that Ubuntu plays nicer with Windows than Windows plays with Ubuntu.

  • Del369

    I installed Ubuntu 16.04 (Zorin 12) on the first 3 partitions of a Samsung SSD, I just installed Win 10 on the other free space on that drive (250gb) and all I needed to do after was:-

    sudo os-prober
    sudo update-grub
    sudo reboot

    The Win install didn’t destroy Grub it actually booted straight to Ubuntu straight after the Win first reboot, oh I did need to comment out the following in etc/default/grub

    #GRUB_HIDDEN_TIMEOUT=0

    That was it basically, reading the comments bewow it might have been because I had my Ubuntu EFI SSD as first boot device that it went so easy.

    • Gayan Weerakutti Post author

      Windows would not have override your grub. So you may now have two separate bootloaders for Windows and Ubuntu which is fine.

  • Joseph

    Did not work. Followed to the T. All that come up on reboot after grub install command with no errors is a grub terminal but no booting options. Now nothing will boot. It would be great if you could give that scenario some coverage. Thanks

    • Gayan Weerakutti Post author

      What did you mean by T? Can you see the boot loaders in BIOS boot menu? If so you should be able to access them.

  • ali

    I created windows bootable USB.When I boot through BIOS it says can’t boot in the selected partition-partition of gpt style.When I try booting through UEFI it simply says can’t boot.

    • Gayan Weerakutti Post author

      Make sure that your iso is UEFI compatible. Then use a utility like Rufus to create an UEFI/BIOS bootable USB flash drive.