In this laboratory you will exercise working with GRUB, system shutdown and restart, /proc filesystem and Kernel runtime parameters.


Lab 1.1 Booting the system

Lab objective 1: Shutdown, halt, reboot

Lab objective 2: Booting into non-graphical mode from GRUB

Lab 1.2 Change Kernel runtime parameters

Lab objective 3: Working with the /proc filesystem

Lab objective 4: Change Linux Kernel runtime parameters

Lab objective 5: Recover your root password during GRUB initialization


Laboratory objective 1: Shutdown vs. halt vs. reboot

Commands used: shutdown


1 Boot up the system. By default it will boot into Graphical mode. Open a terminal and reboot the system from the console using the command:

sudo shutdown -r now

2 After reboot, do the same as in previous exercise and now execute the command:

sudo shutdown -h now



Laboratory objective 2: Booting into non-graphical mode from GRUB


For the purpose of this exercise, I strongly recommend testing on a virtual machine, not on a live system. My solution is given on a openSUSE Leap system inside a virtual machine.

1 boot the system and when GRUB is loading, hit the key “e” on your keyboard. This will get you into editing the GRUB file.

2 find the line in the file that says: linux /boot/vmlinuz-4.4.76-1-default root=UUID=d8bba85c-d1ec-4b77-814a-7210fcd22113fd ${extra_cmdline} resume=/dev/sda1 splash=silent quiet showopts - NOTE: your line could be different depending on the system, but what is important is to find the exact line that consists of the string: “splah=silent quiet” or something like this.

3 set your cursor on that line and insert a “3” after the string quiet, so that it will look like this:

splah=silent quiet 3 showopts

The number 3 comes from init3, which represents the command mode specific runlevel.

NOTE: if you are working on a Debian based system (like Ubuntu, Debian or Mint) you should use runlevel 2 instead of 3, as runlevels 3,4 and 5 are not used by Debian based distros, compared to the rpm based ones like CentOS and OpenSUSE.

4 now press Ctrl-x or F10 to continue to boot your system. Now it will boot in console mode, not Graphical mode.

5 to get back to your graphical mode, you should use one of the following commands, depending on your Graphical Environment. In my case, on that virtual machine, openSUSE is running with XFCE, so I will have to do:

sudo systemctl start lightdm

lightdm is the default display manager for XFCE

If you have another graphical environment, you should use:

sudo systemctl start gdm - for standard GNOME sudo systemctl start lightdm - for Ubuntu running Unity sudo systemctl start mdm - for MATE and Cinnamon (in case of Mint) sudo systemctl start kdm - for KDE



Laboratory objective 3: Working with the /proc filesystem

Commands used: sysctl, less, wc



1 explore the /proc filesystem - it represents the default method to handle processes and system information. /proc/sys is the place where you find information about your system devices, drivers and kernel features.

2 to modify the kernel runtime parameters you will use the sysctl command. Use the -a option to see the complete list of Kernel parameters. Use it with a pipe to less, as the output is very large…

sudo sysctl -a | less

2 to view the number of parameters that can be modified can be viewed with the command:

sudo sysctl -a | wc -l

My output is:

alexandru@linux-vje9:~> sudo sysctl -a | wc -l

3 analyze a specific line, for example: = drive name: sr0

this indicates that sr0 (srzero) is an alias for the optical drive and that the kernel knows the drive as sr0 and uses that name to refer to it.



Laboratory objective 4: Change and modify Linux Kernel runtime parameters

Commands used:cd, sysctl, echo



The name of a parameter matches the directory structure inside /proc/sys.

1 this is a test on some of the parameters, to see how the sysctl output relates to the /proc/sys/ directory

alexandru@linux-vje9:~> cd /proc/sys
alexandru@linux-vje9:/proc/sys> ls
abi debug dev fs kernel net vm
alexandru@linux-vje9:/proc/sys> sudo sysctl dev.cdrom.autoclose
[sudo] password for root:
dev.cdrom.autoclose = 1
alexandru@linux-vje9:/proc/sys> cat /proc/sys/dev/cdrom/autoclose
alexandru@linux-vje9:/proc/sys> sudo sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0
alexandru@linux-vje9:/proc/sys> cat /proc/sys/net/ipv4/ip_forward

2 modify the Linux Kernel parameters by using the sysctl command, with the -w option, the parameters name, the equal sign and the value to be changed. For example:

sudo sysctl -w net.ipv4.ip_forward=1

3 try the same with the echo command and redirection:

echo 0 > /proc/sys/net/ipv4/ip_forward




Laboratory objective 5: Recover your root password during GRUB initialization

Problem: you forgot your root password and need to recover your system.



This exercise has been tested on a CentOS 7 system and is proven to work on any RHEL 7 / CentOS 7 / Fedora system. Test it on others, like Debian or Ubuntu, at your own risk.

1 At boot time, you will need to interrupt the boot process by pressing any key during GRUB initialization and Kernel selection. You have that shown on the image below.

grub1 The GRUB Kernel selection screen

2 After you select the desired Kernel version, you have to hit e to edit the GRUB file. When you do that, then you will be entered inside that file. Then go to the line that starts with linux16, hit the end key and add the text rd.break at the end of the line, as shown below.

grub2 Adding the rd.break at the end of the Linux Kernel line

3 Then you hit ctrl+x and boot into the initramfs shell, which will let you change the password as we will see in the following lines.

grub3 The initramfs shell

4 Now that you are inside the initramfs shell, you will have to issue the following commands. Be extra careful about those and try not to brake anything.

The first command is:

mount -oremount,rw /sysroot

This is the very first step, to remount the sysroot directory as read-write with the -o options flag followed (without any spaces) by the remount,rw options. This will ensure that you will be able to use the passwd command in order to change your root password and edit the contents of the /etc/passwd file.

The second command is:

chroot /sysroot

This command will mount the /sysroot directory as root directory using the change root command, know as chroot. Next, your shell prompt will change and the /sysroot directory will now act as the root directory.

The third command is:

passwd root

This is the passwd command that will let you change the root password. Next you will be prompted to enter the new password twice.

The fourth command is:

touch /.autorelabel

This command will make sure that SELinux context will be updated. For this, the .autorelabel file is needed, in order for SELinux to relabel all the files, making that the password file /etc/passwd change to be successful.

Next you will have to exit the chroot shell and then the initramfs shell by issuing two succesive exit commands. This will logout and restart the system.

All the commands needed for this process are shown in the image below.

grub5 The commands for the password change process

After restart, boot into your normal interface and test to see if the new password is working.