Hibernation works by using a swap partition¹ to swap out all processes' memories, the kernel state, finally save some state of CPU and possibly other devices, then power off. On the way, it notes in the swap partition that this is a hibernation image.
Resuming from hibernation works by telling the kernel to try resuming from a swap partition, using the resume=
kernel argument, resume=/dev/sda4
(if /dev/sda4 is your swap partition), resume=UUID=deadbeef-cafe-b00b-1337-123456123456
or similar.
The kernel during boot then looks into that partition, finds the note in the swap partition that says "hey, this is a hibernation image", and restores device, kernel and processes from that. If the note is not there, it just boots as normal.
You can check the source code, specifically the description of the software_resume()
function:
* software_resume - Resume from a saved hibernation image.
*
* This routine is called as a late initcall, when all devices have been
* discovered and initialized already.
*
* The image reading code is called to see if there is a hibernation image
* available for reading. If that is the case, devices are quiesced and the
* contents of memory is restored from the saved image.
So this involves two instances of the kernel, the "boot kernel" and "the image kernel" and the process is described in the official kernel documentation which also explains why this isn't done via the bootloader:
Although in principle the image might be loaded into memory and the
pre-hibernation memory contents restored by the boot loader, in
practice this can’t be done because boot loaders aren’t smart enough
and there is no established protocol for passing the necessary
information. So instead, the boot loader loads a fresh instance of the
kernel, called “the restore kernel”, into memory and passes control to
it in the usual way. Then the restore kernel reads the system image,
restores the pre-hibernation memory contents, and passes control to
the image kernel. Thus two different kernel instances are involved in
resuming from hibernation.
¹ These days, can also be a swap file on many (most?) file systems, or an LVM volume….