Configuring GRUB2
You can run one of two commands at the shell prompt (as root) to see which version of GRUB your particular Linux system is using:
•grub-install –v
•grub2-install -v
GRUB2 uses a completely different set of configuration files as compared to the GRUB Legacy bootloader. Here are the configuration files used by GRUB2:
•/boot/grub/grub.cfg file
•/etc/grub.d directory
•/etc/default/grub file
On some distributions, the grub.cfg file is located in /boot/grub instead of /boot/grub2
However, unlike the menu.lst file, grub.cfg is automatically updated every time you make a configuration change and then run one of the following commands:
•update-grub
•grub2-mkconfig -o /boot/grub2/grub.cfg
You have to run update-grub or grub2-mkconfig after making any configuration changes to the GRUB2 bootloader. They will not take effect until this has been done.
Even though grub.cfg is somewhat analogous to menu.lst, it doesn’t actually contain the GRUB2 menu information. Instead, it is stored in several configuration files within the /etc/grub.d directory. All the files within /etc/grub.d are executable script files. If you make changes to one of these files and then run the update-grub or grub2-mkconfig command, the grub.cfg file is automatically updated with the new GRUB settings. So, in summary, the /etc/default/grub file contains the GRUB menu configuration settings, but the script files in /etc/grub.d are the ones you actually edit to make any changes.
Grub2
hd0,1
If you were to view the contents of the grub.cfg file, you would see that it’s divided up into many sections. Each section begins with the text ###BEGIN.
Each of the sections references a particular script in the /etc/grub.d directory from which it was generated by the update-grub or the grub2-mkconfig command. When you look at the files within /etc/grub.d, you’ll see that they typically begin with a numeral, as shown here:
openSUSE:/etc/grub.d # ls
00_header 20_linux_xen 20_ppc_terminfo 40_custom 90_persistent10_linux 20_memtest86+ 30_os-prober 41_custom README
This naming convention is important because the placement of the menu items within the grub.cfg file is determined by the numeric order of the script file names within /etc/grub.d. The lowest-numbered files are executed first by the update-grub or grub2-mkconfig command. So in this example, 00_header would be run first, 10_linux would be run second, and so on. Any script files using nonnumeric files names will not be run until after all the numerically named files are run first. This then influences the order in which the information from these script files appears within /boot/grub2/grub.cfg.
00_header:
This file configures various parameters for the GRUB2 boot menu, such as the initial appearance, the graphics mode, the default selection, timeout values, and so on.
10_linux:
This file identifies each of the Linux kernels that have been installed on the system. If you have multiple kernels installed, the 10_linux script will search within your boot folder and locate any installed Linux kernels. For each one it finds, it will create a separate GRUB menu entry.
30_os-prober:
This script searches for any other operating systems that may be installed on your system. If you just have Linux installed, this script will locate your Linux kernel and create a menu entry for it. However, if you have Linux and Windows installed on the same system, 30_os-prober will identify Linux as well as the Windows operating system that has been installed and automatically create a GRUB menu entry for each.
40_custom:
This file is designed for you to use to customize the behavior of the GRUB menu. Basically, it’s a template for adding custom menu entries that will be inserted into the grub.cfg file.
Finally, we need to look at the /etc/default/grub configuration file. This file contains information that used to be contained in the upper section of the original GRUB Legacy menu.lst file, as shown here:
openSUSE:/etc/grub.d # cat /etc/default/grub
GRUB_DISTRIBUTOR="openSUSE 13.1"
GRUB_DEFAULT=saved
GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=8
You can go ahead and edit this file and make whatever changes you need to and have those changes incorporated into grub.cfg when you run the update-grub or grub2-mkconfig command. Within this file are several different parameters you can use to change the way GRUB behaves and looks:
•GRUB_DEFAULT:
This parameter sets the default menu entry. For example, if you were to configure grub_default=0, the first menu entry becomes the default menu entry. If you have a timer set and no selection is made by the user, the first menu entry will be automatically selected. You can specify either an entry number or an entry title.
•GRUB_SAVED DEFAULT:
If you set this parameter to true, GRUB will automatically select the last selected operating system from the menu as the default operating system to be used on the next boot. As you can see, this parameter could potentially conflict with the grub_default parameter. Therefore, you can use either one, but not both.
•GRUB_HIDDEN_TIMEOUT:
The grub_hidden_timeout parameter can be used to cause the boot process to pause and display a blank screen (or a splash image if you configure it to do so) for a specified number of seconds. After the end of the timeout period, the system will boot. The grub_hidden_timeout parameter determines how long (in seconds) the blank screen will be displayed. While the screen is blank, the user can press the shift key to display the menu. If you don’t want them to have that option, set this parameter to a value of zero. If you set this to a null value, the menu will be displayed for the number of seconds configured by the grub_timeout parameter.
•GRUB_HIDDEN_TIMEOUT_QUIET:
This parameter works in conjunction with the grub_hidden_timeout parameter. If it is set to true, no countdown is displayed. If it is set to false, a counter will be displayed on the blank screen for the duration of the value specified for grub_hidden_timeout.
•GRUB_TIMEOUT:
This parameter specifies how long (in seconds) the user has to make a menu selection from the GRUB menu before the default operating system is booted. If you set this to a value of −1, the timer is disabled and GRUB will wait until the user makes a selection.
•GRUB_CMDLINE_LINUX:
This parameter is used to pass options to the kernel. With the GRUB Legacy bootloader, this was done by adding options to the end of the kernel line. You can do the same thing in GRUB2 using the grub_command line_Linux parameter.
•GRUB_GFX MODE:
This parameter sets the resolution of the graphical menu displayed by GRUB2. You can also append a color depth, if needed. For example, if you wanted the grub menu to use a screen resolution of 1440×900 and to use 24-bit color depth, you would set this parameter to a value of 1440×900×24. You can actually specify multiple resolutions with this parameter. List your preferred screen resolution first, then a comma, then the second one, and then a comma, and so on. GRUB2 will try to use the first resolution first. If the resolution is supported by the video display, it will be used and the others will be ignored. If it is not supported, GRUB will move on to the second resolution, and it will keep working its way down the list until it finds one that it can use. If this parameter is commented out, or if the resolution specified isn’t supported, GRUB2 will use the default graphic mode setting specified in the /etc/grub.d/00_header file.
•GRUB_INIT_TUNE:
You can use this parameter to play a single beep just prior to the GRUB2 menu being displayed. The syntax is to put an equal sign and then a quotation mark and then three numbers. The first number is the tempo to be used. The second number is the pitch of the tune. The third number is the duration of the tune. End the parameter with a closing quotation mark.
•GRUB_BACKGROUND:
This parameter sets the background image used by the GRUB2 menu.
•GRUB_DISABLE_OSPROBER:
Setting this parameter to a value of true will then disable the osprober check. This functionality looks for partitions on the hard drive that have other operating systems, such as Windows or other Linux distributions.
Showing posts with label bootloader. Show all posts
Showing posts with label bootloader. Show all posts
Tuesday, August 23, 2016
Grub Legacy Bootloader
How GRUB Legacy WorksThe GRUB Legacy bootloader is divided into separate chunks called stages. These include the following:
•Stage 1: This stage of GRUB is usually stored in the MBR. Its only real job is to point to the location of Stage 1.5 or Stage 2.
•Stage 1.5: This stage of GRUB is located in the first 30KB of the hard drive immediately after the MBR, but before the first partition. Stage 1.5 contains any drivers needed to load Stage 2.
•Stage 2: This stage of GRUB is stored in a disk partition. When loaded by Stage 1 or Stage 1.5, Stage 2 presents a graphical menu on the screen that allows the user to select the kernel image that should be loaded. You can configure GRUB with a default image and a timeout value. If the user doesn’t select an option within the timeout period, the system will automatically boot the default kernel image.
Installing GRUB Legacy
>rpm -q grub
>grub-install /dev/sda
Configuring GRUB
/boot/grub/
/boot/grub/grub.conf OR /boot/grub/menu.lst
One or more title sections that are used to launch a specific operating system
GRUB: hd0,0
Boot Options field
You can use this field to send boot options to the Linux kernel that are not contained in a GRUB menu item to customize the way the kernel will function.
>init=program_name
>init=/bin/bash
When you boot the system, the bash shell is loaded and you have full root-level access to the system, allowing you to diagnose and repair whatever is keeping the system from booting normally. You won’t be prompted to provide your root password. Because of this, you can use this technique to rescue a system if you’ve forgotten its root user’s password.
To increase the security of the GRUB menu
The simplest way to do this is to edit your GRUB configuration file (menu.lst or grub.conf ) and enter the following:
password password
Here’s an example:
password natasha01
When GRUB is configured this way, users can still select any menu item they want without the password, but editing any GRUB menu item will require them to enter the password you specified. If you want to require users to enter the password before they can select a menu item too, you need to add the lock parameter within the appropriate title elements in the GRUB configuration file:
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate
password natasha01
###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.3 - 2.6.34-12
lock
root (hd0,1)
kernel /boot/vmlinuz-2.6.34-12-desktop root=/dev/sda2 resume=/dev/sda1
splash=silent quiet showopts vga=0x317
initrd /boot/initrd-2.6.34-12-desktop
If you want to define different passwords for each GRUB menu item, you can place passwordpassword directives within each title element.
1.Open a terminal session and switch to root.
2.At the shell prompt, enter grub-md5-crypt.
3.When prompted, enter the password you want to assign to the GRUB menu.When complete, the hashed form of the password is displayed on the screen. An example follows:
fs2:~ # grub-md5-crypt
Password:
Retype password:
$1$WLZwz/$DP3wgbtInP1KJOL.Wg3t00
4.Open the GRUB configuration file in a text editor.
5.In the GRUB configuration file, enter password --md5hashed_password. Here is an example:
password --md5 $1$WLZwz/$DP3wgbtInP1KJOL.Wg3t00
6.Save your changes to the file and reboot the system.
•Stage 1: This stage of GRUB is usually stored in the MBR. Its only real job is to point to the location of Stage 1.5 or Stage 2.
•Stage 1.5: This stage of GRUB is located in the first 30KB of the hard drive immediately after the MBR, but before the first partition. Stage 1.5 contains any drivers needed to load Stage 2.
•Stage 2: This stage of GRUB is stored in a disk partition. When loaded by Stage 1 or Stage 1.5, Stage 2 presents a graphical menu on the screen that allows the user to select the kernel image that should be loaded. You can configure GRUB with a default image and a timeout value. If the user doesn’t select an option within the timeout period, the system will automatically boot the default kernel image.
Installing GRUB Legacy
>rpm -q grub
>grub-install /dev/sda
Configuring GRUB
/boot/grub/
/boot/grub/grub.conf OR /boot/grub/menu.lst
One or more title sections that are used to launch a specific operating system
GRUB: hd0,0
Boot Options field
You can use this field to send boot options to the Linux kernel that are not contained in a GRUB menu item to customize the way the kernel will function.
>init=program_name
>init=/bin/bash
When you boot the system, the bash shell is loaded and you have full root-level access to the system, allowing you to diagnose and repair whatever is keeping the system from booting normally. You won’t be prompted to provide your root password. Because of this, you can use this technique to rescue a system if you’ve forgotten its root user’s password.
To increase the security of the GRUB menu
The simplest way to do this is to edit your GRUB configuration file (menu.lst or grub.conf ) and enter the following:
password password
Here’s an example:
password natasha01
When GRUB is configured this way, users can still select any menu item they want without the password, but editing any GRUB menu item will require them to enter the password you specified. If you want to require users to enter the password before they can select a menu item too, you need to add the lock parameter within the appropriate title elements in the GRUB configuration file:
##YaST - generic_mbr
gfxmenu (hd0,1)/boot/message
##YaST - activate
password natasha01
###Don't change this comment - YaST2 identifier: Original name: linux###
title Desktop -- openSUSE 11.3 - 2.6.34-12
lock
root (hd0,1)
kernel /boot/vmlinuz-2.6.34-12-desktop root=/dev/sda2 resume=/dev/sda1
splash=silent quiet showopts vga=0x317
initrd /boot/initrd-2.6.34-12-desktop
If you want to define different passwords for each GRUB menu item, you can place passwordpassword directives within each title element.
1.Open a terminal session and switch to root.
2.At the shell prompt, enter grub-md5-crypt.
3.When prompted, enter the password you want to assign to the GRUB menu.When complete, the hashed form of the password is displayed on the screen. An example follows:
fs2:~ # grub-md5-crypt
Password:
Retype password:
$1$WLZwz/$DP3wgbtInP1KJOL.Wg3t00
4.Open the GRUB configuration file in a text editor.
5.In the GRUB configuration file, enter password --md5hashed_password. Here is an example:
password --md5 $1$WLZwz/$DP3wgbtInP1KJOL.Wg3t00
6.Save your changes to the file and reboot the system.
Subscribe to:
Posts (Atom)