CPU_REBOOT(9)

πŸ“¦ version 11.0, in nixpkgs unstable

πŸ’… CPU_REBOOT(9) β€” the kernel developer's manual, but make it make sense πŸ’…

okay bestie, so this page is CPU_REBOOT(9) from the Kernel Developer's Manual β€” section 9, kernel-adjacent, very "final boss of the boot sequence" energy. It's the function that literally hits the lights or restarts the whole vibe. Let's get into it 🫢


✨ NAME ✨

cpu_reboot β€” halt or reboot the system. that's it. that's the whole job. the end-of-day function. the "we're closing, please make your way to the exit" of kernel space πŸ’€


πŸŽ€ SYNOPSIS πŸŽ€

#include <sys/reboot.h>

void
cpu_reboot(int howto, char *bootstr);

so it takes an int howto and a char *bootstr, and it returns void β€” meaning it does not give you anything back. it's giving "I am the last thing that happens, there is no return, there is no after." main character energy fr fr πŸ‘‘


🌸 DESCRIPTION 🌸

The cpu_reboot() function handles the final system shutdown, and then either halts or reboots the system. Which one it picks depends on two things, no cap:

  • the flags you pass in howto
  • whether or not the system has finished autoconfiguration

Two whole paths. Two whole vibes. Let's go.

πŸ”₯ if the system HAS finished autoconfiguration

then cpu_reboot() does the following, in this exact order (the order matters, do not shuffle, this is not a playlist):

  1. Sets the boothowto system variable (see boothowto(9)) from the howto argument. lowkey just recording what you asked for, so the next boot knows the lore πŸ“
  2. If this is the first invocation of cpu_reboot() and the RB_NOSYNC flag is not set in howto, it syncs and unmounts the system disks by calling vfs_shutdown(9), and sets the time of day clock by calling resettodr(9). this is the "save your work before I close the laptop" step and it is so important 😭
  3. Disables interrupts. everyone quiet, the adults are talking 🀫
  4. If rebooting after a crash (i.e., if RB_DUMP is set in howto, but RB_HALT is not), it saves a system crash dump. yes bestie, we're preserving the evidence πŸ”
  5. Runs any shutdown hooks by calling pmf_system_shutdown(9). hooks get to say their goodbyes πŸ₯Ή
  6. Prints a message indicating that the system is about to be halted or rebooted. a little announcement, a little "going down in 3, 2, 1" πŸ“’
  7. If RB_HALT is set in howto, it halts the system. Otherwise, it reboots the system. that's the fork in the road, the whole plot twist, the moment ✨

🌈 if the system has NOT finished autoconfiguration

then it's a whole different situation, and honestly it's simpler: cpu_reboot() runs any shutdown hooks by calling pmf_system_shutdown(9), prints a message, and halts the system.

that's it. no disk sync step listed here, no dump step listed here β€” the page only says hooks, message, halt. don't go adding steps that aren't in the original, i'm watching you πŸ‘€

πŸ¦‹ one more thing: bootstr

If RB_STRING is set in howto, then the parameter bootstr is passed to the system boot loader on some ports. not all ports! some. iykyk 🧚


πŸ‘‘ SEE ALSO πŸ‘‘

the whole friend group, assembled:


πŸ’œ sign-off πŸ’œ

that's the whole page, bestie β€” go forth and reboot responsibly 🌟 this little icon was brought to you by Debian, dated February 11, 2010, from the CPU_REBOOT(9) page in the Kernel Developer's Manual. periodt πŸ’…πŸŽ€

πŸ“¦ where this page comes from