Skip to content

Instantly share code, notes, and snippets.

@darrenldl
Last active July 6, 2021 14:21
Show Gist options
  • Save darrenldl/cee1850826ae390a025ffeca74e8e7f7 to your computer and use it in GitHub Desktop.
Save darrenldl/cee1850826ae390a025ffeca74e8e7f7 to your computer and use it in GitHub Desktop.
Hooks for unmounting external USB on Arch

Hooks for unmounting external USB on Arch

Files

  • install_closeboot is the install hook
  • runtime_closeboot is the runtime hook

Instructions

  1. Copy install_closeboot to /usr/lib/initcpio/install/closeboot
  2. Copy runtime_closeboot to /usr/lib/initcpio/hooks/closeboot
  3. Modify /usr/lib/initcpio/hooks/closeboot appropriately, namely by replacing /dev/PATH_DUMMY with whatever device path the device would be residing at, ideally use a UUID path. Use ls -l /dev/disk/by-uuid/ to find the appropriate path indexed by UUID for your external device.
  4. Add closeboot to list of hooks at /etc/mkinitcpio.conf after encrypt hook, e.g. HOOKS="base udev autodetect modconf block encrypt closeboot filesystems keyboard fsck"
  5. Regnerate kernel images via mkinitcpio -p linux with boot partitions mounted
#!/bin/ash
build() {
add_runscript
}
help() {
cat <<HELPEOF
This hook is a custom hook installed for external USB device after being opened by the encrypt hook.
HELPEOF
}
#!/usr/bin/ash
run_hook() {
if [ -b /dev/PATH_DUMMY ]; then
cryptsetup close /dev/PATH_DUMMY >/dev/null
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment