Kernel Management

Learn about kernel.

The Linux kernel is the heart of the operating system. It is the layer between the user who works with Linux from a shell environment and the hardware that is available in the computer on which the user is working.

Basic Kernel Management :

  • modprobe <module-name> -> to manually load a kernel module.

  • modprobe -r <module-name> -> to manually unload a kernel module.

  • modinfo <module-name> to list parameters that a module support

  • Module params can be edited under /etc/modprobe.d/

  • the /proc directory provides a UI to the kernel.

  • sysctl -a to dump all kernels tunables

Updating & Installing Kernel :

  • Updating and installing kernels is one of the most common question that comes in RHCSA 8, lets learn how to update and install new kernel and set it as the default. Lets start with updating.

  • uname -r > to get info about the current kernel version.

  • yum list kernel --showduplicates

  • yum update kernel => should end up creating a vmlinuz file.

  • rpm -ql kernel | grep "/boot/vmlinuz

  • if it doesn't exist then simple insert this command "dracut"

  • yum list kernel, Now we are done lets move forward and learn how to install a kernel and set is the default kernel while booting.

Installing Kernel

  • yum install kernel

  • grubby --info=ALL -> the one with index 0 is the default kernel.

  • grubby --set-default-index 0

  • or grub2-set-default 0 -> will set the most recent kernel as the default

  • grub2-set-default 1 -> will set the second most recent kernel as the default.

  • reboot to verify.

Setting the pervious kernel as the default

  • uname -r -> confirming the default kernel the system is using.

  • rpm -qa kernel -> confirming the kernels installed.

  • grubby --info=ALL

  • grubby --default-index

  • cp /boot/grub2/grub.cfg /boot/grub2/grub.cfg_backup -> creating a backup

  • grubby --set-default-index=1

  • grubby --default-index to confirm

  • grub2-mkconfig -o /boot/grub2/grub.cfg

  • reboot to confirm.

Modifying grub :

  • vim /etc/default/grub <-> then deleting "rhgb" and "quite". -> by doing this, all the boot messages on the screen will be shown while booting.

  • Add biosdevname=0 add net.ifnames=0 to variable GRUB_COMDLINE_LINUX -> to use eth* as interface name.

  • grub2-mkconfig -o /boot/grub2/grub.cfg -> to rewrite the changes on grub.cfg. grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg => NEVER EDIT grub2.cfg otherwise when kernel updates the changes will be gone.

  • How to know if the system is EFI? dmesg | egrep -i "efi|bios" or mount | grep "^/"

systemd tragets :

A target is just a group of unit files. Isolatable targets define a desired final state, such as emergency.target, rescue.target, multi-user.target and graphical.target. Disabling and enabling services, links them into their desired targets. This is dictated by their WantedBy setting within the unit file, as shown by systemctl cat httpd {install} WantedBy=multiuser.target

The default target and their wants are defined in /etc/systemd/system/, as symlinks. This directory is just a big bag of symlinks.

To boot into a specific target:

  • GRUB2 boot prompt systemd.unit=rescue.target

  • On a running system systemctl isolate xxx.target

systemctl list-dependencies visually lays out the hierarchy of targets and units.

systemctl get-default and set-default can be used to, you guessed it, set the default target. For example if we want to set the default target to multiuser.target, then all we have to do is systemctl set-default multi-user.target

Essential Troubleshooting (Changing root password) :

Edit GRUB2 entry while booting, add rd.break to end of linux kernel line, once in a shell, remount sysroot as rw, update the root password and flag to selinux this is cool: mount -o remount /sysroot chroot /sysroot passwd touch /.autorelabel ctrl+d ctrl + d

Last updated