initramfs:我在哪里可以确定进入 /sbin 的内容?

lar*_*els 5 boot initramfs

我在哪里可以配置update-initramfs将哪些二进制文件复制到initrd 映像内的/sbin目录中?

我一直在 /etc/initramfs-tools 和 /usr/lib/initramfs-tools 下查找,但在任何地方都找不到二进制文件列表

# grep -ri sbin /etc/initramfs-tools
# grep -ri sbin /usr/lib/initramfs-tools
#
Run Code Online (Sandbox Code Playgroud)

A.B*_*.B. 5

您必须使用/usr/share/initramfs-tools/hooks. 当您键入update-initramfs. 创建您自己的挂钩脚本或删除脚本。

另一个文件夹是 /etc/initramfs-tools/hook

man initramfs-tools

   Hooks can be found in two places: /usr/share/initramfs-tools/hooks  and
   /etc/initramfs-tools/hooks.  They are executed during generation of the
   initramfs-image and are responsible for  including  all  the  necessary
   components  in the image itself. No guarantees are made as to the order
   in which the different scripts are  executed  unless  the  prereqs  are
   setup in the script.
Run Code Online (Sandbox Code Playgroud)

请注意,钩子脚本是包的一部分,例如kmod. 该包kmod/usr/share/initramfs-tools/hooks.


示例脚本

#!/bin/sh -e
# Copy the compatibility symlinks until initramfs-tools will be converted
# to use the kmod program.

if [ "$1" = "prereqs" ]; then exit 0; fi

. /usr/share/initramfs-tools/hook-functions

copy_exec /bin/kmod
cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/

mkdir -p $DESTDIR/lib/modprobe.d/
if [ "$(echo /lib/modprobe.d/*)" != "/lib/modprobe.d/*" ]; then
  cp -a /lib/modprobe.d/* $DESTDIR/lib/modprobe.d/
fi
Run Code Online (Sandbox Code Playgroud)

如您所见,钩子脚本将所有文件复制/lib/modprobe.d/initramfs/lib/modprobe.d/

cp -a /lib/modprobe.d/* $DESTDIR/lib/modprobe.d/
Run Code Online (Sandbox Code Playgroud)

modprobe进入initramfs/sbin

cp -a /sbin/modprobe /sbin/rmmod $DESTDIR/sbin/
Run Code Online (Sandbox Code Playgroud)

您自己initrd.img的一个文件foo

cd 
mkdir initrd
cd initrd
touch foo   # an example file
find . | cpio -o -H newc > ../initrd.img
cd ..
gzip initrd.img
cp initrd.img.gz initrd.img
Run Code Online (Sandbox Code Playgroud)

检查您的内容 initrd.img

cd
mkdir initrd_out
cd initrd_out
cpio -i < ../initrd.img
Run Code Online (Sandbox Code Playgroud)

并与ls你应该看到一个文件

% ls
foo
Run Code Online (Sandbox Code Playgroud)