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

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

  • Boot into CentOS 7.

  • Determine what partition your Windows OS resides on by running sudo fdisk -l in Terminal.
[pastacode lang=”bash” manual=”Disk%20%2Fdev%2Fsda%3A%20320.1%20GB%2C%20320072933376%20bytes%2C%20625142448%20sectors%0A%20Units%20%3D%20sectors%20of%201%20*%20512%20%3D%20512%20bytes%0A%20Sector%20size%20(logical%2Fphysical)%3A%20512%20bytes%20%2F%20512%20bytes%0A%20I%2FO%20size%20(minimum%2Foptimal)%3A%20512%20bytes%20%2F%20512%20bytes%0A%20Disk%20label%20type%3A%20dos%0A%20Disk%20identifier%3A%200xcd8b1219″ message=”Linux” highlight=”” provider=”manual”/] [ad type=”banner”] [pastacode lang=”bash” manual=”%20Device%20Boot%20%20%20%20%20%20%20%20%20%20Start%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20%20%20%20%20%20%20%20%20%20%20%20%20%20Blocks%20%09%20%20Id%20%20%09System%0A%20%2Fdev%2Fsda1%20%20%20*%20%20%20%20%20%20%20%202048%20%20%20%20%20%20%20%20%20%204194303%20%20%20%20%20%20%202096128%20%20%20%09%207%20%20%09HPFS%2FNTFS%2FexFAT%0A%20%2Fdev%2Fsda2%20%20%20%20%20%20%20%20%204194304%20%20%20%20%20%20360402758%20%20%20178104227%2B%20%20%20%20%20%20%20%20%20%20%207%20%20%20%20%20%20%20%20%20%20%20%20%20%20HPFS%2FNTFS%2FexFAT%0A%20%2Fdev%2Fsda3%20%20%20%20%20%20%20360402942%20%20%20625141759%20%20%20132369409%20%20%20%20%20%20%20%20%20%20%20%20%20%205%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Extended%0A%20%2Fdev%2Fsda5%20%20%20%20%20%20%20612595712%20%20%20625141759%20%20%20%20%206273024%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2082%20%20%20%20%20%20%20%20%20%20%20Linux%20swap%20%2F%20Solaris%0A%20%2Fdev%2Fsda6%20%20%20%20%20%20%20360407040%20%20%20361431039%20%20%20%20%20%20512000%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2083%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Linux%0A%20%2Fdev%2Fsda7%20%20%20%20%20%20%20361433088%20%20%20612589567%20%20%20125578240%20%20%20%20%20%20%20%20%20%20%20%20%20%208e%20%20%20%20%20%20%20%20%20%20%20%20%20Linux%20LVM%0A” message=”Linux” highlight=”” provider=”manual”/]

In this example, /dev/sda1 is the recovery partition, and /dev/sda2 is the Windows OS partition. Since partition indexes start at zero, the Windows OS partition will be `hd0,1` (a = 0, 2 = 1; or first disk, second partition) when we edit the Grub file. Make note of this.

  • Open a terminal and navigate to /etc/grub.d/:
[pastacode lang=”bash” manual=”cd%20%20%2Fetc%2Fgrub.d%2F” message=”Linux” highlight=”” provider=”manual”/]

  • Edit the 40_custom file. You may not see the file if you ls in /grub.d/.
[pastacode lang=”bash” manual=”sudo%20nano%2040_custom” message=”Linux” highlight=”” provider=”manual”/]

  • You should see the following in the nano text editor:
[pastacode lang=”bash” manual=”%23!%2Fbin%2Fsh%0A%20exec%20tail%20-n%20%2B3%20%240%0A%20%23%20This%20file%20provides%20an%20easy%20way%20to%20add%20custom%20menu%20entries.%20%20Simply%20type%20the%0A%20%23%20menu%20entries%20you%20want%20to%20add%20after%20this%20comment.%20%20Be%20careful%20not%20to%20change%0A%20%23%20the%20’exec%20tail’%20line%20above.%0A” message=”Linux” highlight=”” provider=”manual”/]

  • Below the last #, type on a new line:
[pastacode lang=”bash” manual=”menuentry%20%22Windows%207%22%20%7B%0A%20%20%20%20%20%20%20%20%20set%20root%3D(hd0%2C1)%0A%20%20%20%20%20%20%20%20%20chainloader%20%2B1%0A%20%20%20%20%20%20%20%20%20%7D%0A” message=”Linux” highlight=”” provider=”manual”/] [ad type=”banner”]

  • Finally, run the following to apply the changes to the grub.cfg file:
[pastacode lang=”bash” manual=”grub2-mkconfig%20–output%3D%2Fboot%2Fgrub2%2Fgrub.cfg” message=”Linux code” highlight=”” provider=”manual”/]
  • Once you reboot, you should see the option of booting into Windows 7.
  • If a default boot entry into Windows (or something else) is requested, then you need to edit the GRUB_DEFAULT in /etc/default/grub:
[pastacode lang=”bash” manual=”GRUB_DEFAULT%3D%22Windows%207%22″ message=”Linux Code” highlight=”” provider=”manual”/]

Categorized in: