Circle Device


Quick Reference

Gentoo initrd or initramfs

Gentoo initrd or initramfs

Extract an initramfs from a genkernel built initramfs.

An initramfs in Gentoo is just a compressed .cpio archive, first find out what compression is used then extract it.

$ file initramfs-genkernel-x86_64-4.19.57-gentoo
initramfs-genkernel-x86_64-4.19.57-gentoo: gzip compressed data, l...
$ zcat initramfs-genkernel-x86_64-4.19.57-gentoo > initramfs-genkernel-x86_64-4.19.57-gentoo.cpio
$ mkdir initramfs
$ cd initramfs
$ cpio -vid < ../initramfs-genkernel-x86_64-4.19.57-gentoo.cpio

This one is gzipped, use xzcat, bzcat, etc as required.

Then change the stuff in the initramfs directory. For example to add hyperv support as modules:

$ cp -r /lib/modules/4.19.57-gentoo/kernel/drivers/hv lib/modules/4.19.57-gentoo/kernel/drivers
$ cp /lib/modules/4.19.57-gentoo/kernel/drivers/scsi/hv_storvsc.ko lib/modules/4.19.57-gentoo/kernel/drivers/scsi
$ cp -r /lib/modules/4.19.57-gentoo/kernel/drivers/net/hyperv lib/modules/4.19.57-gentoo/kernel/drivers/net

And you should then add a new file in etc/modules/ called hv, like this:

$ cat etc/modules/hv

And update the variable HWOPTS_BLK in etc/initrd.defaults so that the above file is used to load the Hyper-V modules:

HWOPTS_BLK='nvme sata scsi usb firewire hv waitscan'

Then wrap it all back up into a .cpio archive and compress it:

find . -print0 | cpio --null -ov --format=newc | gzip -9 > ../initramfs-genkernel-x86_64-4.19.57-gentoo

The above command will overwrite the original initramfs-genkernel-x86_64-4.19.57-gentoo.

Important Notes

The result is not quite the same as that produced by genkernel but it is close and should work most of the time.


Quick Links: Techie Stuff | General | Personal | Quick Reference