

How to reset the root password and boot management
Sep 28, 2024
2 min read
4
85
0
It's essential for the RHCSA exam to be able to reset the root password and boot into different Systemd targets.

GRUB
The location of Grub depends upon if you boot using BIOS system or en EFI system. To know if you are on a BIOS or EFI system. dmesg | grep "EFI". If you get nothing you booted using BIOS. You can dmesg | grep "BIOS" just to be sure.
Another way is to use lsblk and if your boot disk is mounted on "/boot" than you are using BIOS. If it says "/boot/efi". You guessed it, you are using EFI. :)
You need to edit the configuration file in "/etc/default/grub" to make changes persistent. Afterwards you must compile the changes to grub.cfg. You cannot edit that file directly.
FOR BIOS/MBR
To make static changes to Grub edit "/etc/default/grub". Commit the changes you make. grub2-mkconfig -o /boot/grub2/grub.cfg
FOR EFI
To make static changes to Grub edit "/etc/default/grub". Commit the changes you make. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
SYSTEMD TARGETS
Used for troubleshooting in a minimal environment.
Also used for troubleshooting but not in a minimal environment.
The default environment, without a GUI.
A fully functioning target like multi-user.target but with a GUI.
To know what target you are in do systemctl get-default. You can also do systemctl list-dependencies. It lists first the target you are running and it's dependencies.
CHANGE THE DEFAULT SYSTEMD TARGET
Let's set the default to a non GUI target. systemctl set-default multi-user.target You must reboot the machine to enter the new default target.
CHANGE A RUNNING TARGET
Let's say we are running in a multi-user.target (GUI) and we want to switch to a non-graphical target we run this command. systemctl isolate multi-user.target. Once we are done and we want to get back to the GUI we issue systemctl set-default multi-user.target
CHANGE A TARGET DURING BOOT IN GRUB
Add this the end of the linux line. systemd.unit=emergency.target You can use any of the targets I listed before instead of emergency.
DEBUG SHELL
How to use early boot debug shell:
systemctl enable --now debug-shell.service
During boot you can access the virtual terminal on TTY9. (Ctrl-Alt-F9)
Enter a root shell without entering a password
When you have finished using it you should disable the service right away. systemctl disable --now debug-shell.service
RESET THE ROOT PASSWORD
Find the line that loads the Linux kernel and add init=/bin/bash to the end of the line.
mount -o remount,rw / This is necessary because it's mounted as read-only.
passwd root
touch /.autorelabel
exec /usr/lib/systemd/systemd/ To reboot the machine or /sbin/reboot -f