Install Windows after Linux

in #linux7 years ago (edited)

This guide is quite different from the traditional way of dual booting Linux and Windows, in which you install Windows first and then Linux. But what if you want to install Windows second on a computer with Ubuntu/Linux already installed.

Here I will guide you through steps of installing Windows 7/8/8.1/10 assuming that you have Ubuntu already installed on your system. The same steps could be applied for Debian, Fedora or any other Linux distribution for that matter.

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

1. Now boot into a Ubuntu Live/USB or CD.

2. Open a terminal.

3. You can use one of lsblk, blkid, fdisk -l commands to identify your Linux root, and boot partitions. You may or may not have a separate boot partition. You can also use GParted if you prefer GUIs.

identify linux partitions identify partitions with fdisk

Here in my case, I have a LVM which holds my root, home and swap partitions. But it is very like that you have much simpler partition setup. Let's say that you have:

    `/dev/sda1` as the boot partition

    `/dev/sda2` as the root partition

    `/dev/sda3` as the Windows partition

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

Setup a Chroot Environment

4. 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

    $nbsp;$  sudo mount -t btrfs -o subvol=@ /dev/sda2 /mnt/

.. the subvolume name `‘@‘` may change

5. Run `ls /mnt` to verify that the correct partition was mounted. And it should list the content of your root.

6. Then 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

7. 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

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

    $ sudo chroot /mnt

9. 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

Device Type Mount Point
/dev/sda2 EFI System /boot/efi
/dev/sda3 Linux /
/dev/sda4 Microsoft basic data

Here `/dev/sda2` is the EFI partition and `/dev/sda3` is the root.

    $  sudo mount /dev/sda3 /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

If you have any questions, additions, let me know in the comments section below.

Happy Dual-Booting!


Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.033
BTC 93256.79
ETH 3124.97
USDT 1.00
SBD 3.05