Using Grub without Linux for Windows 7/10 Dual Boot Configuration
Tags: grub, linux, windows, ubuntu
Published: 2020-08-21 20:50:50

> I throw together things until it works
> -- Rasmus Lerdorf, Creator of PHP

TL;DR at the bottom

---

This is part 1 on a 2 part series about manual grub configuration
- Installing Standalone Grub for Windows 7/10 Dual Boot Configuration
- The Absolute Minimum Every Linux User Absolutely, Positively Must Know About grub.cfg (No Excuses!) (coming soon®)

---

## The Problem

- Create a dual boot with
  - A hard drive with Windows 7
  - A SSD with Windows 10
- I am not allowed to edit the [BCD](https://en.wikipedia.org/wiki/EasyBCD)
- I am not allowed to install any other OS

---

The Idea: Installing Grub with 2 Windows bootloader entries.

---

## Preparation is Half the Battle
### Making Space for the boot Partition
Since we shrink NTFS, we use Windows for that.

First, press `<Win-r>` and run `compmgmt.msc` and use the "Disk Management" utility.

Right click on the partition you want to shrink and make at least 200MB space for grub.

![Shink that f*cker](https://dev-to-uploads.s3.amazonaws.com/i/pr311bda8cwpwahzesbd.png)

After you made some free space, right click the free space and create a new partition using "New Simple Volume". Which settings you select doesn't matter since we will overwrite it later.

After that, the last preparation step is to

### Create a neat Ubuntu Stick

[Just use rufus.](http://rufus.ie/)

## Installing Grub

After you booted up, grab a root shell, and find out which the new partition is (for example by listing all partitions via `fdisk -l` and comparing size. [You can ignore all `/dev/loopXX`.](https://en.wikipedia.org/wiki/Loop_device))

Now we format it with a grub compatible file system. From now on, the new partiton is `/dev/sda2`.

(for simplicity, I assume bios/mbr from now on)

```
mkfs.ext4 /dev/sda2
``` 

Afterwards, we mount it, create a boot directory and try to install grub:

```
mount /dev/sda2 /mnt && mkdir /mnt/boot
# The --boot-directory is needed since we don't manipulate
# our own bootloader, therefore we don't have the default
# location /boot
grub-install --boot-directory=/mnt/boot /dev/sda1
```

If that didn't work, just force it, we have to configure it manually anyways:

```
grub-install --force --boot-directory=/mnt/boot /dev/sda1
```

It can't be that easy! And it isn't!!!! When you try to generate the config with

```
grub-mkconfig -o /mnt/boot/grub/grub.cfg
```

it should cry about something like

```
/usr/sbin/grub-probe:error:failed to get canonical path of /cow.
```

This happens because `grub-probe`, the tool called by the `grub-mkconfig` script, can't handle ubuntu's live system root.

## Improvise, Adapt, Overcome

But that's no problem! Writing one's own minimal `grub.cfg` is easier than you'd expect! 

First, find out which UUID's your `C:\` partitions have. Again, just compare the size and file system with `fdisk -l` and throw the `/dev/sdxx` into `blkid`.

Now, let's start writing a `grub.cfg` by opening your favorite editor

```
nano -w /mnt/boot/grub/grub.cfg
```

We just have to do 2 things. First, we set some sane defaults:

```
# Set first as default
set default="0"

# Set timeout for 10 seconds that we have enough time
set timeout=10

# sane IO
terminal_input console
terminal_output gfxterm

# minimalistic color sheme
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
```

Now, we have to create the entries. I'll comment as I go
```
# Here, the "Windows 10" is just the representative name
# it can be chosen as you want to
menuentry "Windows 10" --class windows --class os {
        # insmod ntfs loads ntfs support
	insmod ntfs
        # finds the right partition by the UUID you found earlier
	search --no-floppy --set=root --fs-uuid <YOUR UUID>
        # Starts the windows NT loader
	ntldr /bootmgr
}

# Analogous for your other windows
menuentry "Windows 7" --class windows --class os {
	insmod ntfs
	search --no-floppy --set=root --fs-uuid <YOUR UUID>
	ntldr /bootmgr
}

```

Afterwards, just unmount everything, change the boot order if necessary and et voila, you solved the problem!

## TLDR Code

Minimal `grub.cfg`
```
set default="0"
set timeout=10
terminal_input console
terminal_output gfxterm
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry "Windows 10" --class windows --class os {
	insmod ntfs
	search --no-floppy --set=root --fs-uuid <YOUR UUID>
	ntldr /bootmgr
}
menuentry "Windows 7" --class windows --class os {
	insmod ntfs
	search --no-floppy --set=root --fs-uuid <YOUR UUID>
	ntldr /bootmgr
}
```

## Thanks
Thanks for reading and [thanks to Anton Tagunov for his blog post on the topic](http://atagunov.blogspot.com/2012/04/installing-grub2-without-linux.html).