Меню Рубрики

Installing windows after installing linux

Linux Developer Space

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 Grub is just a matter of running 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 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. (Ctrl + Alt + t)
  3. Use a command like lsblk, blkid or GParted to identify your Linux root, and boot partitions. You may or may not have a separate boot partition.

Find Linux Partitions

/dev/sda1 is the Linux boot partition

/dev/sda2 is the Linux root partition

/dev/sda3 is the Windows partition

Setup a Chroot Environment

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

Mount your root filesystem under /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 subvol=@ /dev/sda2 /mnt/

Run ls /mnt to verify that the correct partition is mounted. It should list the content of your root.

Mount the boot partition. (SKIP if you don’t have a separate boot partition)

If you have an EFI partition you should mount that also. It is basically a small FAT32 partition around 100mb. Please refer to the section on how to reinstall Grub in an EFI system.

Bind these directories, so grub can detect other operating systems, like so.

Let’s chroot into our existing Ubuntu/Linux system on the hard disk.

Once you’ve successfully reinstalled Grub, 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 bootloader in a 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.

Case #2

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

Mount EFI partition under ‘/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.

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,

9 responses

Just wanted to give you a heads up. I recently followed your guide for repairing Grub after installing windows but wanted to let you know I had to deviate due to a typo I noticed. I worried someone else might make a catastrophic mistake if they didn’t notice so I’m letting you know.

In the section about Reinstalling Grub in an EFI based system, the example under “Mount EFI partition under ‘/mnt/boot/efi’” says to mount /dev/sda2, when I believe it should actually be /dev/sda1, according to your system layout shown earlier.

It’s possible I’m wrong, I’m not extremely well versed, but changing it worked for me and it looks like following the guide to the tee would result in installing Grub in the wrong partition.

Kane – June 19th, 2019

Thanks for the heads up. I fixed the typo that you pointed out.

Gayan Weerakutti – June 20th, 2019

I need your help. I have both Linux mint and Ubuntu installed on my system. I had Windows 8.1 before and I tried dual booting with Linux mint, I failed so I ended up with just Linux mint because i really wanted it. I installed Ubuntu later on, but I don’t like it.

The problem now is that there are applications I need to use which only support windows. I want to reinstall windows 8.1 on the Ubuntu partition but I keep getting error 0xc000000f. I do not mind doing a clean install of windows and dual boot later, but I’m stuck with that error. Please help.

Bongi – December 15th, 2019

It’s hard to tell without knowing the exact error, your partition scheme, when and how you got it. But what I’d do is to install GParted on Linux Mint. Then would create, and format partitions as necessary to install Windows. Find out if you’re currently using BIOS or UEFI. Boot into your Windows installation media in the same boot mood. Then would follow this article to recover Grub.

Gayan Weerakutti – December 15th, 2019

Thanks for the how-to. Worked like a charm.

MJ Patterson – February 12th, 2020

This has been so helpful for me ! Thanks a lot

Anonymous Coward – April 19th, 2020

Hi, In the case of a separate /home partition, should we also mount it? Thanks, Nivs

Nivs – May 2nd, 2020

Not it’s not necessary to mount a /home partition or any other partition that is not mentioned in the post.

Gayan Weerakutti – May 2nd, 2020

Hi! This method also works in UEFI mode? The Windows will installing itself in UEFI mode?

kagaa – July 1st, 2020

Leave a comment

© 2020 Gayan Weerakutti, unless otherwise noted.


How can I install Windows after I’ve installed Ubuntu?

I have Ubuntu on my laptop. Now I want install Windows 7 in a dual-boot. How can I do this?

I can’t lose my Ubuntu files, and I’m afraid that I might break GRUB.

Go here for UEFI only!

16 Answers 16

Here’s the general outline:

  1. Make space for Windows
  2. Install Windows
  3. Mount the /boot directory or partition
  4. Install the bootloader (GRUB)

Step Zero – Backup your important data before doing anything

Step One – Make space for Windows

Open up GParted, and make sure that you have at least 20 GB available for Windows 7, either as a partition you can remove, or as unpartitioned space. If it’s a partition, remove it from GRUB to make sure it doesn’t break your Ubuntu install — GParted will complain if anything bad is about to happen.

Make note of current /boot device. If that doesn’t show up there, make note of the / device. The device name is something like sda5 .

Step Two – Install Windows

Install Windows 7 into the space you just made

Step Three – Mount /boot

Note: Instead of mounting the boot directory or partition from the installation in the live media environment you can specify the path with the —boot-directory parameter for grub-install, more information on the manpage.

Load up from your Ubuntu live CD, and then run these commands.

If you DO NOT have a separate /boot partition:

If you have a SEPARATE /boot partition:

Step Four – Install the bootloader

Note: These instructions were initially written for Windows 7 and BIOS booting computers. If you have UEFI and Windows 8 and above you probably need to replace grub-pc with grub-efi-amd64 in sudo apt-get install grub-pc .

Then continue with those commands:

And restart. It should work fine and boot both systems.

Installing Windows after Ubuntu is not the recommended process for a dual boot Windows and Ubuntu system, but it is possible.

  • First, you have to make sure that the 50GB free space is available, resizing your Ubuntu by using gParted if necessary.
  • Also use gParted or Disk Utility to format the the free space as NTFS, this prevents Windows 7 from creating an additional boot partition in addition to the «C» drive.

Next, boot to the Windows DVD installer and install Windows on the NTFS partition. Upon reboot, Windows will automatically boot and you won’t see the grub menu allowing you to choose Ubuntu, because the Windows bootloader has replaced grub.

Now, what you need to do is run Ubuntu from LiveCD or LiveUSB and install boot-repair.

To install boot-repair, open up a terminal by pressing Ctrl+Alt+T and type the following commands:

After installation, boot-repair will automatically launch, if is doesn’t, launch it via Dash.

Make sure to select recommended repair to repair grub. Reboot and that’s it.

  • You should now have a Grub menu on boot, allowing you to choose from Ubuntu, memtest, and Windows 7
  • boot-repair did a really good job launched from a live-usb, by just applying the recommended option.

    UEFI only!

    This answer covers UEFI-only, and is meant to be a bit of a more modern answer as UEFI has succeeded the ancient BIOS. Also, there are some edits here to fit the fact it’s answering a «how I do this» rather than a «can I do this» type of question.

    To install Windows alongside Ubuntu, you just do the following:

    1. Insert Windows 10 USB
    2. Create a partition/volume on the drive to install Windows 10 on alongside Ubuntu (it’ll create more than one partition, that’s normal; also make sure you have space for Windows 10 on your drive, you might need to shrink Ubuntu)
    3. Install the Windows 10.

    Note: when making sure things are ready for your dual boot, check if Ubuntu is installed in the GPT partition table! While 99% of the time you will be using GPT if you’re planning to do this, it is possible to install Ubuntu’s UEFI on MBR but Windows 10 does not support that strange use-case. In that situation, convert to GPT if possible. If not, backup and reinstall, and I’d recommend that as it’ll be easier.

    When you boot have you checked the boot order on your BIOS? If you’re booting straight to the hard drive it will always miss the USB. You need to move the USB device boot option higher in the priority list.

    Also check that your computer allows you to boot from USB in the USB port you are using.

    First, you have to boot with a live CD/USB stick and shrink your partition in order to create a second one. Windows 7 requires and creates a second partition which is called «system reserved». I don’t know why, but it does. (So you will end up with three partitions or four if you have a swap partition.)

    When your partition is ready, just boot with your Windows 7 DVD/USB stick and install Windows 7 on the new partition.

    When Windows 7 has been installed, GRUB will break and you will only be able to boot Windows (automatically). Just boot with a live Ubuntu CD/USB stick and fix it (how it is mentioned in other comments).

    Now another issue that some users may face:

    I own an HP Mini 210 netbook which came with Windows 7. I erased everything and installed Ubuntu. Later on I decided to also reinstall Windows 7 and have a dual boot (needed Windows for a specific application from my university which wouldn’t run through wine). At that time I had three partitions:

    Now when I tried to install Windows 7 I faced a problem because Windows 7 needs to create a second primary partition (system reserved). I already had three partitions and therefore was unable to create two more. The workaround here is to create an extended partition in which you will include both swap and backup storage. Now I have: