Linux Exercise: System Initialization
GRUB/GRUB2
Figure out whether your distribution is using GRUB or GRUB2.
- # ls /boot
If you just see a "grub" directory, you are most likely using GRUB. If you see both a "grub" and a "grub2" directory, or just a "grub2" directory you are most likely using GRUB2.
- # ls /boot
Change the GRUB/GRUB2 configuration so that the menu timeout is now 15 seconds.
- If using GRUB: Modify the "timeout" value in the file /boot/grub/grub.conf. Reboot the system.
- If using GRUB2: Modify the "TIMEOUT" value in the file /etc/default/grub. Run the command grub2-mkconfig -o /boot/grub2/grub.cfg. Reboot the system.
Kernel configuration
Use the rpm command to make a list of all installed kernels on your system.
- # rpm -qa | grep kernel
Look at the version of the kernel that is currently running.
- # cat /proc/version
Look at the contents of the currently running kernel RPMs. Can you identify the different components and locations?
- If you are using CentOS/Red Hat 7 or earlier:
# rpm -ql kernel-version | less
- If you are using CentOS/Red Hat 8 or later:
# rpm -ql kernel-core-version | less
# rpm -ql kernel-modules-version | less - In both cases, you should be seeing the following components:
- The core kernel image in /boot, plus a few associated debug/development files.
- The initrd/initramfs file in /boot.
- Several 100s of modules in /lib/modules/version, plus a few associated index files.
- If you are using CentOS/Red Hat 7 or earlier:
Look at the list of currently loaded modules.
- # lsmod
In the next few steps we are going to play with loading and unloading modules. This is done with the "nf_conntrack_ftp" module, which in turn is dependent on the "nf_conntrack" module. In order for these steps to work properly, the nf_conntrack module should NOT be loaded. Check whether this module is loaded using the lsmod | grep nf_conntrack command. If it is loaded, then this is usually caused by either the firewalld or the libvirtd service. In that case, disable these services with systemctl disable firewalld and systemctl disable libvirtd, reboot your system and run lsmod again. The nf_conntrack module should not be loaded now.
Make a list of all modules that were provided with the current running kernel, that have the name "conntrack_ftp" in them. Try to load this module using insmod. Does this work?
- In CentOS 7/Red Hat 7 or earlier:
# rpm -ql kernel-version | grep conntrack_ftp - In CentOS 8/Red Hat 8 or later:
# rpm -ql kernel-core-version | grep conntrack_ftp
# rpm -ql kernel-modules-version | grep conntrack_ftp - You should see a module, called /lib/modules/version/kernel/net/netfilter/nf_conntrack_ftp.ko. In newer kernel versions, modules are compressed by default so the name is /lib/modules/version/kernel/net/netfilter/nf_conntrack_ftp.ko.xz.
- # insmod /lib/modules/version/kernel/net/netfilter/nf_conntrack_ftp.ko*
This will give you an "unknown symbol" error. The nf_conntrack_ftp module is dependent on other modules, and the symbols they implement/export.
- In CentOS 7/Red Hat 7 or earlier:
Take a look at the file /lib/modules/version/modules.dep. Do you see the line about nf_conntrack_ftp?
- # vi /lib/modules/version/modules.dep
Look for the line describing the dependencies for nf_conntrack_ftp. You'll see this module is dependent on nf_conntrack.
- # vi /lib/modules/version/modules.dep
Look at the list of currently loaded modules again. Check whether nf_conntrack was loaded.
- # lsmod | grep nf_conntrack
Try to load the module nf_conntrack_ftp again, this time using modprobe. Does this work this time? Take a look at the list of modules again, in particular for conntrack modules.
- # modprobe nf_conntrack_ftp
- # lsmod | grep nf_conntrack
You should see both the nf_conntrack and the nf_contrack_ftp module loaded now.
Remove the nf_conntrack_ftp and the nf_conntrack module from the kernel.
- # rmmod nf_conntrack_ftp
- # rmmod nf_conntrack
Run the dmesg command to view the internal kernel log. Do you see the result of your actions?
- # dmesg | less
System V init
Do these exercises if your system uses System V init. System V init was used in Red Hat Enterprise Linux up to version 5, and other distributions from the same timeframe. You can also perform these exercises if you are using Red Hat 6 or another distribution that uses upstart.
Look at the /etc/inittab file and figure out what your default runlevel is.
- # cat /etc/inittab
Check with the runlevel command if your system indeed booted in this runlevel.
- # runlevel
Change the default runlevel in /etc/inittab. If it's 3, change it to 5, and vice versa. Then reboot the system and see if it comes up in the right runlevel.
- # vi /etc/inittab
- # reboot
- # runlevel
Note: Your system will only start the graphical environment in runlevel 5 if the graphical environment is actually installed. If the graphical environment is not installed, but you will want to use it anyway, you will need to install it manually. How this is done is covered in a different exercise. The very short version: run the command yum -y groupinstall "GNOME Desktop". Note that this will download several 100s of megabytes over the internet and may take a long time to complete.
Verify the sshd daemon is started in the current runlevel. Also verify sshd is running now.
- # chkconfig --list sshd
- # service sshd status
Disable the sshd daemon and verify it doesn't boot anymore in the current runlevel.
- # chkconfig sshd off
- # chkconfig --list sshd
- # reboot
Enable the sshd daemon again and start it manually.
- # service sshd status
- # chkconfig sshd on
- # service sshd start
systemd
Do these exercises only if your system uses systemd. Systemd is used in Red Hat 7 or later, and in other distributions from the same timeframe.
If you installed a "mimimal" installation, install the graphical environment now.
- On Red Hat/CentOS 7 or earlier:
# yum -y groupinstall "GNOME Desktop" - On Red Hat/CentOS 8 or later:
# yum -y groupinstall "Server with GUI"
Note: This will download and install several 100s of megabytes worth of software and may require quite a long time, depending on your internet connection.
Note 2: If you get an error message about a package conflict, then run the command yum -y update first, and then run the yum -y groupinstall command again.
- On Red Hat/CentOS 7 or earlier:
Check your current default target.
- # systemctl get-default
If your current target is multi-user, switch it to graphical and vice versa. Then reboot the system and verify it comes up in the right target.
- # systemctl set-default graphical
- # reboot
Check the sshd daemon is started.
- # systemctl status sshd
Disable the sshd daemon, restart the ssytem and verify that the sshd daemon is indeed not started.
- # systemctl disable sshd
- # reboot
- # systemctl status sshd
Enable and start the sshd daemon again.
- # systemctl enable sshd
- # systemctl start sshd