General TC > General TC Talk

[Solved] how to remaster cat'ed initramfs?

<< < (2/3) > >>

GNUser:
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: ---#!/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

--- End code ---
Topic can be marked as Solved :)

Rich:
Hi GNUser
This works:

--- Code: ---tc@box:~/cat$ mkdir mnt
tc@box:~/cat$ cd mnt
tc@box:~/cat/mnt$ zcat ../initrd.gz | while sudo cpio -id; do :; done
--- End code ---
That's a  colon semicolon  sequence between  do  and  done.

Rich:
Hi GNUser
just a heads up about modules.gz:

--- Code: ---tc@box:~/cat$ readlink mnt/lib/modules/6.1.2-tinycore64/kernel.tclocal
/usr/local/lib/modules/6.1.2-tinycore64/kernel/
--- End code ---

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.

nick65go:
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: ---❯ 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
 
~
--- End code ---

--- Code: ---❯ 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
 
--- End code ---

--- Code: ---❯ 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
--- End code ---


--- Code: ---❯ 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/
 
--- End code ---

GNUser:

--- Quote from: Rich on January 09, 2026, 11:16:20 PM ---Hi GNUser
This works:

--- Code: ---tc@box:~/cat$ mkdir mnt
tc@box:~/cat$ cd mnt
tc@box:~/cat/mnt$ zcat ../initrd.gz | while sudo cpio -id; do :; done
--- End code ---
That's a  colon semicolon  sequence between  do  and  done.

--- End quote ---
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?

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version