DEV Community

loading...
Cover image for Using Grub without Linux for Windows 7/10 Dual Boot Configuration

Using Grub without Linux for Windows 7/10 Dual Boot Configuration

lquenti profile image Lars Quentin ・3 min read

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

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.

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

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

grub-install --force --boot-directory=/mnt/boot /dev/sda1
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

it should cry about something like

/usr/sbin/grub-probe:error:failed to get canonical path of /cow.
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
}

Enter fullscreen mode Exit fullscreen mode

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
}
Enter fullscreen mode Exit fullscreen mode

Thanks

Thanks for reading and thanks to Anton Tagunov for his blog post on the topic.

Discussion (0)

Forem Open with the Forem app