I am trying to update a process used to remaster the Ubuntu 18.04 install image for 20.04 and running into a problem with extracting the initrd archive.
The command used is cpio -id --no-absolute-filenames
. When I use this same command to extract the initrd image from the 20.04 image, it extracts kernel/x86/microcode/AuthenticAMD.bin
and stops.
Inspecting initrd file contents I can see a "TRAILER" section showing that there are multiple archives in the file. As suggested in other threads about cpio archives, I tried to extract the compound archive as such: cat initrd | while cpio -id --no-absolute-filenames; do :; done
. In this case, the first entry extracts but then it has a bunch of "0 blocks" and doesn't extract anything else.
Does anyone know how this archive was created or how to extract it?
/usr/sbin/update-initramfs calls /usr/sbin/mkinitramfs, which calls
where the lz4 is coming from /etc/initramfs-tools/initramfs.conf
reversing that into
fails though.
keeps persisting it's a cpio archive, but
still ends up in the same AuthenticAMD.bin. Maybe somebody else can build on this?
Edit: nope. According to https://unix.stackexchange.com/a/511224/44864 The answer is
Same problem here -- the solution was to not unpack with Ubuntu version 20.04 using unmkinitramfs.
I created a bootable USB and booted my machine into Ubuntu 20 -- unmkinitramfs was then able to unpack the initrd. I'm still finding my way around building a new bootable USB that doesn't autologin (and works correctly with casper-rw).
If you want to see more about what unmkinitramfs does, it's a bash script. In a comparison between Bionic and Focal, Bionic does not supprt lz4 compression.
I'm currently creating a custom live CD, based on Ubuntu 20.04 live CD. Everything is fine untill i tried to modify initrd. I mean the initrd located in the casper directory of the iso.
The standard way to build the live cd ,as far as i understood, is first.
Extract the iso in a separate directory
Extract the squashfs file system in a separate directory
Mount proc sys dev .. prior to make the chroot on the squashfs directory
# Make a chroot on squahfs dir
And you can start modifying the squashfs filesystem for your needs.
# Make your modifications
Prior to leave your chroot
# Do an update-initramfs (update-initramfs -k all -u)
Rebuild the squashfs image
Copy it into the iso dir
Rebuild the iso image.
One thing i noticed, update-initramfs does not modify initrd.
In my case i was changing the plymouth theme.
mkdir temp;cd temp unmkinitramfs ../initrd . # (casper) mkinitramfs . -o ../initrd.new
To me, this should create an initrd.new with the same size as the original.
But its not the case ! the new one is bigger
Otherwise, i tried an other method -----------------------
Do
binwalk initrd .. 3492528 0x354AB0 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000" 3492864 0x354C00 LZ4 compressed data, legacy
Just after the TRAILER line (get the lz4 size , here 3492864)
dd if=../initrd bs=3492864 skip=1 | unlz4 -c | cpio -id
Now rebuild initrd
find | cpio -H newc -o | lz4 -c > ../initrd.partial.lz4
And finally concatenate the microcode files and your new initrd (initrd.partial.lz) by
Count is block size divided by 512
dd if=../initrd of=../initrd.microcode bs=512 count=6822
Rebuild the newinitrd
cat ../initrd.microcode ../initrd.partial.lz4 > ../initrd.new
#---------------------------------------------------------
They do not have the same size eather!
It looks like that with focal, the initrd format has changed somehow. For sure lz4 compression has been added to focal, but there is something else, but its not documented ....