RHEL: Adding a boot entry to GRUB/GRUB2 configuration

# Tested on RHEL 6 & 7


# RHEL 6
# ------------------------------------------------------------------------------------------

# Adding a new entry to grub boot file is as simple as adding a new boot stanza, at the end
# of the file, to /boot/grub/grub.conf

# To modify the default boot entry, we have to change the 'default' option to point to the
# the new stanza. We can use entry position (zero-based numbering):


vi /boot/grub/grub.conf
[...]
default=1
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS (2.6.32-358.el6.i686)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.i686 ro root=/dev/mapper/rootvg-lv_root [...]
        initrd /initramfs-2.6.32-358.el6.i686.img
title CentOS - Backup ramdisk image
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.i686 ro root=/dev/mapper/rootvg-lv_root [...]
        initrd /initramfs-2.6.32-358.el6.i686.img.bak




# RHEL 7
# ------------------------------------------------------------------------------------------

# RHEL 7 uses grub2 and /boot/grub2/grub.cfg config file, instead of the old grub.conf
# format.

# The new grub.cfg file is not intended for direct editing. Rather we have to modify the
# source file and run the grub2-mkconfig command to generate it.

# The sources files are /etc/default/grub and the scripts under /etc/grub.d/

# If we want to add a new custom entry to boot menu, we have to add a boot stanza to
# /etc/grub.d/40_custom. These stanzas will look like this:

menuentry "CentOS - Backup ramdisk image" {
        load_video
        set gfxpayload=keep
        insmod gzio
        insmod part_msdos
        insmod ext2
        set root='hd0,msdos1'
        linux16 /vmlinuz-3.10.0-327.el7.i686 root=/dev/mapper/rootvg-lv_root ro crashkernel=auto [...]
        initrd16 /initramfs-3.10.0-327.el7.i686.img.bak
    }
menuentry "Another boot entry" {
        set root=(hd0,1)
        linux /vmlinuz-3.09-custom
        initrd /initrd-3.09-custom.img
    }

# To modify the default boot entry, we have to change the GRUB_DEFAULT option in
# /etc/default/grub to point to the new stanza we added. We can use entry position
# (zero-based numbering) or by name:

GRUB_DEFAULT="CentOS - Backup ramdisk image"

# or # GRUB_DEFAULT=2


# Default value of GRUB_DEFAULT is 'saved' which points to /boot/grub2/grubenv file.


# Once finished, we have to run following command in order to re-generate
# /boot/grub2/grub.cfg file:

grub2-mkconfig -o /boot/grub2/grub.cfg

0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Fix rpmdb: Thread died in Berkeley DB library
Viewed 20962 times since Fri, Feb 14, 2020
RHCS6: Show/Add GFS2/GFS journals
Viewed 12636 times since Sun, Jun 3, 2018
Use Fail2ban to Secure Your Server
Viewed 14578 times since Fri, Jul 5, 2019
Use inotify-tools on CentOS 7 or RHEL 7 to watch files and directories for events
Viewed 13946 times since Fri, Jul 27, 2018
Logrotate Example for Custom Logs
Viewed 2501 times since Sun, Jan 12, 2020
7 Tips – Tuning Command Line History in Bash
Viewed 5204 times since Fri, Jul 5, 2019
O’Reilly’s CD bookshelf
Viewed 12345 times since Wed, Jun 27, 2018
RHEL: XFS basic operations
Viewed 15876 times since Sat, Jun 2, 2018
How to manage Linux password expiry with the chage command
Viewed 11115 times since Tue, Sep 11, 2018
Create a Linux Swap File
Viewed 2927 times since Fri, Jun 8, 2018