Configuring Grub 2 on CentOS 7 to Dual Boot with Windows 7

  • 6
    Shares

This post assumes that Windows was installed first, and then CentOS was installed second.
Once you install CentOS 7 alongside your Windows OS, you may find that you cannot boot into Windows. The Grub bootloader may only show your Linux OS as your only options to boot from.

To fix this and have the Grub bootloader list your Windows OS, you need to edit the Grub bootloader files. If you have used CentOS is the past (with 6 or earlier), you may find that editing Grub is different. Previously, you would edit /boot/grub/grub.conf. This is no longer the case, as the grub2.cfg file is generated dynamically, based on dependency files. Here’s what you need to edit to configure your bootloader.

Step 1 – Boot into CentOS 7, if you haven’t already.

Step 2 – Determine what partition your Windows OS resides on by running sudo fdisk -l in Terminal. Here’s my output:

[root@localhost ~]$ fdisk -l

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk label type: dos
Disk identifier: 0x30576da1

Device Boot Start End Blocks Id System
/dev/sda1 * 2048 206847 102400 7 HPFS/NTFS/exFAT
/dev/sda2 206848 307202047 153497600 7 HPFS/NTFS/exFAT
/dev/sda3 307202048 307611647 204800 83 Linux
/dev/sda4 307611648 976773119 334580736 5 Extended
/dev/sda5 307613696 516624383 104505344 8e Linux LVM

Disk /dev/mapper/centos-root: 104.9 GB, 104857600000 bytes, 204800000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes

Step 3 – Open a terminal and navigate to /etc/grub.d/ and modify 40_custom file and add following lines at the end of file.

[root@localhost ~]$ cd  /etc/grub.d/
[root@localhost ~]$ vi 40_custom

# add below line

menuentry "Windows 7" {
         set root=(hd0,1)
         chainloader +1
         }

Step 4 – Finally, run the following to apply the changes to the grub.cfg file

[root@localhost ~]$ grub2-mkconfig --output=/boot/grub2/grub.cfg

References:
http://dareneiri.github.io/Configuring-Grub-2-on-CentOS-7/

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

More Posts - Website

Follow Me:
TwitterFacebookLinkedInGoogle Plus

Avinash Pawar

DevOps Practitioner interested in learning new technologies and interested in sharing the knowledge with others.

Leave a Reply