Configure grub2 for installed distros.

GRUB2 configuration files are located in three places:

/boot/grub/
- This is the main grub2 installation directory with gurb.cfg a replace of grub legacy menu.lst.
/etc/default/grub
- This is the file where we can configure the grub2 boot menu, like color, timeout and etc.
/etc/grub.d/
- This directory contains grub2 scripts for each linux or windows distro, here we can add remove or change distro showing order in the grub2 boot menu.
These are scripts in thid dir:
00_header
is the script that loads GRUB settings from /etc/default/grub, including timeout, default boot entry, and others.
05_debian_theme
defines the background, colors and themes. The name of this script is definitely going to change to when other distributions adopt GRUB 2.
10_linux
loads the menu entries for the installed distribution.
20_memtest86+
loads the memtest utility.
30_os-prober
is the script that will scan the hard disks for other operating systems and add them to the boot menu.
40_custom
is a template that you can use to create additional entries to be added to the boot menu.
Add new grub2 boot script for distro to boot
To add a new boot option create a new file that has a XX_ prefix in the name, where XX is a sequence of numbers.
The next step is to write the actual content. Here's a sample:
#!/bin/sh
exec tail -n +3 $0
menuentry "Something" {
set root=(hdX,Y)
-- boot parameters --
}
menuentry "Something"
is the name that will show in the menu. Example: Linux.
set root=(hdX,Y)
- we're back to old school, setting the root device.

NOTE: Critical! GRUB 2 uses PARTITION notation that starts with 1 and not 0 like GRUB legacy! This is terribly important to remember, but devices are still numbered from 0.

-- boot parameters --
will really change from one OS to another. In Linux, you may want to use something like:
linux /boot/vmlinuz
initrd /boot/initrd.img
But in Windows, you would probably use:
chainloader (hdX,Y)+1
Therefore, a complete script example would look something like this for ubuntu:
#!/bin/sh
exec tail -n +3 $0
menuentry 'Ubuntu' --class ubuntu --class gnu-linux --class gnu --class os $menuentry_id_option 'gnulinux-simple-de3a9c7e-546d-47d0-b485-183c82a927ec' {
        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,msdos3'
        if [ x$feature_platform_search_hint = xy ]; then
          search --no-floppy --fs-uuid --set=root --hint-bios=hd0,msdos3 --hint-efi=hd0,msdos3 --hint-baremetal=ahci0,msdos3  de3a9c7e-546d-47d0-b485-183c82a927ec
        else
          search --no-floppy --fs-uuid --set=root de3a9c7e-546d-47d0-b485-183c82a927ec
        fi
        linux   /boot/vmlinuz-4.13.0-36-generic root=UUID=de3a9c7e-546d-47d0-b485-183c82a927ec ro  quiet splash $vt_handoff
        initrd  /boot/initrd.img-4.13.0-36-generic
}
Download files 08_windows, put the file in /etc/grub.d, will put the windows in first of grub2 boot menu.
For the changes to take effect run the command:
update-grub2
If you install or remove the os, this command will automatically add this new os:
os-prober
when you install the grub2 on legacy grub run this command to change to the grub2:
upgrade-from-grub-legacy


<< Previous Next >>