:: Re: [DNG] initramfs?
Etusivu
Poista viesti
Vastaa
Lähettäjä: Alessandro Selli
Päiväys:  
Vastaanottaja: dng
Aihe: Re: [DNG] initramfs?
  Sorry to disappoint you, but it Just Doesn't Work.


On 18/11/18 at 10:18, aitor_czr wrote:

>
> Hendrik, you can uncompress the content of the initrd.img by the
> following way:
>
> 1) Rename it to initrd.gz and use gunzip:
>
> # mv initrd.img initrd.gz
> # gunzip initrd.gz



1) You assume the initramfs was compressed with gzip.  This is the
default, but it could be changed in /etc/initramfs-tools/initramfs.conf
setting, for instance, COMPRESS=xz.

2) initramfs is actually formed of two cpio archives: a small,
uncompressed one that is followed by a compressed one.


[alessandro@wkstn05 ~]$ file /boot/initrd.img-4.18.0-0.bpo.1-amd64
/boot/initrd.img-4.18.0-0.bpo.1-amd64: ASCII cpio archive (SVR4 with no CRC)
[alessandro@wkstn05 ~]$ mkdir /tmp/initramfs
[alessandro@wkstn05 ~]$ cd /tmp/initramfs
[alessandro@wkstn05 initramfs]$ cpio -vi <
/boot/initrd.img-4.18.0-0.bpo.1-amd64
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/.enuineIntel.align.0123456789abc
cpio: kernel/x86/microcode/GenuineIntel.bin not created: newer or same
age version exists
kernel/x86/microcode/GenuineIntel.bin
28 blocks
[alessandro@wkstn05 initramfs]$


  28 blocks are 14 KiB, a very small part of the 5,4M
initrd.img-4.18.0-0.bpo.1-amd64 file.


> 2) After that, you can extract the files using cpio:
>
> # mkdir tmp
> # cd tmp
> # cpio -id < ../initrd



  The rest of the initramfs are in a compressed archive that starts
after the 28th block (in my case).  To get that archive you have to
extract it from the 29th block on:


[alessandro@wkstn05 initramfs]$ dd
if=/boot/initrd.img-4.18.0-0.bpo.1-amd64 skip=28
of=/tmp/initrd.img-4.18.0-0.bpo.1-amd64.cpio.xz
11012+1 record dentro
11012+1 record fuori
5638392 bytes (5,6 MB, 5,4 MiB) copied, 0,0228946 s, 246 MB/s
[alessandro@wkstn05 initramfs]$ file
/tmp/initrd.img-4.18.0-0.bpo.1-amd64.cpio.xz
/tmp/initrd.img-4.18.0-0.bpo.1-amd64.cpio.xz: XZ compressed data
[alessandro@wkstn05 initramfs]$


>
> 3) Look at the content (in this case is the initrd.img of
> debian-installer):
>
> # ls
> bin  conf  etc init  lib  sbin  scripts  usr



  Right now I only have:


[alessandro@wkstn05 initramfs]$ ls -R
.:
kernel

./kernel:
x86

./kernel/x86:
microcode

./kernel/x86/microcode:
GenuineIntel.bin

[alessandro@wkstn05 initramfs]$


  To extract the rest of the initramfs you decompress the second part of
the file and feed it to cpio:



[alessandro@wkstn05 initramfs]$ xz -dc
/tmp/initrd.img-4.18.0-0.bpo.1-amd64.cpio.xz | cpio -iv
[alessandro@wkstn05 initramfs]$
.
lib64
lib64/ld-linux-x86-64.so.2
init
scripts
scripts/init-top
scripts/init-top/ORDER
scripts/init-top/udev
scripts/init-top/blacklist
scripts/init-top/keymap
scripts/init-top/all_generic_ide
scripts/functions
scripts/local
scripts/nfs
scripts/init-bottom
scripts/init-bottom/ORDER
scripts/init-bottom/udev
scripts/local-premount
scripts/local-premount/ORDER
[...]
cpio: bin/busybox linked to bin/cat
cpio: bin/busybox linked to bin/cal
cpio: bin/busybox linked to bin/bzip2
cpio: bin/busybox linked to bin/bzcat
cpio: bin/busybox linked to bin/bunzip2
cpio: bin/busybox linked to bin/basename
cpio: bin/busybox linked to bin/awk
cpio: bin/busybox linked to bin/ash
cpio: bin/busybox linked to bin/ar
cpio: bin/busybox linked to bin/[[
cpio: bin/busybox linked to bin/[
bin/busybox
bin/udevadm
bin/loadkeys
bin/cryptroot-unlock
bin/kmod
40012 blocks
[alessandro@wkstn05 initramfs]$


40.012 blocks are 20MiB.

This works in my Devuan Ascii, but didn't work on a colleague's Ubuntu
18.something.


>
> 4) Now you can modify the content of the initrd, and generate the new
> initrd in the parent directory:
>
> # find . | cpio --create --format='newc' > ../newinitrd
>
> Compress it with gzip and rename it to initrd.img
>
> And ready :)
>
> Aitor.



  And I end up with an unbootable system.



--
Alessandro Selli <alessandroselli@???>
VOIP SIP: dhatarattha@???
Chiave firma e cifratura PGP/GPG signing and encoding key:
BA651E4050DDFC31E17384BABCE7BD1A1B0DF2AE