Getting Three Window Partitions and One Linux Partition with GRUB2 Multi-Boot System (Non-UEFI)
In this article, we will discuss how to create a multi-boot system with three Windows partitions and one Linux partition using GRUB2 on a non-UEFI based system. This setup is useful for developers, testers, or anyone who wants to run multiple operating systems on a single machine.
Partitioning the Hard Drive
The first step in creating a multi-boot system is to partition the hard drive. We will need to create four primary partitions, one for each operating system. To do this, we can use a partitioning tool such as fdisk or gdisk on Linux, or the built-in Disk Management tool on Windows.
# fdisk /dev/sda
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199):
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (4196352-209715199, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-209715199, default 209715199):
Using default value 209715199
Partition 2 of type Linux and of size 90 GiB is set
Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3-4, default 3): 3
First sector (4196352-209715199, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-209715199, default 209715199):
Using default value 209715199
Partition 3 of type Linux and of size 90 GiB is set
Command (m for help): n
Partition type:
p primary (3 primary, 0 extended, 1 free)
e extended
Select (default p): p
Partition number (4-4, default 4): 4
First sector (4196352-209715199, default 4196352):
Using default value 4196352
Last sector, +sectors or +size{K,M,G} (4196352-209715199, default 209715199):
Using default value 209715199
Partition 4 of type Linux and of size 90 GiB is set
Installing Windows
Once the hard drive is partitioned, we can install Windows on the first partition. We can use the Windows installation media to boot the system and follow the on-screen instructions to install Windows. During the installation process, we will need to format the partition using the NTFS file system.
Installing Linux
After installing Windows, we can install Linux on the second partition. We can use a Linux distribution such as Ubuntu or Fedora to create a bootable USB drive and boot the system from it. During the installation process, we will need to select the second partition and format it using the ext4 file system.
Configuring GRUB2
Once both operating systems are installed, we can configure GRUB2 to boot both of them. We can edit the GRUB2 configuration file located at /etc/default/grub and add the following lines:
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash"
GRUB_CMDLINE_LINUX=""
# Windows bootloader
menuentry 'Windows Boot Manager (on /dev/sda1)' --class windows --class os $menuentry_id_option 'osprober-chain-1C5E1E3A5E1E1E1E' {
insmod part_msdos
insmod ntfs
set root='hd0,msdos1'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1 --hint-baremetal=ahci0,msdos1 1C5E1E3A5E1E1E1E
else
search --no-floppy --fs-uuid --set=root 1C5E1E3A5E1E1E1E
fi
chainloader +1
}
# Linux bootloader
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-88888888-8888-8888-8888-888888888888' {
recordfail
load_video
gfxmode $linux_gfx_mode
insmod gzio
if [ x$grub_platform = xxen ]; then insmod xzio; insmod lzopio; fi
insmod part_msdos
insmod ext2
set root='hd0,msdos2'
if [ x$feature_platform_search_hint = xy ]; then
search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos2 --hint-efi=hd0,msdos2 --hint-baremetal=ahci0,msdos2 8888-8888
else
search --no-floppy --fs-uuid --set=root 8888-8888
fi
linux /boot/vmlinuz-5.4.0-90-generic root=UUID=88888888-8888-8888-8888-888888888888 ro quiet splash $vt_handoff
initrd /boot/initrd.img-5.4.0-90-generic
}
We can then update the GRUB2 configuration by running the following command:
sudo update-grub
- Partition the hard drive into four primary partitions
- Install Windows on the first partition
- Install Linux on the second partition
- Configure GRUB2 to boot both operating systems