加密 mkinitcpio.conf 中的钩子用于完整系统加密 USB 驱动器 Arch 安装

Str*_*Bad 6 arch-linux dependencies hook mkinitcpio

我已经在U 盘上安装了 Arch Linux,并使用 LUKS 进行了完整的系统加密。Arch wiki 像往常一样带我浏览了几乎所有内容。我遇到的唯一问题是在mkinitcpio. Arch wiki 说对于 USB 安装,block钩子必须紧跟在udev钩子之后。维基还说对于加密,encrypt钩子必须在钩子之前,但不一定是立即,filesystem钩子。遵循这些规则我第一次尝试:

HOOKS="encrypt base udev block autodetect modconf filesystems keyboard fsck"
Run Code Online (Sandbox Code Playgroud)

但它没有用,所以我encrypt后来搬到了:

HOOKS="base udev block autodetect modconf encrypt filesystems keyboard fsck"
Run Code Online (Sandbox Code Playgroud)

它工作正常。这引出了我的问题。哪些是对的依赖encrypt挂钩和我在哪里可以找到有关钩依赖性的详细信息?

mik*_*erv 12

你的钩子都在这里:

% ls /usr/lib/initcpio/{hooks,install}
/usr/lib/initcpio/hooks:
btrfs        dmraid   keymap  mdadm    mhwd-fb  miso_loop_mnt  net     shutdown  udev  v86d
consolefont  encrypt  lvm2    memdisk  miso     miso_pxe_nbd   resume  sleep     usr

/usr/lib/initcpio/install:
autodetect  consolefont  fw        mdadm_udev  miso_loop_mnt  pata    sd-encrypt   sleep    usbinput
base        dmraid       keyboard  memdisk     miso_pxe_nbd   pcmcia  sd-lvm2      strip    usr
bcache      encrypt      keymap    mhwd-fb     mmc            resume  sd-shutdown  systemd  v86d
block       filesystems  lvm2      miso        modconf        sata    sd-vconsole  udev     virtio
btrfs       fsck         mdadm     miso_kms    net            scsi    shutdown     usb
Run Code Online (Sandbox Code Playgroud)

它们都是 shell 脚本:

% cat /usr/lib/initcpio/{hooks,install}/encrypt
#!/usr/bin/ash
run_hook() {
    modprobe -a -q dm-crypt >/dev/null 2>&1
    [ "${quiet}" = "y" ] && CSQUIET=">/dev/null"
    # Get keyfile if specified
    ckeyfile="/crypto_keyfile.bin"
    if [ -n "$cryptkey" ]; then
        IFS=: read ckdev ckarg1 ckarg2 <<EOF
...
Run Code Online (Sandbox Code Playgroud)

这是你已经知道的东西——它非常熟悉。

基本上,如果您希望在早期的用户空间中发生某些事情,您只需要加载必要的内核模块并采取相应的行动——这就是所有这些钩子所做的。

如果您想知道initramfs图像中发生了什么,只需看一眼:

% lsinitcpio --help lsinitcpio 17 usage: lsinitcpio [action] [options] 
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
Run Code Online (Sandbox Code Playgroud)

lsinitcpio很方便,但它只不过是一个辅助 shell 函数 - 就像其他函数一样。当您查看磁盘映像时,您会注意到它实际上仅此而已 - 毕竟只是一个普通的 linux 根映像:

% mkdir /tmp/init ; cd $_
% lsinitcpio $(printf /boot/*.img | head -n1) | grep -Eo '^./[^/]*' | sort -u
./VERSION
./bin
./buildconfig
./config
./dev
./etc
./init
./init_functions
./lib
./lib64
./new_root
./proc
./run
./sbin
./sys
./tmp
./usr
Run Code Online (Sandbox Code Playgroud)

你可以提取它:

% lsinitcpio --extract $(printf /boot/*.img | head -n1)
% ls
dev
etc
new_root
proc
run
sys
tmp
usr
VERSION
bin
buildconfig
config
init
init_functions
lib
lib64
sbin
Run Code Online (Sandbox Code Playgroud)

并四处看看:

% cat ./init_functions
...
default_mount_handler() {
    if [ ! -b "$root" ]; then
        err "Unable to find root device '$root'."
        echo "You are being dropped to a recovery shell"
        echo "    Type 'exit' to try and continue booting"
        launch_interactive_shell
        msg "Trying to continue (this will most likely fail) ..."
    fi
    msg ":: mounting '$root' on real root"
    if ! mount ${fstype:+-t $fstype} -o ${rwopt:-ro}${rootflags:+,$rootflags} "$root" "$1"; then
        echo "You are now being dropped into an emergency shell."
        launch_interactive_shell
        msg "Trying to continue (this will most likely fail) ..."
    fi
}
...
Run Code Online (Sandbox Code Playgroud)