top of page

How to reset the root password and boot management

a day ago

2 min read

1

6

0



It's essential for the RHCSA exam to be able to reset the root password and boot into different Systemd targets.

Linux boot order

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


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:

  1. systemctl enable --now debug-shell.service

  2. During boot you can access the virtual terminal on TTY9. (Ctrl-Alt-F9)

  3. Enter a root shell without entering a password

  4. When you have finished using it you should disable the service right away. systemctl disable --now debug-shell.service


RESET THE ROOT PASSWORD

  1. Find the line that loads the Linux kernel and add init=/bin/bash to the end of the line.

  2. mount -o remount,rw / This is necessary because it's mounted as read-only.

  3. passwd root

  4. touch /.autorelabel

  5. exec /usr/lib/systemd/systemd/ To reboot the machine or /sbin/reboot -f

Related Posts

Comments

Share Your ThoughtsBe the first to write a comment.
bottom of page