You are not logged in.

#1 2025-08-24 12:44:37

akuya
Member
Registered: 2025-08-24
Posts: 3

[Sloved] mkinitcpio ERROR: Hook 'luks_unlock' cannot be found

I am trying to build a full-disk encryption scheme in ArchLinux. I found that GRUB cannot pass header parameters, so I think I need to write a custom hook script to guide the LUKS header and key file.

My core problem is actually how to mount the USB flash drive at startup and successfully unlock LUKS, that is, the LUKS header and key file problem.

I am attempting to set up a custom mkinitcpio hook on Arch Linux to decrypt my root partition using a key file and header file from a USB drive during system boot.

However, I am encountering an issue: despite confirming that the files exist and are configured correctly, mkinitcpio continues to report an error stating that the hook cannot be found.

Here is my device architecture:

```none
AMD R7 H255
24GB DDR5 4800MHz RAM
A TF card inserted into a card reader forms the USB
The hard drive is a 1TB NVMe drive

```

These are the image parameters I used to install the system:
archlinux-2025.08.01-x86_64

```bash
[root@archiso hooks]# uname -a
Linux archiso 6.15.8-arch1-2 #1 SMP PREEMPT_DYNAMIC Tue, 29 Jul 2025 15:05:00 +0000 x86_64 GNU/Linux
[root@archiso hooks]#
```

My plan is to construct a full-disk encryption system with the EFI boot keyfile and LUKS header all located on the USB drive in a secure architecture.

/dev/sda1 for EFI
/dev/sda2 for /boot
/dev/sda3 for keyfile
/dev/sda4 for LUKS header

/dev/nvme0n1 One Full Encrypt Disk but there is not a LUKS header on it

```bash
[root@archiso etc]# ls /key/
keyfile
[root@archiso etc]# ls /header/
0header.img
[root@archiso etc]#
```


The following is some data I collected in the arch-chroot environment of ArchISO.
I also checked his binary data to prevent invisible characters from causing interference.
I type the `chmod +x` for the two files but it still error when mkinitcpio

## 1.Partition structure

```bash
[root@archiso ~]# lsblk -f
NAME          FSTYPE      FSVER     LABEL       UUID                                   FSAVAIL FSUSE% MOUNTPOINTS
loop0         squashfs    4.0
sda
├─sda1        vfat        FAT32                 899B-AC94                              1021.8M     0% /efi
├─sda2        ext4        1.0                   70da482e-f647-47c2-acd6-c1b208c8a2a8      1.5G    15% /boot
├─sda3        vfat        FAT32                 8A4D-AE92                                  10G     0% /key
└─sda4        vfat        FAT32                 8A76-DBEB                                  10G     0% /header
sdb
├─sdb1        ntfs                  Ventoy      58C04941C049269A
│ └─ventoy    iso9660     Joliet Ex ARCH_202508 2025-08-01-13-39-26-00
└─sdb2        vfat        FAT16     VTOYEFI     223C-F3F8
nvme0n1
└─crypt_system
  │           LVM2_member LVM2 001              FonZj4-Enqi-PWvJ-kTJc-T9MI-HSuQ-sdYXfN
  ├─system-lv_root
  │           ext4        1.0                   4d338a11-4fa6-4465-8ac6-6913b22c64b5    369.8G     1% /
  ├─system-lv_home
  │           ext4        1.0                   2b4b5ef1-9e04-4eb0-8820-72147db656f5    139.1G     0% /home
  └─system-lv_vm
              ext4        1.0                   d126b9b3-70bb-4c3a-981a-b6d1b1ee569d    372.6G     0% /vm
[root@archiso ~]#

```

---
## 2.hook script

### luks_unlock(/etc/initcpio/hooks)

```bash
[root@archiso hooks]# pwd
/etc/initcpio/hooks
[root@archiso hooks]# cat luks_unlock
#!/bin/sh

readonly KEY_UUID="8A4D-AE92"
readonly HEADER_UUID="8A76-DBEB"
readonly KEY_MOUNT_POINT="/key"
readonly HEADER_MOUNT_POINT="/header"

install() {

    install_bin '/usr/bin/mount'
    install_bin '/usr/bin/mkdir'
    install_bin '/usr/bin/lsblk'
    install_bin '/usr/bin/cryptsetup'

    install_script '/etc/initcpio/install/luks_unlock_exec' '/usr/bin/luks_unlock_exec'

}

run_hook() {

    /usr/bin/luks_unlock_exec
}

if [ -n "$run_hook" ]; then
    run_hook
else
    install
fi

```



```bash
root@archiso hooks]# hexdump -C -n 1024 luks_unlock
00000000  23 21 2f 62 69 6e 2f 73  68 0a 0a 72 65 61 64 6f  |#!/bin/sh..reado|
00000010  6e 6c 79 20 4b 45 59 5f  55 55 49 44 3d 22 38 41  |nly KEY_UUID="8A|
00000020  34 44 2d 41 45 39 32 22  0a 72 65 61 64 6f 6e 6c  |4D-AE92".readonl|
00000030  79 20 48 45 41 44 45 52  5f 55 55 49 44 3d 22 38  |y HEADER_UUID="8|
00000040  41 37 36 2d 44 42 45 42  22 0a 72 65 61 64 6f 6e  |A76-DBEB".readon|
00000050  6c 79 20 4b 45 59 5f 4d  4f 55 4e 54 5f 50 4f 49  |ly KEY_MOUNT_POI|
00000060  4e 54 3d 22 2f 6b 65 79  22 0a 72 65 61 64 6f 6e  |NT="/key".readon|
00000070  6c 79 20 48 45 41 44 45  52 5f 4d 4f 55 4e 54 5f  |ly HEADER_MOUNT_|
00000080  50 4f 49 4e 54 3d 22 2f  68 65 61 64 65 72 22 0a  |POINT="/header".|
00000090  0a 69 6e 73 74 61 6c 6c  28 29 20 7b 0a 0a 20 20  |.install() {..  |
000000a0  20 20 69 6e 73 74 61 6c  6c 5f 62 69 6e 20 27 2f  |  install_bin '/|
000000b0  75 73 72 2f 62 69 6e 2f  6d 6f 75 6e 74 27 0a 20  |usr/bin/mount'. |
000000c0  20 20 20 69 6e 73 74 61  6c 6c 5f 62 69 6e 20 27  |   install_bin '|
000000d0  2f 75 73 72 2f 62 69 6e  2f 6d 6b 64 69 72 27 0a  |/usr/bin/mkdir'.|
000000e0  20 20 20 20 69 6e 73 74  61 6c 6c 5f 62 69 6e 20  |    install_bin |
000000f0  27 2f 75 73 72 2f 62 69  6e 2f 6c 73 62 6c 6b 27  |'/usr/bin/lsblk'|
00000100  0a 20 20 20 20 69 6e 73  74 61 6c 6c 5f 62 69 6e  |.    install_bin|
00000110  20 27 2f 75 73 72 2f 62  69 6e 2f 63 72 79 70 74  | '/usr/bin/crypt|
00000120  73 65 74 75 70 27 0a 0a  20 20 20 20 69 6e 73 74  |setup'..    inst|
00000130  61 6c 6c 5f 73 63 72 69  70 74 20 27 2f 65 74 63  |all_script '/etc|
00000140  2f 69 6e 69 74 63 70 69  6f 2f 69 6e 73 74 61 6c  |/initcpio/instal|
00000150  6c 2f 6c 75 6b 73 5f 75  6e 6c 6f 63 6b 5f 65 78  |l/luks_unlock_ex|
00000160  65 63 27 20 27 2f 75 73  72 2f 62 69 6e 2f 6c 75  |ec' '/usr/bin/lu|
00000170  6b 73 5f 75 6e 6c 6f 63  6b 5f 65 78 65 63 27 0a  |ks_unlock_exec'.|
00000180  0a 7d 0a 0a 72 75 6e 5f  68 6f 6f 6b 28 29 20 7b  |.}..run_hook() {|
00000190  0a 0a 20 20 20 20 2f 75  73 72 2f 62 69 6e 2f 6c  |..    /usr/bin/l|
000001a0  75 6b 73 5f 75 6e 6c 6f  63 6b 5f 65 78 65 63 0a  |uks_unlock_exec.|
000001b0  7d 0a 0a 69 66 20 5b 20  2d 6e 20 22 24 72 75 6e  |}..if [ -n "$run|
000001c0  5f 68 6f 6f 6b 22 20 5d  3b 20 74 68 65 6e 0a 20  |_hook" ]; then. |
000001d0  20 20 20 72 75 6e 5f 68  6f 6f 6b 0a 65 6c 73 65  |   run_hook.else|
000001e0  0a 20 20 20 20 69 6e 73  74 61 6c 6c 0a 66 69 0a  |.    install.fi.|
000001f0
[root@archiso hooks]#
```

---
### luks_unlock_exec(/etc/initcpio/install)

```bash
[root@archiso install]# pwd
/etc/initcpio/install
[root@archiso install]# cat luks_unlock_exec
#!/bin/sh

log_message() {
    echo "Custom LUKS Hook: $1"
}

# 1.Search first Udisk part

log_message "Searching for device with UUID $KEY_UUID..."
KEY_DEV=$(lsblk -o UUID,NAME | grep "$KEY_UUID" | awk '{print $2}')

if [ -z "$KEY_DEV" ]; then
    log_message "Device with UUID $KEY_UUID not found. Aborting."
    exit 1
fi

log_message "Found key device: /dev/$KEY_DEV. Attempting to mount..."
mkdir -p "$KEY_MOUNT_POINT"
mount -o ro "/dev/$KEY_DEV" "$KEY_MOUNT_POINT"

if [ $? -ne 0 ]; then
    log_message "Failed to mount key device. Aborting."
    exit 1
fi
log_message "Successfully mounted key device."


# 2.Search Second Udisk part

log_message "Searching for device with UUID $HEADER_UUID..."
HEADER_DEV=$(lsblk -o UUID,NAME | grep "$HEADER_UUID" | awk '{print $2}')

if [ -z "$HEADER_DEV" ]; then
    log_message "Device with UUID $HEADER_UUID not found. Aborting."
    exit 1
fi

log_message "Found header device: /dev/$HEADER_DEV. Attempting to mount..."
mkdir -p "$HEADER_MOUNT_POINT"
mount -o ro "/dev/$HEADER_DEV" "$HEADER_MOUNT_POINT"

if [ $? -ne 0 ]; then
    log_message "Failed to mount header device. Aborting."
    umount "$KEY_MOUNT_POINT"
    exit 1
fi
log_message "Successfully mounted header device."


log_message "Executing cryptsetup luksOpen..."
cryptsetup --header "$HEADER_MOUNT_POINT/0header.img" --key-file "$KEY_MOUNT_POINT/keyfile" luksOpen /dev/nvme0n1 crypt_system

if [ $? -ne 0 ]; then
    log_message "cryptsetup failed. Aborting."
    umount "$KEY_MOUNT_POINT"
    umount "$HEADER_MOUNT_POINT"
    exit 1
fi

```


```bash
[root@archiso install]# hexdump -C -n 1024 luks_unlock_exec
00000000  23 21 2f 62 69 6e 2f 73  68 0a 0a 6c 6f 67 5f 6d  |#!/bin/sh..log_m|
00000010  65 73 73 61 67 65 28 29  20 7b 0a 20 20 20 20 65  |essage() {.    e|
00000020  63 68 6f 20 22 43 75 73  74 6f 6d 20 4c 55 4b 53  |cho "Custom LUKS|
00000030  20 48 6f 6f 6b 3a 20 24  31 22 0a 7d 0a 0a 23 20  | Hook: $1".}..# |
00000040  31 2e 53 65 61 72 63 68  20 66 69 72 73 74 20 55  |1.Search first U|
00000050  64 69 73 6b 20 70 61 72  74 0a 0a 6c 6f 67 5f 6d  |disk part..log_m|
00000060  65 73 73 61 67 65 20 22  53 65 61 72 63 68 69 6e  |essage "Searchin|
00000070  67 20 66 6f 72 20 64 65  76 69 63 65 20 77 69 74  |g for device wit|
00000080  68 20 55 55 49 44 20 24  4b 45 59 5f 55 55 49 44  |h UUID $KEY_UUID|
00000090  2e 2e 2e 22 0a 4b 45 59  5f 44 45 56 3d 24 28 6c  |...".KEY_DEV=$(l|
000000a0  73 62 6c 6b 20 2d 6f 20  55 55 49 44 2c 4e 41 4d  |sblk -o UUID,NAM|
000000b0  45 20 7c 20 67 72 65 70  20 22 24 4b 45 59 5f 55  |E | grep "$KEY_U|
000000c0  55 49 44 22 20 7c 20 61  77 6b 20 27 7b 70 72 69  |UID" | awk '{pri|
000000d0  6e 74 20 24 32 7d 27 29  0a 0a 69 66 20 5b 20 2d  |nt $2}')..if [ -|
000000e0  7a 20 22 24 4b 45 59 5f  44 45 56 22 20 5d 3b 20  |z "$KEY_DEV" ]; |
000000f0  74 68 65 6e 0a 20 20 20  20 6c 6f 67 5f 6d 65 73  |then.    log_mes|
00000100  73 61 67 65 20 22 44 65  76 69 63 65 20 77 69 74  |sage "Device wit|
00000110  68 20 55 55 49 44 20 24  4b 45 59 5f 55 55 49 44  |h UUID $KEY_UUID|
00000120  20 6e 6f 74 20 66 6f 75  6e 64 2e 20 41 62 6f 72  | not found. Abor|
00000130  74 69 6e 67 2e 22 0a 20  20 20 20 65 78 69 74 20  |ting.".    exit |
00000140  31 0a 66 69 0a 0a 6c 6f  67 5f 6d 65 73 73 61 67  |1.fi..log_messag|
00000150  65 20 22 46 6f 75 6e 64  20 6b 65 79 20 64 65 76  |e "Found key dev|
00000160  69 63 65 3a 20 2f 64 65  76 2f 24 4b 45 59 5f 44  |ice: /dev/$KEY_D|
00000170  45 56 2e 20 41 74 74 65  6d 70 74 69 6e 67 20 74  |EV. Attempting t|
00000180  6f 20 6d 6f 75 6e 74 2e  2e 2e 22 0a 6d 6b 64 69  |o mount...".mkdi|
00000190  72 20 2d 70 20 22 24 4b  45 59 5f 4d 4f 55 4e 54  |r -p "$KEY_MOUNT|
000001a0  5f 50 4f 49 4e 54 22 0a  6d 6f 75 6e 74 20 2d 6f  |_POINT".mount -o|
000001b0  20 72 6f 20 22 2f 64 65  76 2f 24 4b 45 59 5f 44  | ro "/dev/$KEY_D|
000001c0  45 56 22 20 22 24 4b 45  59 5f 4d 4f 55 4e 54 5f  |EV" "$KEY_MOUNT_|
000001d0  50 4f 49 4e 54 22 0a 0a  69 66 20 5b 20 24 3f 20  |POINT"..if [ $? |
000001e0  2d 6e 65 20 30 20 5d 3b  20 74 68 65 6e 0a 20 20  |-ne 0 ]; then.  |
000001f0  20 20 6c 6f 67 5f 6d 65  73 73 61 67 65 20 22 46  |  log_message "F|
00000200  61 69 6c 65 64 20 74 6f  20 6d 6f 75 6e 74 20 6b  |ailed to mount k|
00000210  65 79 20 64 65 76 69 63  65 2e 20 41 62 6f 72 74  |ey device. Abort|
00000220  69 6e 67 2e 22 0a 20 20  20 20 65 78 69 74 20 31  |ing.".    exit 1|
00000230  0a 66 69 0a 6c 6f 67 5f  6d 65 73 73 61 67 65 20  |.fi.log_message |
00000240  22 53 75 63 63 65 73 73  66 75 6c 6c 79 20 6d 6f  |"Successfully mo|
00000250  75 6e 74 65 64 20 6b 65  79 20 64 65 76 69 63 65  |unted key device|
00000260  2e 22 0a 0a 0a 23 20 32  2e 53 65 61 72 63 68 20  |."...# 2.Search |
00000270  53 65 63 6f 6e 64 20 55  64 69 73 6b 20 70 61 72  |Second Udisk par|
00000280  74 20 0a 0a 6c 6f 67 5f  6d 65 73 73 61 67 65 20  |t ..log_message |
00000290  22 53 65 61 72 63 68 69  6e 67 20 66 6f 72 20 64  |"Searching for d|
000002a0  65 76 69 63 65 20 77 69  74 68 20 55 55 49 44 20  |evice with UUID |
000002b0  24 48 45 41 44 45 52 5f  55 55 49 44 2e 2e 2e 22  |$HEADER_UUID..."|
000002c0  0a 48 45 41 44 45 52 5f  44 45 56 3d 24 28 6c 73  |.HEADER_DEV=$(ls|
000002d0  62 6c 6b 20 2d 6f 20 55  55 49 44 2c 4e 41 4d 45  |blk -o UUID,NAME|
000002e0  20 7c 20 67 72 65 70 20  22 24 48 45 41 44 45 52  | | grep "$HEADER|
000002f0  5f 55 55 49 44 22 20 7c  20 61 77 6b 20 27 7b 70  |_UUID" | awk '{p|
00000300  72 69 6e 74 20 24 32 7d  27 29 0a 0a 69 66 20 5b  |rint $2}')..if [|
00000310  20 2d 7a 20 22 24 48 45  41 44 45 52 5f 44 45 56  | -z "$HEADER_DEV|
00000320  22 20 5d 3b 20 74 68 65  6e 0a 20 20 20 20 6c 6f  |" ]; then.    lo|
00000330  67 5f 6d 65 73 73 61 67  65 20 22 44 65 76 69 63  |g_message "Devic|
00000340  65 20 77 69 74 68 20 55  55 49 44 20 24 48 45 41  |e with UUID $HEA|
00000350  44 45 52 5f 55 55 49 44  20 6e 6f 74 20 66 6f 75  |DER_UUID not fou|
00000360  6e 64 2e 20 41 62 6f 72  74 69 6e 67 2e 22 0a 20  |nd. Aborting.". |
00000370  20 20 20 65 78 69 74 20  31 0a 66 69 0a 0a 6c 6f  |   exit 1.fi..lo|
00000380  67 5f 6d 65 73 73 61 67  65 20 22 46 6f 75 6e 64  |g_message "Found|
00000390  20 68 65 61 64 65 72 20  64 65 76 69 63 65 3a 20  | header device: |
000003a0  2f 64 65 76 2f 24 48 45  41 44 45 52 5f 44 45 56  |/dev/$HEADER_DEV|
000003b0  2e 20 41 74 74 65 6d 70  74 69 6e 67 20 74 6f 20  |. Attempting to |
000003c0  6d 6f 75 6e 74 2e 2e 2e  22 0a 6d 6b 64 69 72 20  |mount...".mkdir |
000003d0  2d 70 20 22 24 48 45 41  44 45 52 5f 4d 4f 55 4e  |-p "$HEADER_MOUN|
000003e0  54 5f 50 4f 49 4e 54 22  0a 6d 6f 75 6e 74 20 2d  |T_POINT".mount -|
000003f0  6f 20 72 6f 20 22 2f 64  65 76 2f 24 48 45 41 44  |o ro "/dev/$HEAD|
00000400
[root@archiso install]#
```

---

### mkinitcpio.conf

```bash
[root@archiso etc]# cat mkinitcpio.conf
# vim:set ft=sh
# MODULES
# The following modules are loaded before any boot hooks are
# run.  Advanced users may wish to specify all system modules
# in this array.  For instance:
#     MODULES=(usbhid xhci_hcd)
MODULES=(vfat xhci_pci nvme nvme_core)

# BINARIES
# This setting includes any additional binaries a given user may
# wish into the CPIO image.  This is run last, so it may be used to
# override the actual binaries included by a given hook
# BINARIES are dependency parsed, so you may safely ignore libraries
BINARIES=()

# FILES
# This setting is similar to BINARIES above, however, files are added
# as-is and are not parsed in any way.  This is useful for config files.
FILES=()

# HOOKS
# This is the most important setting in this file.  The HOOKS control the
# modules and scripts added to the image, and what happens at boot time.
# Order is important, and it is recommended that you do not change the
# order in which HOOKS are added.  Run 'mkinitcpio -H <hook name>' for
# help on a given hook.
# 'base' is _required_ unless you know precisely what you are doing.
# 'udev' is _required_ in order to automatically load modules
# 'filesystems' is _required_ unless you specify your fs modules in MODULES
# Examples:
##   This setup specifies all modules in the MODULES setting above.
##   No RAID, lvm2, or encrypted root is needed.
#    HOOKS=(base)
#
##   This setup will autodetect all modules for your system and should
##   work as a sane default
#    HOOKS=(base udev autodetect modconf block filesystems fsck)
#
##   This setup will generate a 'full' image which supports most systems.
##   No autodetection is done.
#    HOOKS=(base udev modconf block filesystems fsck)
#
##   This setup assembles a mdadm array with an encrypted root file system.
##   Note: See 'mkinitcpio -H mdadm_udev' for more information on RAID devices.
#    HOOKS=(base udev modconf keyboard keymap consolefont block mdadm_udev encrypt filesystems fsck)
#
##   This setup loads an lvm2 volume group.
#    HOOKS=(base udev modconf block lvm2 filesystems fsck)
#
##   This will create a systemd based initramfs which loads an encrypted root filesystem.
#    HOOKS=(base systemd autodetect modconf kms keyboard sd-vconsole sd-encrypt block filesystems fsck)
#
##   NOTE: If you have /usr on a separate partition, you MUST include the
#    usr and fsck hooks.
HOOKS=(base udev autodetect microcode modconf kms keyboard keymap consolefont block luks_unlock lvm2  filesystems fsck)

# COMPRESSION
# Use this to compress the initramfs image. By default, zstd compression
# is used for Linux ≥ 5.9 and gzip compression is used for Linux < 5.9.
# Use 'cat' to create an uncompressed image.
#COMPRESSION="zstd"
#COMPRESSION="gzip"
#COMPRESSION="bzip2"
#COMPRESSION="lzma"
#COMPRESSION="xz"
#COMPRESSION="lzop"
#COMPRESSION="lz4"

# COMPRESSION_OPTIONS
# Additional options for the compressor
#COMPRESSION_OPTIONS=()

# MODULES_DECOMPRESS
# Decompress loadable kernel modules and their firmware during initramfs
# creation. Switch (yes/no).
# Enable to allow further decreasing image size when using high compression
# (e.g. xz -9e or zstd --long --ultra -22) at the expense of increased RAM usage
# at early boot.
# Note that any compressed files will be placed in the uncompressed early CPIO
# to avoid double compression.
#MODULES_DECOMPRESS="no"
[root@archiso etc]#
```

---

```bash
[root@archiso etc]# hexdump -C  mkinitcpio.conf
00000000  23 20 76 69 6d 3a 73 65  74 20 66 74 3d 73 68 0a  |# vim:set ft=sh.|
00000010  23 20 4d 4f 44 55 4c 45  53 0a 23 20 54 68 65 20  |# MODULES.# The |
00000020  66 6f 6c 6c 6f 77 69 6e  67 20 6d 6f 64 75 6c 65  |following module|
00000030  73 20 61 72 65 20 6c 6f  61 64 65 64 20 62 65 66  |s are loaded bef|
00000040  6f 72 65 20 61 6e 79 20  62 6f 6f 74 20 68 6f 6f  |ore any boot hoo|
00000050  6b 73 20 61 72 65 0a 23  20 72 75 6e 2e 20 20 41  |ks are.# run.  A|
00000060  64 76 61 6e 63 65 64 20  75 73 65 72 73 20 6d 61  |dvanced users ma|
00000070  79 20 77 69 73 68 20 74  6f 20 73 70 65 63 69 66  |y wish to specif|
00000080  79 20 61 6c 6c 20 73 79  73 74 65 6d 20 6d 6f 64  |y all system mod|
00000090  75 6c 65 73 0a 23 20 69  6e 20 74 68 69 73 20 61  |ules.# in this a|
000000a0  72 72 61 79 2e 20 20 46  6f 72 20 69 6e 73 74 61  |rray.  For insta|
000000b0  6e 63 65 3a 0a 23 20 20  20 20 20 4d 4f 44 55 4c  |nce:.#     MODUL|
000000c0  45 53 3d 28 75 73 62 68  69 64 20 78 68 63 69 5f  |ES=(usbhid xhci_|
000000d0  68 63 64 29 0a 4d 4f 44  55 4c 45 53 3d 28 76 66  |hcd).MODULES=(vf|
000000e0  61 74 20 78 68 63 69 5f  70 63 69 20 6e 76 6d 65  |at xhci_pci nvme|
000000f0  20 6e 76 6d 65 5f 63 6f  72 65 29 0a 0a 23 20 42  | nvme_core)..# B|
00000100  49 4e 41 52 49 45 53 0a  23 20 54 68 69 73 20 73  |INARIES.# This s|
00000110  65 74 74 69 6e 67 20 69  6e 63 6c 75 64 65 73 20  |etting includes |
00000120  61 6e 79 20 61 64 64 69  74 69 6f 6e 61 6c 20 62  |any additional b|
00000130  69 6e 61 72 69 65 73 20  61 20 67 69 76 65 6e 20  |inaries a given |
00000140  75 73 65 72 20 6d 61 79  0a 23 20 77 69 73 68 20  |user may.# wish |
00000150  69 6e 74 6f 20 74 68 65  20 43 50 49 4f 20 69 6d  |into the CPIO im|
00000160  61 67 65 2e 20 20 54 68  69 73 20 69 73 20 72 75  |age.  This is ru|
00000170  6e 20 6c 61 73 74 2c 20  73 6f 20 69 74 20 6d 61  |n last, so it ma|
00000180  79 20 62 65 20 75 73 65  64 20 74 6f 0a 23 20 6f  |y be used to.# o|
00000190  76 65 72 72 69 64 65 20  74 68 65 20 61 63 74 75  |verride the actu|
000001a0  61 6c 20 62 69 6e 61 72  69 65 73 20 69 6e 63 6c  |al binaries incl|
000001b0  75 64 65 64 20 62 79 20  61 20 67 69 76 65 6e 20  |uded by a given |
000001c0  68 6f 6f 6b 0a 23 20 42  49 4e 41 52 49 45 53 20  |hook.# BINARIES |
000001d0  61 72 65 20 64 65 70 65  6e 64 65 6e 63 79 20 70  |are dependency p|
000001e0  61 72 73 65 64 2c 20 73  6f 20 79 6f 75 20 6d 61  |arsed, so you ma|
000001f0  79 20 73 61 66 65 6c 79  20 69 67 6e 6f 72 65 20  |y safely ignore |
00000200  6c 69 62 72 61 72 69 65  73 0a 42 49 4e 41 52 49  |libraries.BINARI|
00000210  45 53 3d 28 29 0a 0a 23  20 46 49 4c 45 53 0a 23  |ES=()..# FILES.#|
00000220  20 54 68 69 73 20 73 65  74 74 69 6e 67 20 69 73  | This setting is|
00000230  20 73 69 6d 69 6c 61 72  20 74 6f 20 42 49 4e 41  | similar to BINA|
00000240  52 49 45 53 20 61 62 6f  76 65 2c 20 68 6f 77 65  |RIES above, howe|
00000250  76 65 72 2c 20 66 69 6c  65 73 20 61 72 65 20 61  |ver, files are a|
00000260  64 64 65 64 0a 23 20 61  73 2d 69 73 20 61 6e 64  |dded.# as-is and|
00000270  20 61 72 65 20 6e 6f 74  20 70 61 72 73 65 64 20  | are not parsed |
00000280  69 6e 20 61 6e 79 20 77  61 79 2e 20 20 54 68 69  |in any way.  Thi|
00000290  73 20 69 73 20 75 73 65  66 75 6c 20 66 6f 72 20  |s is useful for |
000002a0  63 6f 6e 66 69 67 20 66  69 6c 65 73 2e 0a 46 49  |config files..FI|
000002b0  4c 45 53 3d 28 29 0a 0a  23 20 48 4f 4f 4b 53 0a  |LES=()..# HOOKS.|
000002c0  23 20 54 68 69 73 20 69  73 20 74 68 65 20 6d 6f  |# This is the mo|
000002d0  73 74 20 69 6d 70 6f 72  74 61 6e 74 20 73 65 74  |st important set|
000002e0  74 69 6e 67 20 69 6e 20  74 68 69 73 20 66 69 6c  |ting in this fil|
000002f0  65 2e 20 20 54 68 65 20  48 4f 4f 4b 53 20 63 6f  |e.  The HOOKS co|
00000300  6e 74 72 6f 6c 20 74 68  65 0a 23 20 6d 6f 64 75  |ntrol the.# modu|
00000310  6c 65 73 20 61 6e 64 20  73 63 72 69 70 74 73 20  |les and scripts |
00000320  61 64 64 65 64 20 74 6f  20 74 68 65 20 69 6d 61  |added to the ima|
00000330  67 65 2c 20 61 6e 64 20  77 68 61 74 20 68 61 70  |ge, and what hap|
00000340  70 65 6e 73 20 61 74 20  62 6f 6f 74 20 74 69 6d  |pens at boot tim|
00000350  65 2e 0a 23 20 4f 72 64  65 72 20 69 73 20 69 6d  |e..# Order is im|
00000360  70 6f 72 74 61 6e 74 2c  20 61 6e 64 20 69 74 20  |portant, and it |
00000370  69 73 20 72 65 63 6f 6d  6d 65 6e 64 65 64 20 74  |is recommended t|
00000380  68 61 74 20 79 6f 75 20  64 6f 20 6e 6f 74 20 63  |hat you do not c|
00000390  68 61 6e 67 65 20 74 68  65 0a 23 20 6f 72 64 65  |hange the.# orde|
000003a0  72 20 69 6e 20 77 68 69  63 68 20 48 4f 4f 4b 53  |r in which HOOKS|
000003b0  20 61 72 65 20 61 64 64  65 64 2e 20 20 52 75 6e  | are added.  Run|
000003c0  20 27 6d 6b 69 6e 69 74  63 70 69 6f 20 2d 48 20  | 'mkinitcpio -H |
000003d0  3c 68 6f 6f 6b 20 6e 61  6d 65 3e 27 20 66 6f 72  |<hook name>' for|
000003e0  0a 23 20 68 65 6c 70 20  6f 6e 20 61 20 67 69 76  |.# help on a giv|
000003f0  65 6e 20 68 6f 6f 6b 2e  0a 23 20 27 62 61 73 65  |en hook..# 'base|
00000400  27 20 69 73 20 5f 72 65  71 75 69 72 65 64 5f 20  |' is _required_ |
00000410  75 6e 6c 65 73 73 20 79  6f 75 20 6b 6e 6f 77 20  |unless you know |
00000420  70 72 65 63 69 73 65 6c  79 20 77 68 61 74 20 79  |precisely what y|
00000430  6f 75 20 61 72 65 20 64  6f 69 6e 67 2e 0a 23 20  |ou are doing..# |
00000440  27 75 64 65 76 27 20 69  73 20 5f 72 65 71 75 69  |'udev' is _requi|
00000450  72 65 64 5f 20 69 6e 20  6f 72 64 65 72 20 74 6f  |red_ in order to|
00000460  20 61 75 74 6f 6d 61 74  69 63 61 6c 6c 79 20 6c  | automatically l|
00000470  6f 61 64 20 6d 6f 64 75  6c 65 73 0a 23 20 27 66  |oad modules.# 'f|
00000480  69 6c 65 73 79 73 74 65  6d 73 27 20 69 73 20 5f  |ilesystems' is _|
00000490  72 65 71 75 69 72 65 64  5f 20 75 6e 6c 65 73 73  |required_ unless|
000004a0  20 79 6f 75 20 73 70 65  63 69 66 79 20 79 6f 75  | you specify you|
000004b0  72 20 66 73 20 6d 6f 64  75 6c 65 73 20 69 6e 20  |r fs modules in |
000004c0  4d 4f 44 55 4c 45 53 0a  23 20 45 78 61 6d 70 6c  |MODULES.# Exampl|
000004d0  65 73 3a 0a 23 23 20 20  20 54 68 69 73 20 73 65  |es:.##   This se|
000004e0  74 75 70 20 73 70 65 63  69 66 69 65 73 20 61 6c  |tup specifies al|
000004f0  6c 20 6d 6f 64 75 6c 65  73 20 69 6e 20 74 68 65  |l modules in the|
00000500  20 4d 4f 44 55 4c 45 53  20 73 65 74 74 69 6e 67  | MODULES setting|
00000510  20 61 62 6f 76 65 2e 0a  23 23 20 20 20 4e 6f 20  | above..##   No |
00000520  52 41 49 44 2c 20 6c 76  6d 32 2c 20 6f 72 20 65  |RAID, lvm2, or e|
00000530  6e 63 72 79 70 74 65 64  20 72 6f 6f 74 20 69 73  |ncrypted root is|
00000540  20 6e 65 65 64 65 64 2e  0a 23 20 20 20 20 48 4f  | needed..#    HO|
00000550  4f 4b 53 3d 28 62 61 73  65 29 0a 23 0a 23 23 20  |OKS=(base).#.## |
00000560  20 20 54 68 69 73 20 73  65 74 75 70 20 77 69 6c  |  This setup wil|
00000570  6c 20 61 75 74 6f 64 65  74 65 63 74 20 61 6c 6c  |l autodetect all|
00000580  20 6d 6f 64 75 6c 65 73  20 66 6f 72 20 79 6f 75  | modules for you|
00000590  72 20 73 79 73 74 65 6d  20 61 6e 64 20 73 68 6f  |r system and sho|
000005a0  75 6c 64 0a 23 23 20 20  20 77 6f 72 6b 20 61 73  |uld.##   work as|
000005b0  20 61 20 73 61 6e 65 20  64 65 66 61 75 6c 74 0a  | a sane default.|
000005c0  23 20 20 20 20 48 4f 4f  4b 53 3d 28 62 61 73 65  |#    HOOKS=(base|
000005d0  20 75 64 65 76 20 61 75  74 6f 64 65 74 65 63 74  | udev autodetect|
000005e0  20 6d 6f 64 63 6f 6e 66  20 62 6c 6f 63 6b 20 66  | modconf block f|
000005f0  69 6c 65 73 79 73 74 65  6d 73 20 66 73 63 6b 29  |ilesystems fsck)|
00000600  0a 23 0a 23 23 20 20 20  54 68 69 73 20 73 65 74  |.#.##   This set|
00000610  75 70 20 77 69 6c 6c 20  67 65 6e 65 72 61 74 65  |up will generate|
00000620  20 61 20 27 66 75 6c 6c  27 20 69 6d 61 67 65 20  | a 'full' image |
00000630  77 68 69 63 68 20 73 75  70 70 6f 72 74 73 20 6d  |which supports m|
00000640  6f 73 74 20 73 79 73 74  65 6d 73 2e 0a 23 23 20  |ost systems..## |
00000650  20 20 4e 6f 20 61 75 74  6f 64 65 74 65 63 74 69  |  No autodetecti|
00000660  6f 6e 20 69 73 20 64 6f  6e 65 2e 0a 23 20 20 20  |on is done..#   |
00000670  20 48 4f 4f 4b 53 3d 28  62 61 73 65 20 75 64 65  | HOOKS=(base ude|
00000680  76 20 6d 6f 64 63 6f 6e  66 20 62 6c 6f 63 6b 20  |v modconf block |
00000690  66 69 6c 65 73 79 73 74  65 6d 73 20 66 73 63 6b  |filesystems fsck|
000006a0  29 0a 23 0a 23 23 20 20  20 54 68 69 73 20 73 65  |).#.##   This se|
000006b0  74 75 70 20 61 73 73 65  6d 62 6c 65 73 20 61 20  |tup assembles a |
000006c0  6d 64 61 64 6d 20 61 72  72 61 79 20 77 69 74 68  |mdadm array with|
000006d0  20 61 6e 20 65 6e 63 72  79 70 74 65 64 20 72 6f  | an encrypted ro|
000006e0  6f 74 20 66 69 6c 65 20  73 79 73 74 65 6d 2e 0a  |ot file system..|
000006f0  23 23 20 20 20 4e 6f 74  65 3a 20 53 65 65 20 27  |##   Note: See '|
00000700  6d 6b 69 6e 69 74 63 70  69 6f 20 2d 48 20 6d 64  |mkinitcpio -H md|
00000710  61 64 6d 5f 75 64 65 76  27 20 66 6f 72 20 6d 6f  |adm_udev' for mo|
00000720  72 65 20 69 6e 66 6f 72  6d 61 74 69 6f 6e 20 6f  |re information o|
00000730  6e 20 52 41 49 44 20 64  65 76 69 63 65 73 2e 0a  |n RAID devices..|
00000740  23 20 20 20 20 48 4f 4f  4b 53 3d 28 62 61 73 65  |#    HOOKS=(base|
00000750  20 75 64 65 76 20 6d 6f  64 63 6f 6e 66 20 6b 65  | udev modconf ke|
00000760  79 62 6f 61 72 64 20 6b  65 79 6d 61 70 20 63 6f  |yboard keymap co|
00000770  6e 73 6f 6c 65 66 6f 6e  74 20 62 6c 6f 63 6b 20  |nsolefont block |
00000780  6d 64 61 64 6d 5f 75 64  65 76 20 65 6e 63 72 79  |mdadm_udev encry|
00000790  70 74 20 66 69 6c 65 73  79 73 74 65 6d 73 20 66  |pt filesystems f|
000007a0  73 63 6b 29 0a 23 0a 23  23 20 20 20 54 68 69 73  |sck).#.##   This|
000007b0  20 73 65 74 75 70 20 6c  6f 61 64 73 20 61 6e 20  | setup loads an |
000007c0  6c 76 6d 32 20 76 6f 6c  75 6d 65 20 67 72 6f 75  |lvm2 volume grou|
000007d0  70 2e 0a 23 20 20 20 20  48 4f 4f 4b 53 3d 28 62  |p..#    HOOKS=(b|
000007e0  61 73 65 20 75 64 65 76  20 6d 6f 64 63 6f 6e 66  |ase udev modconf|
000007f0  20 62 6c 6f 63 6b 20 6c  76 6d 32 20 66 69 6c 65  | block lvm2 file|
00000800  73 79 73 74 65 6d 73 20  66 73 63 6b 29 0a 23 0a  |systems fsck).#.|
00000810  23 23 20 20 20 54 68 69  73 20 77 69 6c 6c 20 63  |##   This will c|
00000820  72 65 61 74 65 20 61 20  73 79 73 74 65 6d 64 20  |reate a systemd |
00000830  62 61 73 65 64 20 69 6e  69 74 72 61 6d 66 73 20  |based initramfs |
00000840  77 68 69 63 68 20 6c 6f  61 64 73 20 61 6e 20 65  |which loads an e|
00000850  6e 63 72 79 70 74 65 64  20 72 6f 6f 74 20 66 69  |ncrypted root fi|
00000860  6c 65 73 79 73 74 65 6d  2e 0a 23 20 20 20 20 48  |lesystem..#    H|
00000870  4f 4f 4b 53 3d 28 62 61  73 65 20 73 79 73 74 65  |OOKS=(base syste|
00000880  6d 64 20 61 75 74 6f 64  65 74 65 63 74 20 6d 6f  |md autodetect mo|
00000890  64 63 6f 6e 66 20 6b 6d  73 20 6b 65 79 62 6f 61  |dconf kms keyboa|
000008a0  72 64 20 73 64 2d 76 63  6f 6e 73 6f 6c 65 20 73  |rd sd-vconsole s|
000008b0  64 2d 65 6e 63 72 79 70  74 20 62 6c 6f 63 6b 20  |d-encrypt block |
000008c0  66 69 6c 65 73 79 73 74  65 6d 73 20 66 73 63 6b  |filesystems fsck|
000008d0  29 0a 23 0a 23 23 20 20  20 4e 4f 54 45 3a 20 49  |).#.##   NOTE: I|
000008e0  66 20 79 6f 75 20 68 61  76 65 20 2f 75 73 72 20  |f you have /usr |
000008f0  6f 6e 20 61 20 73 65 70  61 72 61 74 65 20 70 61  |on a separate pa|
00000900  72 74 69 74 69 6f 6e 2c  20 79 6f 75 20 4d 55 53  |rtition, you MUS|
00000910  54 20 69 6e 63 6c 75 64  65 20 74 68 65 0a 23 20  |T include the.# |
00000920  20 20 20 75 73 72 20 61  6e 64 20 66 73 63 6b 20  |   usr and fsck |
00000930  68 6f 6f 6b 73 2e 0a 48  4f 4f 4b 53 3d 28 62 61  |hooks..HOOKS=(ba|
00000940  73 65 20 75 64 65 76 20  61 75 74 6f 64 65 74 65  |se udev autodete|
00000950  63 74 20 6d 69 63 72 6f  63 6f 64 65 20 6d 6f 64  |ct microcode mod|
00000960  63 6f 6e 66 20 6b 6d 73  20 6b 65 79 62 6f 61 72  |conf kms keyboar|
00000970  64 20 6b 65 79 6d 61 70  20 63 6f 6e 73 6f 6c 65  |d keymap console|
00000980  66 6f 6e 74 20 62 6c 6f  63 6b 20 6c 75 6b 73 5f  |font block luks_|
00000990  75 6e 6c 6f 63 6b 20 6c  76 6d 32 20 20 66 69 6c  |unlock lvm2  fil|
000009a0  65 73 79 73 74 65 6d 73  20 66 73 63 6b 29 0a 0a  |esystems fsck)..|
000009b0  23 20 43 4f 4d 50 52 45  53 53 49 4f 4e 0a 23 20  |# COMPRESSION.# |
000009c0  55 73 65 20 74 68 69 73  20 74 6f 20 63 6f 6d 70  |Use this to comp|
000009d0  72 65 73 73 20 74 68 65  20 69 6e 69 74 72 61 6d  |ress the initram|
000009e0  66 73 20 69 6d 61 67 65  2e 20 42 79 20 64 65 66  |fs image. By def|
000009f0  61 75 6c 74 2c 20 7a 73  74 64 20 63 6f 6d 70 72  |ault, zstd compr|
00000a00  65 73 73 69 6f 6e 0a 23  20 69 73 20 75 73 65 64  |ession.# is used|
00000a10  20 66 6f 72 20 4c 69 6e  75 78 20 e2 89 a5 20 35  | for Linux ... 5|
00000a20  2e 39 20 61 6e 64 20 67  7a 69 70 20 63 6f 6d 70  |.9 and gzip comp|
00000a30  72 65 73 73 69 6f 6e 20  69 73 20 75 73 65 64 20  |ression is used |
00000a40  66 6f 72 20 4c 69 6e 75  78 20 3c 20 35 2e 39 2e  |for Linux < 5.9.|
00000a50  0a 23 20 55 73 65 20 27  63 61 74 27 20 74 6f 20  |.# Use 'cat' to |
00000a60  63 72 65 61 74 65 20 61  6e 20 75 6e 63 6f 6d 70  |create an uncomp|
00000a70  72 65 73 73 65 64 20 69  6d 61 67 65 2e 0a 23 43  |ressed image..#C|
00000a80  4f 4d 50 52 45 53 53 49  4f 4e 3d 22 7a 73 74 64  |OMPRESSION="zstd|
00000a90  22 0a 23 43 4f 4d 50 52  45 53 53 49 4f 4e 3d 22  |".#COMPRESSION="|
00000aa0  67 7a 69 70 22 0a 23 43  4f 4d 50 52 45 53 53 49  |gzip".#COMPRESSI|
00000ab0  4f 4e 3d 22 62 7a 69 70  32 22 0a 23 43 4f 4d 50  |ON="bzip2".#COMP|
00000ac0  52 45 53 53 49 4f 4e 3d  22 6c 7a 6d 61 22 0a 23  |RESSION="lzma".#|
00000ad0  43 4f 4d 50 52 45 53 53  49 4f 4e 3d 22 78 7a 22  |COMPRESSION="xz"|
00000ae0  0a 23 43 4f 4d 50 52 45  53 53 49 4f 4e 3d 22 6c  |.#COMPRESSION="l|
00000af0  7a 6f 70 22 0a 23 43 4f  4d 50 52 45 53 53 49 4f  |zop".#COMPRESSIO|
00000b00  4e 3d 22 6c 7a 34 22 0a  0a 23 20 43 4f 4d 50 52  |N="lz4"..# COMPR|
00000b10  45 53 53 49 4f 4e 5f 4f  50 54 49 4f 4e 53 0a 23  |ESSION_OPTIONS.#|
00000b20  20 41 64 64 69 74 69 6f  6e 61 6c 20 6f 70 74 69  | Additional opti|
00000b30  6f 6e 73 20 66 6f 72 20  74 68 65 20 63 6f 6d 70  |ons for the comp|
00000b40  72 65 73 73 6f 72 0a 23  43 4f 4d 50 52 45 53 53  |ressor.#COMPRESS|
00000b50  49 4f 4e 5f 4f 50 54 49  4f 4e 53 3d 28 29 0a 0a  |ION_OPTIONS=()..|
00000b60  23 20 4d 4f 44 55 4c 45  53 5f 44 45 43 4f 4d 50  |# MODULES_DECOMP|
00000b70  52 45 53 53 0a 23 20 44  65 63 6f 6d 70 72 65 73  |RESS.# Decompres|
00000b80  73 20 6c 6f 61 64 61 62  6c 65 20 6b 65 72 6e 65  |s loadable kerne|
00000b90  6c 20 6d 6f 64 75 6c 65  73 20 61 6e 64 20 74 68  |l modules and th|
00000ba0  65 69 72 20 66 69 72 6d  77 61 72 65 20 64 75 72  |eir firmware dur|
00000bb0  69 6e 67 20 69 6e 69 74  72 61 6d 66 73 0a 23 20  |ing initramfs.# |
00000bc0  63 72 65 61 74 69 6f 6e  2e 20 53 77 69 74 63 68  |creation. Switch|
00000bd0  20 28 79 65 73 2f 6e 6f  29 2e 0a 23 20 45 6e 61  | (yes/no)..# Ena|
00000be0  62 6c 65 20 74 6f 20 61  6c 6c 6f 77 20 66 75 72  |ble to allow fur|
00000bf0  74 68 65 72 20 64 65 63  72 65 61 73 69 6e 67 20  |ther decreasing |
00000c00  69 6d 61 67 65 20 73 69  7a 65 20 77 68 65 6e 20  |image size when |
00000c10  75 73 69 6e 67 20 68 69  67 68 20 63 6f 6d 70 72  |using high compr|
00000c20  65 73 73 69 6f 6e 0a 23  20 28 65 2e 67 2e 20 78  |ession.# (e.g. x|
00000c30  7a 20 2d 39 65 20 6f 72  20 7a 73 74 64 20 2d 2d  |z -9e or zstd --|
00000c40  6c 6f 6e 67 20 2d 2d 75  6c 74 72 61 20 2d 32 32  |long --ultra -22|
00000c50  29 20 61 74 20 74 68 65  20 65 78 70 65 6e 73 65  |) at the expense|
00000c60  20 6f 66 20 69 6e 63 72  65 61 73 65 64 20 52 41  | of increased RA|
00000c70  4d 20 75 73 61 67 65 0a  23 20 61 74 20 65 61 72  |M usage.# at ear|
00000c80  6c 79 20 62 6f 6f 74 2e  0a 23 20 4e 6f 74 65 20  |ly boot..# Note |
00000c90  74 68 61 74 20 61 6e 79  20 63 6f 6d 70 72 65 73  |that any compres|
00000ca0  73 65 64 20 66 69 6c 65  73 20 77 69 6c 6c 20 62  |sed files will b|
00000cb0  65 20 70 6c 61 63 65 64  20 69 6e 20 74 68 65 20  |e placed in the |
00000cc0  75 6e 63 6f 6d 70 72 65  73 73 65 64 20 65 61 72  |uncompressed ear|
00000cd0  6c 79 20 43 50 49 4f 0a  23 20 74 6f 20 61 76 6f  |ly CPIO.# to avo|
00000ce0  69 64 20 64 6f 75 62 6c  65 20 63 6f 6d 70 72 65  |id double compre|
00000cf0  73 73 69 6f 6e 2e 0a 23  4d 4f 44 55 4c 45 53 5f  |ssion..#MODULES_|
00000d00  44 45 43 4f 4d 50 52 45  53 53 3d 22 6e 6f 22 0a  |DECOMPRESS="no".|
00000d10
[root@archiso etc]#
```


```bash
[root@archiso hooks]# pwd
/etc/initcpio/hooks
[root@archiso hooks]# ls
luks_unlock
[root@archiso hooks]# chmod +x luks_unlock
[root@archiso hooks]# chmod +x ../install/luks_unlock_exec
[root@archiso hooks]# mkinitcpio -P
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
==> Using default configuration file: '/etc/mkinitcpio.conf'
  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux.img
==> Starting build: '6.16.3-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [microcode]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [block]
==> ERROR: Hook 'luks_unlock' cannot be found
  -> Running build hook: [lvm2]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux.img'
==> WARNING: errors were encountered during the build. The image may not be complete.
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'
==> Using default configuration file: '/etc/mkinitcpio.conf'
  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux-fallback.img -S autodetect
==> Starting build: '6.16.3-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [microcode]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
==> WARNING: Possibly missing firmware for module: 'ast'
  -> Running build hook: [keyboard]
==> WARNING: Possibly missing firmware for module: 'xhci_pci_renesas'
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'qla2xxx'
==> WARNING: Possibly missing firmware for module: 'aic94xx'
==> WARNING: Possibly missing firmware for module: 'bfa'
==> WARNING: Possibly missing firmware for module: 'qed'
==> WARNING: Possibly missing firmware for module: 'wd719x'
==> WARNING: Possibly missing firmware for module: 'qla1280'
==> ERROR: Hook 'luks_unlock' cannot be found
  -> Running build hook: [lvm2]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux-fallback.img'
==> WARNING: errors were encountered during the build. The image may not be complete.
[root@archiso hooks]#
```


## My other test, but it still reports an error.

```bash
[root@archiso hooks]# cat luks_unlock
#!/bin/sh

install() { install_bin '/usr/bin/echo'; }
run_hook() { echo 'Hello from my hook!'; }
[root@archiso hooks]# chmod +x luks_unlock

[root@archiso hooks]# hexdump -C luks_unlock
00000000  23 21 2f 62 69 6e 2f 73  68 0a 0a 69 6e 73 74 61  |#!/bin/sh..insta|
00000010  6c 6c 28 29 20 7b 20 69  6e 73 74 61 6c 6c 5f 62  |ll() { install_b|
00000020  69 6e 20 27 2f 75 73 72  2f 62 69 6e 2f 65 63 68  |in '/usr/bin/ech|
00000030  6f 27 3b 20 7d 0a 72 75  6e 5f 68 6f 6f 6b 28 29  |o'; }.run_hook()|
00000040  20 7b 20 65 63 68 6f 20  27 48 65 6c 6c 6f 20 66  | { echo 'Hello f|
00000050  72 6f 6d 20 6d 79 20 68  6f 6f 6b 21 27 3b 20 7d  |rom my hook!'; }|
00000060  0a                                                |.|
00000061
[root@archiso hooks]# mkinitcpio -P
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'
==> Using default configuration file: '/etc/mkinitcpio.conf'
  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux.img
==> Starting build: '6.16.3-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [autodetect]
  -> Running build hook: [microcode]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
  -> Running build hook: [keyboard]
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [block]
==> ERROR: Hook 'luks_unlock' cannot be found
  -> Running build hook: [lvm2]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux.img'
==> WARNING: errors were encountered during the build. The image may not be complete.
==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'
==> Using default configuration file: '/etc/mkinitcpio.conf'
  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux-fallback.img -S autodetect
==> Starting build: '6.16.3-arch1-1'
  -> Running build hook: [base]
  -> Running build hook: [udev]
  -> Running build hook: [microcode]
  -> Running build hook: [modconf]
  -> Running build hook: [kms]
==> WARNING: Possibly missing firmware for module: 'ast'
  -> Running build hook: [keyboard]
==> WARNING: Possibly missing firmware for module: 'xhci_pci_renesas'
  -> Running build hook: [keymap]
  -> Running build hook: [consolefont]
==> WARNING: consolefont: no font found in configuration
  -> Running build hook: [block]
==> WARNING: Possibly missing firmware for module: 'qla2xxx'
==> WARNING: Possibly missing firmware for module: 'aic94xx'
==> WARNING: Possibly missing firmware for module: 'bfa'
==> WARNING: Possibly missing firmware for module: 'qed'
==> WARNING: Possibly missing firmware for module: 'wd719x'
==> WARNING: Possibly missing firmware for module: 'qla1280'
==> ERROR: Hook 'luks_unlock' cannot be found
  -> Running build hook: [lvm2]
  -> Running build hook: [filesystems]
  -> Running build hook: [fsck]
==> Generating module dependencies
==> Creating zstd-compressed initcpio image: '/boot/initramfs-linux-fallback.img'
==> WARNING: errors were encountered during the build. The image may not be complete.
[root@archiso hooks]#
```

I would be very grateful if you could offer any advice. (o゜▽゜)o☆

Last edited by akuya (2025-12-04 08:15:20)

Offline

#2 2025-08-25 00:26:05

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 594

Re: [Sloved] mkinitcpio ERROR: Hook 'luks_unlock' cannot be found

Besides /etc/initcpio/hooks/luks_unlock initcpio script you need /etc/initcpio/install/luks_unlock install hook.
Ah, you have /etc/initcpio/install/luks_unlock_exec but specified wrong name "luks_unlock" in mkinitcpio.conf HOOKS=
You can list available hooks with "mkinitcpio -L".

Last edited by dimich (2025-08-25 00:30:35)

Offline

#3 2025-08-25 11:05:58

akuya
Member
Registered: 2025-08-24
Posts: 3

Re: [Sloved] mkinitcpio ERROR: Hook 'luks_unlock' cannot be found

dimich wrote:

Besides /etc/initcpio/hooks/luks_unlock initcpio script you need /etc/initcpio/install/luks_unlock install hook.
Ah, you have /etc/initcpio/install/luks_unlock_exec but specified wrong name "luks_unlock" in mkinitcpio.conf HOOKS=
You can list available hooks with "mkinitcpio -L".

This is the content of the "mkinitcpio -L":
[root@archiso initcpio]# mkinitcpio -L
==> Available hooks
acpi_override   encrypt         keymap          memdisk         sd-shutdown     systemd
autodetect      filesystems     kms             microcode       sd-vconsole     udev
base            fsck            luks_unlock     modconf         shutdown        usr
block           hostdata        lvm2            resume          sleep
consolefont     keyboard        mdadm_udev      sd-encrypt      strip
[root@archiso initcpio]#

I do it just like you . Yes , it could found hook script but there a new quetion.It seems like that mkinitcpio run the script when mkinitcpio -P
Maybe I have error in script?
I think maybe I have problem in what the build script and run script or What is the good hook script?
I check the Arch Wiki. The hook script should found in /etc/initcpio/install/

I check my code. I found my build part in /etc/initcpio/hooks and the run part in /etc/initcpio/install. I didn't found some detailed document so I ask the googlegemini.
But now I ask what the problem why it give me these answer. I found gemini confused between dracut and mkinitcpio.But whatever I do to notice it . It always giving me the wrong answer with reasonable and logical arguments.

So I think maybe the more important issue what is the good way to make a hook script and what is the structure of hook script.
Thank you for your help:)


[ro.o t@archiso install]# mkinitcpio -P

==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'default'

==> Using default configuration file: '/etc/mkinitcpio.conf'

  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux.img

==> Starting build: '6.16.3-arch1-1'

  -> Running build hook: [base]

  -> Running build hook: [udev]

  -> Running build hook: [autodetect]

  -> Running build hook: [microcode]

  -> Running build hook: [modconf]

  -> Running build hook: [kms]

  -> Running build hook: [keyboard]

  -> Running build hook: [keymap]

  -> Running build hook: [consolefont]

==> WARNING: consolefont: no font found in configuration

  -> Running build hook: [block]

Custom LUKS Hook: Searching for device with UUID ...

Custom LUKS Hook: Found key device: /dev/NAME



├─sda1

└─sda2


├─sdb1

├─sdb2

├─sdb3

└─sdb4


└─crypt_system

├─system-lv_root

├─system-lv_home

└─system-lv_vm. Attempting to mount...

mkdir: cannot create directory ‘’: No such file or directory

mount: : fsconfig() failed: /dev/NAME



├─sda1

└─sda2


├─sdb1

├─sdb2

├─sdb3

└─sdb4


└─crypt_system

├─system-lv_root

├─system-lv_home

└─system-lv_vm: Can't lookup blockdev.

       dmesg(1) may have more information after failed mount system call.

mount: (hint) your fstab has been modified, but systemd still uses

       the old version; use 'systemctl daemon-reload' to reload.

Custom LUKS Hook: Failed to mount key device. Aborting.

==> Building image from preset: /etc/mkinitcpio.d/linux.preset: 'fallback'

==> Using default configuration file: '/etc/mkinitcpio.conf'

  -> -k /boot/vmlinuz-linux -g /boot/initramfs-linux-fallback.img -S autodetect

==> Starting build: '6.16.3-arch1-1'

  -> Running build hook: [base]

  -> Running build hook: [udev]

  -> Running build hook: [microcode]

  -> Running build hook: [modconf]

  -> Running build hook: [kms]

==> WARNING: Possibly missing firmware for module: 'ast'

  -> Running build hook: [keyboard]

==> WARNING: Possibly missing firmware for module: 'xhci_pci_renesas'

  -> Running build hook: [keymap]

  -> Running build hook: [consolefont]

==> WARNING: consolefont: no font found in configuration

  -> Running build hook: [block]

==> WARNING: Possibly missing firmware for module: 'wd719x'

==> WARNING: Possibly missing firmware for module: 'qla2xxx'

==> WARNING: Possibly missing firmware for module: 'qla1280'

==> WARNING: Possibly missing firmware for module: 'qed'

==> WARNING: Possibly missing firmware for module: 'aic94xx'

==> WARNING: Possibly missing firmware for module: 'bfa'

Custom LUKS Hook: Searching for device with UUID ...

Custom LUKS Hook: Found key device: /dev/NAME



├─sda1

└─sda2


├─sdb1

├─sdb2

├─sdb3

└─sdb4


└─crypt_system

├─system-lv_root

├─system-lv_home

└─system-lv_vm. Attempting to mount...

mkdir: cannot create directory ‘’: No such file or directory

mount: : fsconfig() failed: /dev/NAME



├─sda1

└─sda2


├─sdb1

├─sdb2

├─sdb3

└─sdb4


└─crypt_system

├─system-lv_root

├─system-lv_home

└─system-lv_vm: Can't lookup blockdev.

       dmesg(1) may have more information after failed mount system call.

mount: (hint) your fstab has been modified, but systemd still uses

       the old version; use 'systemctl daemon-reload' to reload.

Custom LUKS Hook: Failed to mount key device. Aborting.

[root@archiso install]#

Last edited by akuya (2025-08-25 11:46:05)

Offline

#4 2025-08-25 21:21:57

dimich
Member
From: Kharkiv, Ukraine
Registered: 2009-11-03
Posts: 594

Re: [Sloved] mkinitcpio ERROR: Hook 'luks_unlock' cannot be found

akuya wrote:

I think maybe I have problem in what the build script and run script or What is the good hook script?
I check the Arch Wiki. The hook script should found in /etc/initcpio/install/

In mkinitcpio#HOOKS you can find that scripts in /etc/initcpio/install/ are build hooks. They run during 'mkinitcpio -P' build process if listed in mkinitcpio.conf HOOKS. Scripts in /etc/initcpio/hooks/ are runtime hooks, they run from initramfs on boot. Note

For any runtime hook, there should always be a build hook of the same name, which calls add_runscript to add the runtime hook to the image.

Last edited by dimich (2025-08-25 21:29:09)

Offline

#5 2025-08-26 06:51:59

akuya
Member
Registered: 2025-08-24
Posts: 3

Re: [Sloved] mkinitcpio ERROR: Hook 'luks_unlock' cannot be found

dimich wrote:
akuya wrote:

I think maybe I have problem in what the build script and run script or What is the good hook script?
I check the Arch Wiki. The hook script should found in /etc/initcpio/install/

In mkinitcpio#HOOKS you can find that scripts in /etc/initcpio/install/ are build hooks. They run during 'mkinitcpio -P' build process if listed in mkinitcpio.conf HOOKS. Scripts in /etc/initcpio/hooks/ are runtime hooks, they run from initramfs on boot. Note

For any runtime hook, there should always be a build hook of the same name, which calls add_runscript to add the runtime hook to the image.


I read ArchWiki again and follow the part of dm-crypt/specialties
https://wiki.archlinux.org/title/Dm-cry … der_on_USB
Part 9 Encrypted /boot and a detached LUKS header on USB

The script in the xxx/install/ is a build script
The script in the xxx/hooks/ is a run script


I make another script
I copy /usr/lib/initcpio/install/encrypt as /etc/initcpio/install/luks_unlock
I delete the part of help in it.

Then I make a other script
(/etc/initcpio/hooks/luks_unlock)

```bash
#/bin/bash

key_part="usb-Generic_STORAGE_DEVICE_000000000819-0:0-part3"
header_part="usb-Generic_STORAGE_DEVICE_000000000819-0:0-part4"
key_mount="/key"
header_mount="/header"

run_hook() {

        modprobe -a -q dm-crypt >/dev/null 2>&1
        modprobe loop
        [ "${quiet}" = "y" ] && CSQUIET=">/dev/null"

        while [ ! -L "/dev/disk/by-id/$key_part" ]; do
         echo "Waiting for key_part"
         sleep 1
        done

        while [ ! -L "/dev/disk/by-id/$header_part" ]; do
         echo "Waiting for header_part"
         sleep 1
        done

        mkdir -p "$key_mount"
        mkdir -p "$header_mount"


        mount "/dev/disk/by-id/$key_part" "$key_mount"
        mount "/dev/disk/by-id/$header_part" "$header_mount"

        cryptsetup --header "$header_mount/0header.img" --key-file "$key_mount/keyfile" luksOpen /dev/nvme0n1 crypt_sys>
}

run_hook
```
There are some points need to notice about mkinitcpio.conf,too.

1.Add "vfat" into module()

2.Make sure there are not systemd or encrypt in hook()

3.M


Then it could boot system
Thank you very much:)

Last edited by akuya (2025-08-26 07:01:59)

Offline

Board footer

Powered by FluxBB