I tried to extract the initrd casper/initrd
of Ubuntu 18.10 and got an unexpected result. I did not see the root filesystem and files, but just a folder named kernel
.
What I have done
Firstly I tried to know if I should decompress the initrd or just extract the archive directly, so I issued this command:
$ file initrd
initrd: ASCII cpio archive (SVR4 with no CRC)
What I got
According to the output, it should be an cpio archive and I used cpio
to extract the archive.
$ cpio -id < initrd
56 blocks
$ ls
initrd kernel
If I went to have a look of the directory kernel
, I got
kernel/
└── x86
└── microcode
└── AuthenticAMD.bin
2 directories, 1 file
What I expect
There should be files and folders like init
, etc
, usr
, and so on. For example:
bin conf cryptroot etc init lib lib64 run sbin scripts usr var
I figure out the initrd of Ubuntu 18.10 is archived in a different way from the previous releases. In the previous releases the initrd is usually a lzma (or gzip for much earlier releases) compressed cpio archive. The initrd of 18.10 is an archive composed of several binary files in different formats.
To dive into the archive, you may need
binwalk
(or other similar tools. You could getbinwalk
bysudo apt install binwalk
). Once you getbinwalk
, issue the commandbinwalk initrd
:You could see there are two microcode binary files and a LZMA compressed data file. The latter is what we want: the lzma compressed initrd.
Let's get the lzma compressed initrd by
You will get the expected files mentioned in the questions. Edit the files you want to change. Use the following commands to repack the binary files:
And finally concatenate the microcode files and your new initrd (initrd.partial.lz) by
Now rename
initrd.new
to beinitrd
and put it back tocasper/initrd
. You could boot your live system with your new initrd.My answer is inspired by this post https://unix.stackexchange.com/questions/163346/why-is-it-that-my-initrd-only-has-one-directory-namely-kernel