🌐 🇵🇱 Polski · 🇬🇧 EN
GRUB (GRand Unified Bootloader) is a tool that allows you to select the system to be booted (if multiple are installed on a given machine). GRUB is divided into several stages. The code contained in the master boot record (master boot record - MBR) can be considered stage 1. The next stage, which can be labeled as 1.5, occurs when GRUB attempts to recognize the filesystem, which is optional, or it proceeds directly to stage 2. Stage 2 invokes the kernel and loads it into memory. In stage 1, GRUB must search the master boot record (MBR) for the active partition from which the kernel will be launched. GRUB has its own format for browsing hard drives, the syntax of which is as follows:
(xdn[,m])
Where xd- is the drive designation, n - is the drive number, and m- is the partition number of the drive. Knowledge of this syntax is very useful when troubleshooting GRUB, especially when you need to locate the primary partition of a drive. If the primary partition is found and GRUB loads the system kernel, it proceeds to stage 2, where most of the time is spent when troubleshooting system boot issues. After booting and reaching stage 2, a list of operating systems is displayed, allowing you to choose which system to start, along with a list of options that can be used to change the boot configuration of the given environment.
GRUB boot options:
- e - Edit commands before booting
- a - Append or modify kernel arguments before booting
- c - Start the GRUB command line
We use these options to modify any parameter we want to pass to the system kernel. In this way, you can change the runlevel in which the system is to be started. In the next part, more information about runlevels will be presented; for now, it is enough to know that there are different modes for starting the environment:
- Single-User-Mode - Used if you forget the root password
- Runlevel 2 or 3 - Used to load only partial services during boot
- Emergency Mode - Used to perform tasks on a non-booting system
- Rescue Mode - Used to fix boot issues or re-install GRUB
GRUB has only one main configuration file # /boot/grub/grub.conf . There are also two other files currently in the form of links to the main file, which are # /boot/grub/menu.lst and # /etc/grub.conf.
At boot time, GRUB reads the configuration in the main file. The grub.conf file can be edited from the GRUB command line, and after any changes, the machine must be restarted. Before the system is booted, you can view the configuration file, which is what was changed in RHEL6. For now, we will see what the older version of the # grub.conf file looks like.
Contents of grub.conf
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-71.el6.x86_64)
root (hd0,0)
kernel/vmlinuz-2.6.32-71.el6.x86_64 ro root=/dev/mapper/vg_rhel01-lv_root
rd_LVM_LV=vg_rhel01/lv_root rd_LVM_LV=vg_rhel01/lv_swap rd_NO_LUKS rd_NO_MD
rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc
KEYTABLE=us crashkernel=auto rhgb quiet
initrd /initramfs-2.6.32-71.el6.x86_64.img
Task 1
Enter the GRUB command line and find the drive and partition contained in the grub.conf file.
Ans: # grub> find /grub/grub.conf (result: (hd0,0) )
or # grub> root (result: (hd0,0): Filesystem type is unknown, partition type 0x8e )
Task 2
Install GRUB on the drive returned in Task 1.
Ans: # grub> setup (hd0) ( Result:
Checking if “/boot/grub/stage1” exists... no
Checking if “/grub/stage1” exists... yes
Checking if “/grub/stage2” exists... yes
Checking if “/grub/e2fs_stage1_5” exists... yes
Running “embed /grub/e2fs_stage1_5 (hd0)”... 26 sectors are
embedded.
Running “install /grub/stage1 (hd0) (hd0)1+26 p
(hd0,0)/grub/stage2
/grub/grub.conf”... succeeded
Done.
)
At this point, the MBR is changed, and after typing the command # grub> root, we will see the correct filesystem. It is also very important to have a backup of the grub.conf file so that it can be easily restored in case of problems.
Task 3
Change the "root" user password using the capabilities of GRUB and "Single-User-Mode".
Ans:
Useful links:
Task 3
Change the "root" user password using the capabilities of GRUB and "Single-User-Mode".
Ans:
- Enter GRUB (we have 5 seconds by default)
- Use the "a" option (press the "a" key) to add options before booting
- Where the cursor is, type a space and "s" or "single" ( <BOARDTYPE=pc KEYTABLE=us rd_NO_DM s ) then confirm with Enter.
- Use the "passwd" command to change the "root" user password
It may also happen that the "passwd" command does not change the password, which is caused by SELinux being enabled - you can check this by running the command: # getenforce and if it returns "Enforcing", you should deactivate SELinux with the command # setenforce 0 . After deactivation, we can check the status by running the command # getenforce again, which should result in "Permissive", at which point you can change the "root" password with the command # passwd
Useful links:

Comments