FINALRD(1)

πŸ“¦
version 9build2 Β· 2 versions
, in ubuntu resolute, ubuntu stonking

FINALRD πŸ’–

okay so bestie, this is finalrd β€” the final runtime directory generator for shutdown ✨ she's the one making sure your shutdown is cute and clean instead of a whole messy situation, no cap πŸ’…


🌸 SYNOPSIS 🌸

systemctl enable --now finalrd.service

like literally that's it, that's the whole vibe πŸŽ€


πŸ¦‹ HOOKS DIRECTORIES πŸ¦‹

these are the three little homes your hooks can live in, in order:

/usr/share/finalrd/*.finalrd
/etc/finalrd/*.finalrd
/run/finalrd/*.finalrd

πŸŽ€ HOOKS INTERFACE πŸŽ€

how you talk to a hook, bestie:

foo.finalrd setup
foo.finalrd halt|poweroff|reboot|kexec

✨ DESCRIPTION ✨

so finalrd generates a shutdown directory at /run/initramfs, and then systemd-shutdown pivots to it during shutdown. πŸ‘‘

what does that mean?? it means the system shutdown can actually be finalised there, and arbitrary hooks can be executed off-root β€” so you can safely clean up the rootfs and do all the other shutdown tasks without it being a whole thing 🫢

for example (and this is such a good example), a hook may takeover monitoring external metadata RAID arrays, wait for them to be clean, and then stop them. iconic. if someone is using iscsiroot, it might be needed to perform iscsi logout on shutdown. yep. that too. πŸ’…

typically you would not run finalrd directly, bestie β€” instead you activate finalrd.service. that runs the finalrd generator late in the shutdown cycle, just in time for the pivot. the timing?? chef's kiss 😭


πŸ’œ HOOKLESS OPERATION πŸ’œ

if initramfs-tools is not available, and therefore copy_exec is not available, then hooks will not be executed or copied into the shutdown directory. no hooks, no problem, we move.

however β€” and this is important β€” the shutdown dir will still be created, so that init has somewhere to pivot to, and it'll attempt a cleaner shutdown without holding up the root filesystem. slay πŸ¦‹

for example, Ubuntu Core is such a system. πŸ’–


⭐ HOOKS INTERFACE DESCRIPTION ⭐

*.finalrd hooks can be shipped in /usr, /etc, and /run. these directories are for distribution, sysadmin, and transient hooks respectively β€” iykyk πŸ“š

they are multi-purpose binaries, and the action is passed as the first argument. periodt.

🌈 During the setup stage 🌈

hooks are executed from the rootfs, with one argument β€” setup β€” passed as the first arg.

all hooks are executed in all the directories, in order: first everything in /usr, then from /etc, then from /run. bestie it's a whole queue and everyone gets a turn πŸ’…

the environmental variables DESTDIR and DESTROOTDIR are set, pointing at the finalrd location. this is done for convenience β€” so you can use initramfs-tools's copy_exec function or dracut-install, for copying binaries. so handy 🫢

🌸 During the shutdown stage 🌸

hooks are executed from finalrd in parallel, with one argument passed to them. that argument is one of: halt, poweroff, reboot, kexec. pick your fighter βš”οΈ

⚠️ note, bestie, this one matters: if there are identically named hooks in multiple configuration directories, all of them will be executed during the setup stage. but only the last one will be copied into the finalrd and executed during the shutdown stage. so like… the last one wins the crown πŸ‘‘ don't forget it.

πŸŽ€ SEE ALSO πŸŽ€

The initrd Interface of systemd

https://www.freedesktop.org/wiki/Software/systemd/InitrdInterface


and that's the whole page, bestie!! πŸ’– this was finalrd, version 2, from the finalrd corner of the manpage world 🌸 go forth and have the cleanest shutdown of your life, fr fr πŸ¦‹βœ¨πŸ’…

πŸ“¦ where this page comes from