Pacman Hooks

Hooks run before/after package operations — the mechanism keeping initramfs, GRUB and ACRECOVERY synced automatically.

Where they live

/usr/share/libalpm/hooks/ (shipped) and /etc/pacman.d/hooks/ (yours). Precedence to /etc.

Shipped hooks worth knowing

ls /usr/share/libalpm/hooks/
cat /usr/share/libalpm/hooks/linux.hook

Representative behaviors on AcreetionOS:

  • linux.hook → mkinitcpio -P when kernel files change

  • grub.hook → grub-mkconfig after grub/kernel updates

  • acreetion-recovery-sync → refreshes ACRECOVERY partition kernels (Managing the ACRECOVERY Partition)

  • timeshift-grub → keeps snapshot menu entries current

Anatomy of a hook

/etc/pacman.d/hooks/backup-etc.hook:

[Trigger]
Operation = Install
Operation = Upgrade
Type = Package
Target = *

[Action]
Description = Snapshotting /etc before changes...
When = PreTransaction
Exec = /usr/local/bin/etc-backup.sh
Depends = rsync

When = PreTransaction fires before anything changes — perfect for backups; PostTransaction for rebuilds.

Write your own safely

  1. Trigger narrowly (Type = Path, specific targets) — wildcard pre-transactions slow every install.

  2. Exec must not prompt; failures abort the transaction (pre-hooks) — log, don’t block, unless blocking IS the point.

  3. Debug timing: touch a marker file in Exec while developing.