CentOS 8 Essentials
上QQ阅读APP看书,第一时间看更新

4.2 Editing the CentOS 8 Boot Menu

Once installation of CentOS onto the disk is complete and the system has restarted, the standard CentOS boot menu will appear:

Figure 4-4

At this point, the boot menu only provides the option to boot the CentOS 8 system. Clearly an option also needs to be added so that the Windows system is still accessible. These steps will need to be taken from within the CentOS 8 system, so start the system and log in as root.

The first step is to identify the Windows boot partition on the disk drive using the fdisk command as follows:

# fdisk -l

.

.

Device Boot Start End Sectors Size Id Type

/dev/sda1 * 2048 1126399 1124352 549M 7 HPFS/NTFS/exFAT

/dev/sda2 1126400 53655551 52529152 25G 7 HPFS/NTFS/exFAT

/dev/sda3 53655552 55752703 2097152 1G 83 Linux

/dev/sda4 55752704 104857599 49104896 23.4G 5 Extended

/dev/sda5 55754752 104857599 49102848 23.4G 8e Linux LVM

In the above output /dev/sda3 through to /dev/sda5 are clearly the CentOS 8 partitions. The smaller /dev/sda1 partition is the Windows system partition, leaving /dev/sda2 as the Windows boot partition.

The CentOS 8 boot system works using partition indexes where the first partition is partition 0, the second is partition 1 and so on. As such, the Windows boot partition from the point of view of the boot menu is located on hard disk 0 at partition index location 1 and is defined in the boot configuration as “hd0,1”.

The boot menu configuration settings are stored in the /boot/grub2/grub.cfg file which is generated using the grub2-mkconfig tool based on the content of the configuration files located in the /etc/grub.d directory. To add the Windows boot option to the configuration, edit the /etc/grub.d/40_custom file which should read as follows:

#!/bin/sh

exec tail -n +3 $0

# This file provides an easy way to add custom menu entries. Simply type the

# menu entries you want to add after this comment. Be careful not to change

# the ‘exec tail’ line above.

Edit the file to add the following entry to the end of the 40_custom file:

menuentry "Windows 10" {

         set root=(hd0,1)

         chainloader +1

         }

Save the file and generate the boot menu as follows:

# grub2-mkconfig --output=/boot/grub2/grub.cfg

Generating grub configuration file ...

done

On the next reboot, Windows will now be included as a boot option as shown in Figure 4-5:

Figure 4-5