building CD like initrd.img with latest kernel and modules

General support questions
Post Reply
prasadchavan1404
Posts: 2
Joined: 2020/07/01 08:01:21

building CD like initrd.img with latest kernel and modules

Post by prasadchavan1404 » 2020/07/01 08:20:36

I want to build initrd.img similar to initrd.img comes with CentOS ISO which has support for multiple platforms.

Background: We are shipping our product as ISO, prepared from CentOS 7.5. For security compliance reasons we need to update kernel RPMs. While preparing ISO we used initrd.img, vmlinuz and other artifacts from isolinux directory from ISO.

Actual issue: We can not do rpm -Uvh kernel RPM as we are having customisation in grub.cfg because the way partitioning is done. We need to ship an update which will have updated initrd.img and vmlinuz. While updating kernel RPMs on lab VM and hardware devices we found
1. It installs initramfs
2. initramfs is different on each of them. e.g. hardware initramfs has usr/lib/firmware/tigon/* which is not there in initramfs installed on VM.
3. Hardware or VM does not boot if cross initramfs is used.

We can not ship the updates with initramfs obtained after RPM update on lab devices because they are platform specific which is not the case for initrd from ISO.

So, wanted to know a way to build initrd.img using updated kernel and related RPMs. Please let me know how can I do it or is there a way to get updated initrd.img apart from copying it from CentOS ISOs.

Thank You,
Prasad

User avatar
TrevorH
Forum Moderator
Posts: 29112
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: building CD like initrd.img with latest kernel and modules

Post by TrevorH » 2020/07/01 09:09:53

I think you're misunderstanding how it works. When you update the kernel, it copies the latest existing grub entry and amends it for the new kernel version. It copies all existing parameters from the existing entry so whatever customisation you have done to grub.cfg will be preserved on update.

The initramfs is built at kernel install time and it is tailored to support the hardware that is present at the time. If you want this to boot on other hardware then you need to change dracut.conf and change hostonly= to no. That will then build larger initramfs files but they will contain support for all hardware that the kernel supports.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

prasadchavan1404
Posts: 2
Joined: 2020/07/01 08:01:21

Re: building CD like initrd.img with latest kernel and modules

Post by prasadchavan1404 » 2020/07/09 07:59:43

Thanks Trevor for reply.

On creating initrd, I did below steps,
- update kernel on build server and reboot.
- configure hostonly="no" in /etc/dracut.conf
- modprobe modules from /lib/modules/$(uname -r) using below command
for i in `find /lib/modules/$(uname -r) -type f -name '*.ko*' | awk -F'/' '{print $NF}' | sed 's/.ko.xz//'`; do sudo modprobe $i; done
- install dracut modules
sudo yum install anaconda-dracut.x86_64 clevis-dracut.x86_64 dracut-caps.x86_64 dracut-config-generic.x86_64 dracut-config-rescue.x86_64 dracut-debuginfo.x86_64 dracut-fips.x86_64 dracut-fips-aesni.x86_64 dracut-network.x86_64 dracut-tools.x86_64 redhat-upgrade-dracut-debuginfo.x86_64 dracut.x86_64 redhat-upgrade-dracut.x86_64 redhat-upgrade-dracut-plymouth.noarch
- prepare initrd image using dracut command (arguments to dracut command are derived from arguments shown in lsinitrd /mnt/centos/isolinux/initrd.img)
sudo dracut -f --nomdadmconf --nolvmconf --xz --install '/.buildstamp' --no-early-microcode --add 'fips' --add 'anaconda pollcdrom' --force initrd.img $(uname -r)
chown pchavan:pchavan initrd.img

This initrd worked after updating it on installed OS on VM and a hardware in lab. But, it failed while booting ISO as below,
Screenshot 2020-07-07 at 11.22.55 am.png
Screenshot 2020-07-07 at 11.22.55 am.png (75.56 KiB) Viewed 65 times
Please let me know if the steps performed as okay or if something is missing in the steps.

When you update the kernel, it copies the latest existing grub entry and amends it for the new kernel version. It copies all existing parameters from the existing entry so whatever customisation you have done to grub.cfg will be preserved on update.
We keep 2 initrds and vmlinuz in /boot named as initrd.sda3, vmlinuz.sda3 and initrd.sda4 and vmlinuz.sda4 with 2 root partitions out of which one with latest version is loaded.

Post Reply

Return to “CentOS 7 - General Support”