Compiling Kernel   «Prev  Next»

Lesson 10 Compiling the kernel:
ObjectiveDescribe common post-installation procedures

Post Installation Kernel Compiling

Here's a detailed guide on common post-installation procedures for your newly compiled kernel on Red Hat Enterprise Linux (RHEL) 9.4, focusing on ensuring that your modules are correctly accessible through a ramdisk:
Post-Installation Procedures for New Kernel
  1. Verify Kernel Installation
    • Check Kernel Version:
      uname -r
                          
      This should still show the old kernel version since you haven't rebooted yet.
    • List Available Kernels:
      ls /boot/vmlinuz*
                          
      Confirm your new kernel's vmlinuz file is listed.
  2. Module Verification
    • List Loaded Modules:
      lsmod
                          
      This command lists currently loaded modules, which will be from the old kernel.
    • Check for New Kernel Modules:
      ls /lib/modules/$(uname -r)/modules.dep
                          
      Ensure this shows the dependency file for your new kernel version.
  3. Ramdisk (Initramfs) Generation
    • Regenerate Initramfs:
      dracut -f /boot/initramfs-$(uname -r).img $(uname -r)
                          
      This command rebuilds the initramfs image for your new kernel. The `-f` flag forces regeneration. Ensure you're using the correct version number for your new kernel.
    • Verify Initramfs:
      ls /boot/initramfs-$(uname -r).img
                          
      Confirm the initramfs image exists for your kernel.
  4. Grub2 Configuration
    • Update Grub Configuration:
      grub2-mkconfig -o /boot/grub2/grub.cfg
                          
      This updates the GRUB configuration file to include your new kernel.
    • Check Grub Configuration:
      grep -i "linux" /boot/grub2/grub.cfg
                          
      Look for entries related to your new kernel version.
  5. Boot Loader Setup
    • Set Default Boot Entry: Edit `/etc/default/grub` and set:
      GRUB_DEFAULT=saved
      GRUB_SAVEDEFAULT=true
                          
      Then run:
      grub2-set-default 0  # or the number corresponding to your new kernel entry
                          
  6. Pre-Reboot Checks
    • Test Booting from New Kernel without Rebooting:
      kexec -l /boot/vmlinuz-$(uname -r) --initrd=/boot/initramfs-$(uname -r).img --command-line="root=/dev/mapper/rhel-root ro"
                          
      This command allows you to test booting into the new kernel without a full reboot.
    • Run Boot Loader:
      kexec -e
                          
      Execute this to actually boot into the new kernel.
    • Check Kernel: After successful boot, check:
      uname -r
                          
      This should now match your new kernel version.
  7. Final Reboot
    • Reboot System:
      reboot
                          
      This will reboot your system, and it should boot into the new kernel.
  8. Post-Reboot Verification
    • Check Kernel and Modules: Ensure the system is running the new kernel and verify module loading:
      lsmod
                          
    • Check Boot Logs: Review `/var/log/dmesg` or `journalctl -b -k` for any issues during boot.
By following these steps, you ensure that the new kernel, along with its modules, is correctly integrated into the boot process. If there are any specific modules you've compiled, ensure they're included in the `modules.dep` file or explicitly specified during initramfs generation if necessary. If you encounter any errors during boot, you might need to troubleshoot by checking logs or possibly rebuilding the initramfs with specific modules included.
With both the kernel and modules built and installed, you are ready to let the system use the new kernel.
However, until you reboot you are still using the old kernel, so now is the time to make sure you have done everything correctly. If you implemented certain kernel components as modules, specifically those required at boot time, you will need to provide access to them through a ramdisk. [1] The ramdisk holds an image of the modules, and the kernel loads that image into memory before any other components.
However, ramdisks store their data in random access memory, as opposed to on disk. This is useful during installation.

Creating a ramdisk

The mkinitrd command will examine a given kernel's module library, intelligently select any modules that might be needed at boot time (usually SCSI drivers or software RAID modules), create a ramdisk image, and pack the modules into the ramdisk.
The mkinitrd command takes two arguments: the first is the ramdisk filename to manufacture and the second is the kernel version for which the ramdisk is relevant. The ramdisk should be stored in a location accessible at boot, namely the /boot directory.
To create a ramdisk, named initrd-2.2.14.img and stored in /boot, use:
mkinitrd /boot/initrd-2.2.14.img 2.2.14

When the system reboots, the kernel notices you have a ramdisk for the new kernels version.
It then loads the images in that file and continues to boot.
There are no restrictions on what to name the initial ramdisk image, but meticulous naming helps in the long run.

Saving your kernel configuration

As a precaution, you might want to move your kernel configuration to the /boot partition.
Though this is not required, moving your configuration could save you from future configuration problems.
Essentially, you put the kernel configuration in the same location as the kernel, so you can always recreate that kernel from the configuration file.
Simply copy your Linux kernel configuration file into the /boot directory and name it appropriately:
The next lesson describes the LILO map installer.
cp /usr/src/linux/.config /boot/config-2.2.14

[1]Ramdisk: Ramdisks are block devices like hard disks and CD-ROM drives.

SEMrush Software 10 SEMrush Banner 10