Run Levels, Boot, Reboot, Shutdown
This article covers basic Linux run levels and boot, reboot and shutdown operations, with specific reference to the information needed for the RHCSA EX200 and RHCE EX300 certification exams.
Remember, the exams are hands-on, so it doesn’t matter which method you use to achieve the result, so long as the end product is correct.
The run level determines the mode of operation of the server. The “/etc/inittab” contains an explanation of the run levels (0-6).
# 0 - halt (Do NOT set initdefault to this) # 1 - Single user mode # 2 - Multiuser, without NFS (The same as 3, if you do not have networking) # 3 - Full multiuser mode # 4 - unused # 5 - X11 # 6 - reboot (Do NOT set initdefault to this)
You can display your previous and current run level using the
# runlevel N 5 #
init command is used to switch between run levels if you are already logged into the system.
# init 1 # runlevel 5 1 # # init 3 # runlevel S 3 #
telinit command will do the same thing.
For systems with X and a window manager (typically GNOME) installed, the default run level is usually 5, as shown in the “/etc/inittab” file.
To make the system automatically boot into a different run level, simply change this default in the “/etc/inittab” file. The following entry would make the system boot into run level 3.
Single User Mode
Single user mode is important because it gives you root access without needing the root password. This is very useful if you’ve forgotten, or don’t know, the root password and need root access. This sounds quite dangerous, but single user mode requires you to have direct console access, so provided the physical security of your data centre is good it shouldn’t be a problem.
Boot the server and press a key at the “Press any key to enter the menu” option.
At the GRUB screen, press the “e” key to edit the boot parameters.
Use the arrow keys to move the highlight down to the “kernel …” line and press the “e” key to edit it.
Add “ 1” onto the end of the line, then press the return/enter key to return to the previous screen with the amended values.
Press the “b” key to boot using the amended boot options.
The server will now boot into single user mode.
If you need to change the root password, issue the
# passwd Changing password for user root. New password: Retype new password: passwd: all authentication tokens updated successfully. #
You can now reboot, or use “
init 5” to switch to run level 5.
The process to perform an interactive startup is similar to that for single user mode, except you add the word “ confirm” to the line, rather than “ 1” for single user mode. During the startup you will be prompted to confirm the startup of each service.
Modify the Bootloader
If you need to permanently alter any of the kernel boot options, it can be done by editing the “/boot/grub/grub.conf” file. Below is an example from a test VM running Oracle Linux 6.2 (a RHEL clone).
# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a /boot partition. This means that # all kernel and initrd paths are relative to /boot/, eg. # root (hd0,0) # kernel /vmlinuz-version ro root=/dev/mapper/vg_rhce1-lv_root # initrd /initrd-[generic-]version.img #boot=/dev/vda default=0 timeout=5 splashimage=(hd0,0)/grub/splash.xpm.gz hiddenmenu title Oracle Linux Server-uek (2.6.32-300.3.1.el6uek.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-300.3.1.el6uek.x86_64 ro root=/dev/mapper/vg_rhce1-lv_root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=uk LANG=en_US.UTF-8 rd_LVM_LV=vg_rhce1/lv_root rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb rd_NO_DM rd_LVM_LV=vg_rhce1/lv_swap initrd /initramfs-2.6.32-300.3.1.el6uek.x86_64.img title Oracle Linux Server (2.6.32-220.el6.x86_64) root (hd0,0) kernel /vmlinuz-2.6.32-220.el6.x86_64 ro root=/dev/mapper/vg_rhce1-lv_root rd_NO_LUKS KEYBOARDTYPE=pc KEYTABLE=uk LANG=en_US.UTF-8 rd_LVM_LV=vg_rhce1/lv_root rd_NO_MD quiet SYSFONT=latarcyrheb-sun16 rhgb crashkernel=auto rd_NO_DM rd_LVM_LV=vg_rhce1/lv_swap initrd /initramfs-2.6.32-220.el6.x86_64.img
The modifications you are most likely to be asked to do are to alter the “timeout” and “default” attributes.
The “timeout” attribute indicates how many seconds the boot process will wait before starting the boot process. This is handy because it allows you to stop the boot process and manually amend the boot options. This is necessary if you need to enter single user mode on the fly to change the root password.
The “default” parameter indicates which kernel to boot. In the above example, there are two kernel versions present. The setting “default=0” indicates the first (top) one will be used unless altered interactively during the boot process. To use the second kernel version instead, change the setting to “default=1”.
GRUB2 is used in later Fedora releases. The “/boot/grub2/grub.cfg” file holds the GRUB2 configuration.
Power on a physical box, or click the “Power on the virtual machine” button on for VMs in the Virtual Machine Manager console.
Any of the following commands will reboot the system from the command line.
# reboot # shutdown -r now # init 6
Either of the following commands will shut down the system from the command line.
# shutdown -h now # init 0
For more information see:
Leave a comment