我试图提取casper/initrdUbuntu 18.10的 initrd并得到了一个意想不到的结果。我没有看到根文件系统和文件,而只是一个名为kernel.
首先我想知道我是应该解压 initrd 还是直接解压存档,所以我发出了这个命令:
$ file initrd
initrd: ASCII cpio archive (SVR4 with no CRC)
Run Code Online (Sandbox Code Playgroud)
根据输出,它应该是一个 cpio 存档,我用来cpio解压存档。
$ cpio -id < initrd
56 blocks
$ ls
initrd kernel
Run Code Online (Sandbox Code Playgroud)
如果我去看看目录kernel,我得到了
kernel/
??? x86
??? microcode
??? AuthenticAMD.bin
2 directories, 1 file
Run Code Online (Sandbox Code Playgroud)
应该有文件和文件夹,如init、etc、usr等。例如:
bin conf cryptroot etc init lib lib64 run sbin scripts usr var
Run Code Online (Sandbox Code Playgroud)
我发现 Ubuntu 18.10 的 initrd 以与以前版本不同的方式存档。在以前的版本中,initrd 通常是一个 lzma(或 gzip,用于更早的版本)压缩的 cpio 存档。18.10 的 initrd 是由多个不同格式的二进制文件组成的存档。
要深入了解档案,您可能需要binwalk(或其他类似工具。您可以binwalk通过sudo apt install binwalk)。一旦你得到binwalk,发出命令binwalk initrd:
$ binwalk initrd
DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
0 0x0 ASCII cpio archive (SVR4 with no CRC), file name: ".", file name length: "0x00000002", file size: "0x00000000"
112 0x70 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
232 0xE8 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
356 0x164 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
488 0x1E8 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/AuthenticAMD.bin", file name length: "0x00000026", file size: "0x00006B2A"
28072 0x6DA8 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
28672 0x7000 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
28792 0x7078 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
28916 0x70F4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
29048 0x7178 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/.enuineIntel.align.0123456789abc", file name length: "0x00000036", file size: "0x00000000"
29212 0x721C ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x00180C00"
1605296 0x187EB0 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
1605632 0x188000 LZMA compressed data, properties: 0x5D, dictionary size: 8388608 bytes, uncompressed size: -1 bytes
Run Code Online (Sandbox Code Playgroud)
您可以看到有两个微码二进制文件和一个 LZMA 压缩数据文件。后者是我们想要的:lzma 压缩的 initrd。
让我们通过以下方式获取 lzma 压缩的 initrd
dd if=initrd bs=1605632 跳过=1 | unlzma -c | cpio -id
您将获得问题中提到的预期文件。编辑要更改的文件。使用以下命令重新打包二进制文件:
查找 | cpio -H newc -o | lzma -c > initrd.partial.lz
最后通过以下方式连接微码文件和新的 initrd (initrd.partial.lz)
dd if=initrd of=initrd.microcode bs=512 count=3136
cat initrd.microcode initrd.partial.lz > initrd.new
Run Code Online (Sandbox Code Playgroud)
现在重命名initrd.new为 beinitrd并将其放回casper/initrd. 您可以使用新的 initrd 启动实时系统。
我的回答受到这篇文章的启发https://unix.stackexchange.com/questions/163346/why-is-it-that-my-initrd-only-has-one-directory-namely-kernel
| 归档时间: |
|
| 查看次数: |
4381 次 |
| 最近记录: |