init.rd を展開してみる
init.rd は initramfs を起動するためもの。/boot のパーティションに存在している。
update-initramfs で起動する。grub から起動される最小限のlinux。
展開してみる・・・?
initrd ファイルはcpio なので 、cpio で展開しようとしてみる。
あれれ
cd `mktemp -d` && sudo cat /boot/initrd.img-`uname -r` | cpio -ivd
.
kernel
kernel/x86
kernel/x86/microcode
kernel/x86/microcode/AuthenticAMD.bin
62 ブロック
1ファイルしかない?そんな馬鹿な
takuya@d001:/tmp/tmp.On03d1x9GP$ tree .
.
└── kernel
└── x86
└── microcode
└── AuthenticAMD.bin
3 directories, 1 file
調べてみたら、このcpio ファイルはいくつかの組み合わせなのでうまく行かない。
linux - Why is it that my initrd only has one directory, namely, 'kernel'? - Unix & Linux Stack Exchange
そうだね。cpio ってtar みたいなもんだもんな
binwalk コマンドをいれて、中身を見てみると。。。末尾にgzip 圧縮されたものがある。
takuya@d001:/tmp/tmp.On03d1x9GP$ binwalk /boot/initrd.img-`uname -r`
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: "0x00007752"
31184 0x79D0 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
31744 0x7C00 ASCII cpio archive (SVR4 with no CRC), file name: "kernel", file name length: "0x00000007", file size: "0x00000000"
31864 0x7C78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86", file name length: "0x0000000B", file size: "0x00000000"
31988 0x7CF4 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode", file name length: "0x00000015", file size: "0x00000000"
32120 0x7D78 ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/.enuineIntel.align.0123456789abc", file name length: "0x00000036", file size: "0x00000000"
32284 0x7E1C ASCII cpio archive (SVR4 with no CRC), file name: "kernel/x86/microcode/GenuineIntel.bin", file name length: "0x00000026", file size: "0x0024CC00"
2443952 0x254AB0 ASCII cpio archive (SVR4 with no CRC), file name: "TRAILER!!!", file name length: "0x0000000B", file size: "0x00000000"
2444288 0x254C00 gzip compressed data, from Unix, last modified: 2019-10-18 08:19:18
ここから、bs がわかるので、それを取り出してみる。
takuya@d001:/tmp/tmp.On03d1x9GP$ dd if=/boot/initrd.img-`uname -r` bs=2444288 skip=1 | gunzip | cpio -tdv | head
drwxr-xr-x 13 root root 0 Oct 18 17:19 .
drwxr-xr-x 2 root root 0 Oct 18 17:19 bin
-rwxr-xr-x 1 root root 9424 Feb 1 2019 bin/cpio
-rwxr-xr-x 1 root root 5751 Feb 14 2019 bin/cryptroot-unlock
-rwxr-xr-x 1 root root 108760 Jan 14 2019 bin/date
-rwxr-xr-x 1 root root 9624 Feb 1 2019 bin/dd
-rwxr-xr-x 1 root root 8792 Feb 1 2019 bin/dmesg
-rwxr-xr-x 1 root root 9992 Feb 1 2019 bin/fstype
-rwxr-xr-x 1 root root 8920 Feb 1 2019 bin/halt
-rwxr-xr-x 1 root root 19872 Feb 1 2019 bin/ipconfig
お、ファイルが見えるぞ。
それではこのファイルを取り出してみる
takuya@d001:/tmp/tmp.IrvVwlLK99$ dd if=/boot/initrd.img-`uname -r` bs=2444288 skip=1 of=img.cpio.gz
takuya@d001:/tmp/tmp.IrvVwlLK99$ gunzip img.cpio.gz
takuya@d001:/tmp/tmp.IrvVwlLK99$ cpio -idv < img.cpio
takuya@d001:/tmp/tmp.IrvVwlLK99$ ll
合計 194292
drwx------ 13 takuya takuya 4096 10月 18 17:35 ./
drwxrwxrwt 21 root root 4096 10月 18 17:35 ../
drwxr-xr-x 2 takuya takuya 4096 10月 18 17:35 bin/
drwxr-xr-x 3 takuya takuya 4096 10月 18 17:35 conf/
drwxr-xr-x 2 takuya takuya 4096 10月 18 17:35 cryptroot/
drwxr-xr-x 11 takuya takuya 4096 10月 18 17:35 etc/
-rw-rw-r-- 1 takuya takuya 198891008 10月 18 17:34 img.cpio
-rwxr-xr-x 1 takuya takuya 7077 10月 18 17:35 init*
drwxr-xr-x 10 takuya takuya 4096 10月 18 17:35 lib/
drwxr-xr-x 2 takuya takuya 4096 10月 18 17:35 lib64/
drwxr-xr-x 2 takuya takuya 4096 10月 18 17:35 run/
drwxr-xr-x 2 takuya takuya 4096 10月 18 17:35 sbin/
drwxr-xr-x 10 takuya takuya 4096 10月 18 17:35 scripts/
drwxr-xr-x 7 takuya takuya 4096 10月 18 17:35 usr/
drwxr-xr-x 4 takuya takuya 4096 10月 18 17:35 var/
取り出せました。
chroot してみる
takuya@d001:/tmp/tmp.IrvVwlLK99$ sudo chroot . /bin/sh
BusyBox v1.27.2 (Ubuntu 1:1.27.2-2ubuntu7) built-in shell (ash)
Enter 'help' for a list of built-in commands.
#
更に単純な方法
takuya@d001:/tmp/tmp.gTlrfnehcs$ unmkinitramfs /boot/initrd.img-`uname -r` .