2

How to recompile the file type of CPIO-archive (application/x-cpio)

enter image description here

I am able to unpack its contents with below command.

unmkinitramfs initrd .

enter image description here

But not able to recompile.

How can I Achive this?

PRATAP
  • 107
  • 15
  • Is your problem the same as [cpio incorrectly unpacking initrd](https://serverfault.com/questions/876140/cpio-incorrectly-unpacking-initrd-in-ubuntu-xenial)? – harrymc May 31 '20 at 20:14
  • @harrymc no, Once extracted those 3 directories using `unmkinitramfs` I have to delete the original `initrd` file and create new `initrd` with those 3 directories to use in a live iso to be able to boot with new `initird`. – PRATAP Jun 01 '20 at 01:08
  • So is the problem the same as [How to repack initrd.img?](https://askubuntu.com/questions/777260/how-to-repack-initrd-img) – harrymc Jun 01 '20 at 06:35
  • @harrymc no.. `.img` extension seems to be for previous releases.. and what i observed is that the initrd.img/initrd can be generated when you already logged in. but my case is its the `initrd` for live iso. i did trails to boot live iso with generated image from logged in session and live iso can not boot with that. Also I noticed that the contents r different from live iso and logged in iso. – PRATAP Jun 01 '20 at 09:38
  • Another possibility : [Customize Live Initrd](https://wiki.ubuntu.com/CustomizeLiveInitrd). – harrymc Jun 01 '20 at 10:54
  • @harrymc tried that one too. seems the post is quite older. the big difference i came across all those is.. the image I described in the Q is not gzip.. all the posts are assuming the image is gzip.. when I run cpio commands mentioned.. all says the Image is not gzip and thus my Question n bounty araised. – PRATAP Jun 01 '20 at 11:17
  • You might share that image, if it's problematic, and where you got it from. – harrymc Jun 01 '20 at 12:41
  • @harrymc It is from the downloaded iso.. https://releases.ubuntu.com/20.04 – PRATAP Jun 01 '20 at 13:00
  • https://we.tl/t-YDjOA8YJ1m – PRATAP Jun 01 '20 at 13:10
  • I find that I don't have the environment to check out this problem. Perhaps the above info will be enough for someone else here. – harrymc Jun 02 '20 at 08:14
  • @PRATAP do you basically just wanna repack the 3 directories into a cpio archive (which is what initrd is)? – b0yfriend Jun 06 '20 at 08:50
  • @AntonParas Yes.. thats what exactly.. – PRATAP Jun 06 '20 at 08:50
  • Just adding a comment to track. I am trying to do the exact same thing. Specifically, in my case, I want to change the live CD splash image. Literally every single resource on the web refers to something woefully outdated. All I want is to take the 2 microcode firmwars and the main file system, and recreate the initrd we started with. – Hari Sundararajan Jun 08 '20 at 18:59
  • @harrymc thanks for the link on how to repack initrd.img. While the steps can't be translated one to one , it gave me a basic understanding of what we are trying to do here. – Hari Sundararajan Jun 09 '20 at 04:56

2 Answers2

2

Ok, I took some motivation from this https://askubuntu.com/questions/777260/how-to-repack-initrd-img

Let us start with the assumption that your current directory is $DIR and it has the "initrd" from the live CD/casper/initrd. We will create a new initrd called myinitrd in the same ${DIR}

mkdir 18
unmkinitramfs initrd ${DIR}/18

# start with an empty file
rm -rf ${DIR}/myinitrd
touch ${DIR}/myinitrd

# Add the first microcode firmware
cd ${DIR}/18/early
find . -print0 | cpio --null --create --format=newc > ${DIR}/myinitrd

# Add the second microcode firmware
cd ${DIR}/18/early2
find kernel -print0 | cpio --null --create --format=newc >> ${DIR}/myinitrd

# Add the actual ram fs file system
cd ${DIR}/18/main
find . | cpio --create --format=newc | xz --format=lzma >> ${DIR}/myinitrd

# verify both initrds are the same
binwalk ${DIR}/myinitrd
binwalk ${DIR}/initrd
  • For what it is worth, I used this method to change the hostname and the boot splash logo of the live CD. I extracted the initrd, modified main/etc/casper.conf and the plymouth logo files and everything works as expected. – Hari Sundararajan Jun 09 '20 at 12:10
0

@PRATAP, based on your confirmation in the comments, can you try this?

I'm assuming the 3 directories are inside a parent directory, kernel/

find kernel/ | cpio -o -H newc > my_new_initrd

my_new_initrd should be your recompiled initrd

b0yfriend
  • 235
  • 1
  • 5
  • no worries! as a followup, can you share the output of `file initrd` and `ls -R kernel` ? – b0yfriend Jun 06 '20 at 09:21
  • @PRATAP thanks! I updated the command in my answer, could you try one more time? – b0yfriend Jun 06 '20 at 10:04
  • Sorry, I made a typo! Could you make it `-H` instead of just `H`? – b0yfriend Jun 06 '20 at 10:09
  • 1
    Let us [continue this discussion in chat](https://chat.stackexchange.com/rooms/108973/discussion-between-b0yfriend-and-pratap). – b0yfriend Jun 06 '20 at 10:17
  • 1
    @b0yfriend This method won't work. The 2 folders (early) and (early2) are microcode firmwares. Then there is "main" which is the _actual_ file system. You can't just group all 3 of them into a single initrd. In reality, the original initrd has 3 distinct pieces. try running `binwalk` against the initrd, that might make it clearer – Hari Sundararajan Jun 08 '20 at 19:01