WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [Solved] how to remaster cat'ed initramfs?  (Read 1376 times)

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
[Solved] how to remaster cat'ed initramfs?
« on: January 09, 2026, 03:29:03 PM »
If I create an initramfs from two more components, like so...

Code: [Select]
$ cat modules64.gz rootfs64.gz > corepure64.gz
...then try to remaster the resulting initramfs like so...
Code: [Select]
$ sudo su -c "mkdir temp; cd temp; gunzip -c ../corepure64.gz | cpio -i"
30012 blocks

...I notice that only the contents of the first argument to  cat  (modules64.gz in this case) appear inside the  temp  directory.

Is there a way to remaster the entire  corepure64.gz  in this example (short of remastering its component parts then recreating  corepure64.gz  using cat)?
« Last Edit: January 13, 2026, 10:51:33 AM by Rich »

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1503
Re: how to remaster cat'ed initramfs?
« Reply #1 on: January 09, 2026, 04:05:44 PM »
Does zcat work

zcat "${OLDINITRD}" | sudo cpio -i -H newc -d

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #2 on: January 09, 2026, 05:02:35 PM »
Does zcat work

zcat "${OLDINITRD}" | sudo cpio -i -H newc -d
Hi Paul_123. zcat doesn't help:
Code: [Select]
$ cat modules64.gz rootfs64.gz > corepure64.gz
$ sudo su -c "mkdir temp; cd temp; zcat ../corepure64.gz | cpio -i -H newc -d"
30012 blocks
$ ls temp
lib/ usr/
Note how only the contents of  modules64.gz  appear inside the temp directory.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12604
Re: how to remaster cat'ed initramfs?
« Reply #3 on: January 09, 2026, 05:12:30 PM »
Hi GNUser
Try this:
Code: [Select]
mkdir tempdir
cd tempdir
zcat /path/to/existing/rootfs.gz | sudo cpio -i

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #4 on: January 09, 2026, 06:03:11 PM »
Hi GNUser
Try this:
Code: [Select]
mkdir tempdir
cd tempdir
zcat /path/to/existing/rootfs.gz | sudo cpio -i
Hi Rich. No luck with that, either:

Code: [Select]
$ cat modules64.gz rootfs64.gz > corepure64.gz
$ mkdir tempdir
$ cd tempdir
$ zcat ../corepure64.gz | sudo cpio -i
30012 blocks
$ ls
lib/ usr/
Maybe there's a better way to create  corepure64.gz  from smaller initramfs'es than simply using cat.

EDIT: When a new version of TCL is released and  corepure64.gz  is posted, how does it get created? I have no problem remastering  corepure64.gz  from stable TCL releases. It's only  corepure64.gz  that I create using  cat  that misbehaves in this way.
« Last Edit: January 09, 2026, 06:10:03 PM by GNUser »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #5 on: January 09, 2026, 10:33:37 PM »
It seems that using  cat  to combine initramfs'es results in an initramfs that is usable (for booting), but is not amenable to being remastered.

To combine initramfs'es in such a way that the result is both usable and remasterable, I wrote this little shell script for myself. I called it  combine-initramfs  . It can be placed anywhere in your PATH:

Code: [Select]
#!/bin/sh

# Purpose: Combine multiple initramfs'es into a single one that can be remastered later
# (just using cat results in an initramfs that does not seem amenable to being remastered)
#
# Usage example:
# $ combine-initramfs modules64.gz root64.gz

# 1. pool the contents of all initramfs arguments into temp dir
mkdir -p temp
for i in "$@"; do
i="$(realpath "$i")"
cd temp
zcat "$i" | sudo cpio -i
cd ..
done

# 2. create initramfs from temp dir
cd temp
sudo su -c "find . | cpio -H newc -o | gzip -9 > ../combined.gz"
sudo chown $(cat /etc/sysconfig/tcuser):staff ../combined.gz

# 3. clean up
cd ..
sudo rm -rf temp
Topic can be marked as Solved :)
« Last Edit: January 09, 2026, 10:43:55 PM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12604
Re: how to remaster cat'ed initramfs?
« Reply #6 on: January 09, 2026, 11:16:20 PM »
Hi GNUser
This works:
Code: [Select]
tc@box:~/cat$ mkdir mnt
tc@box:~/cat$ cd mnt
tc@box:~/cat/mnt$ zcat ../initrd.gz | while sudo cpio -id; do :; done
That's a  colon semicolon  sequence between  do  and  done.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12604
Re: how to remaster cat'ed initramfs?
« Reply #7 on: January 10, 2026, 12:03:29 AM »
Hi GNUser
just a heads up about modules.gz:
Code: [Select]
tc@box:~/cat$ readlink mnt/lib/modules/6.1.2-tinycore64/kernel.tclocal
/usr/local/lib/modules/6.1.2-tinycore64/kernel/

The link is absolute to /usr/local/lib/modules/$KERNEL/kernel.
So if modules.gz is a match to the system you are running on, it
will point to your installed drivers once unpacked.

Offline nick65go

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 958
Re: how to remaster cat'ed initramfs?
« Reply #8 on: January 10, 2026, 04:05:53 AM »
Maybe you can have a look at the source code for a tool (in Archlinux), which can extract both CPIO files from a init boot file
Code: [Select]
❯ ls -al  /usr/bin/lsinitcpio
.rwxr-xr-x 12k root 23 Dez  2025 󰡯 /usr/bin/lsinitcpio
 
~
❯ file  /usr/bin/lsinitcpio
/usr/bin/lsinitcpio: Bourne-Again shell script, ASCII text executable
 
~
Code: [Select]
❯ sudo lsinitcpio -a /boot/initramfs-linux.img ==> Image: /boot/initramfs-linux.img
==> Created with mkinitcpio 40
==> Kernel: 6.18.3-arch1-1
==> Early CPIO: 9.99 MiB
==> Size: 11.99 MiB
==> Compressed with: zstd
  -> Uncompressed size: 30.58 MiB (.392 ratio)
  -> Estimated decompression time: 0,082s
 
==> Included modules (38):
  cec                     drm_gpuvm               hid-multitouch          intel-gtt               mmc_core                rpmb-core               spi-pxa2xx-platform     virtio_scsi
  drm_buddy               drm_suballoc_helper     hkdf                    intel-lpss              nvme                    serio_raw               ttm                     wmi
  drm_display_helper      drm_ttm_helper          i2c-algo-bit            intel-lpss-pci          nvme-auth               spi-intel               uas                     xe
  drm_exec                dw_dmac                 i915                    intel-vsec              nvme-core               spi-intel-pci           usb-storage
  drm_gpusvm_helper       gpu-sched               idma64                  mmc_block               nvme-keyring            spi-pxa2xx-core         video
 
==> Included binaries (14):
  blkid                   e2fsck                  kmod                    mount                   plymouthd               switch_root             udevadm
  busybox                 fsck                    loginctl                plymouth                setfont                 systemd-tmpfiles        umount
 
==> Early hook run order:
  udev
 
Code: [Select]
❯ lsinitcpio -h
lsinitcpio 40
usage: lsinitcpio [action] [options] <initramfs>
 
  Actions:
   -a, --analyze        analyze contents of image
   -c, --config         show configuration file image was built with
   -l, --list           list contents of the image (default)
   -x, --extract        extract image to disk
 
  Options:
   -h, --help           display this help
   -n, --nocolor        disable colorized output
   -V, --version        display version information
   -v, --verbose        more verbose output
       --cpio           list or extract only the main CPIO image
       --early          list or extract only the early CPIO image

Code: [Select]
❯ sudo lsinitcpio -l --early /boot/initramfs-linux-cachyos.img
bin
early_cpio
kernel/
kernel/x86/
kernel/x86/microcode/
kernel/x86/microcode/GenuineIntel.bin  <--here stop first cpio for ucode intel firmware
lib
lib64
sbin
usr/
usr/lib/
usr/lib/firmware/
 

« Last Edit: January 10, 2026, 04:19:01 AM by nick65go »

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #9 on: January 10, 2026, 07:21:13 AM »
Hi GNUser
This works:
Code: [Select]
tc@box:~/cat$ mkdir mnt
tc@box:~/cat$ cd mnt
tc@box:~/cat/mnt$ zcat ../initrd.gz | while sudo cpio -id; do :; done
That's a  colon semicolon  sequence between  do  and  done.
Hi Rich. That sure does work! I like it better than my solution (which was really not a solution but a workaround to combine initramfs'es without using cat).

The while loop in your solution is infinite--I have to send the loop SIGINT (Ctrl+c) when I notice that all components of the initrd have been extracted. Is there a way to avoid an infinite loop?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12604
Re: how to remaster cat'ed initramfs?
« Reply #10 on: January 10, 2026, 08:49:54 AM »
Hi GNUser
... Is there a way to avoid an infinite loop?
Yes. Switch to the GNU versions of zcat and/or cpio. It will then
spit out a bunch of warnings which can be silenced like this:
Code: [Select]
zcat ../initrd.gz | while sudo cpio -W none -id; do :; done

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #11 on: January 10, 2026, 08:58:07 AM »
Hi Rich. That's just beautiful! I'm in your debt, as usual.
Happy hacking!

Offline GNUser

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 1799
Re: how to remaster cat'ed initramfs?
« Reply #12 on: January 13, 2026, 10:11:36 AM »
... Is there a way to avoid an infinite loop?
Yes. Switch to the GNU versions of zcat and/or cpio.
At the risk of stating the obvious:
Another way to avoid an infinite loop, while sticking to the default (busybox) versions of zcat and cpio, is to exit the loop after a certain number of iterations:

Code: [Select]
i=0
zcat ../initrd.gz | while [ $i -lt 10 ]; do sudo cpio -id; i=$((i+1)); done

The above assumes the user's  initrd.gz  was built by concatenating no more than 10 initramfs'es together, which seems like a reasonable assumption.

I think we can confidently mark the thread as Solved :)
« Last Edit: January 13, 2026, 10:21:18 AM by GNUser »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 12604
Re: [Solved] how to remaster cat'ed initramfs?
« Reply #13 on: January 13, 2026, 10:53:14 AM »
Hi GNUser
... I think we can confidently mark the thread as Solved :)
So marked.  ;D