target for systemd wake-up process
target for systemd wake-up process
Systemd currently lacks a wakeup.target feature. To automate tasks when the system wakes up from hibernation or suspend, you’d need to configure it manually. Regarding your second point, if /sys/power/image_size retains your settings through unit files, you wouldn’t have to worry about making those files dependent on wakeup mechanisms.
I tested the file and manually launched the service: [Unit] Description=set /sys/power/image_size to zero [Service] User=root Type=oneshot RemainAfterExit=no ExecStart=echo 0 > /sys/power/image_size [Install] WantedBy=multi-user.target The change wasn't applied. It seems systemd might not support this action after shutdown. Maybe a sleep.target is needed, though I couldn't locate details about it. Refer to the link provided: https://github.com/systemd/systemd/issues/6364
Hmm, the situation varies. I'm attempting to restart today because the hibernation feature stopped functioning after I deleted a disk used for storing RAM data. It's now working again, allowing me to conserve energy. While troubleshooting, I discovered that hibernated RAM needs more than just basic setup—it also requires Dracut to load the resume module. Without it, the RAM won't be loaded properly. Setting image_size to 0 helps reduce the size of the RAM image written to disk, speeding up wake-up and ensuring the swap partition fits within RAM. I'm unsure what these targets actually do, but a wakeup.target might be more appropriate. Since my unit file can't adjust image_size, it won't help much. I think I found a solution here: https://bbs.archlinux.org/viewtopic.php?id=195364. I'll check if it works on the next reboot.
The unit file functions correctly when started manually, confirming its intended behavior. The script sets the image size to zero by redirecting output from a shell command. Using sh or bash is necessary because it executes the command properly, ensuring the file is created as expected. After hibernation, the image_size returned zero, which may be due to the sleep duration or system state. I’ll address the hibernation fix in a separate update.
The keyword specifies dependencies for service startup. After installing, configure the file to launch with Hibernate's target. Running without the After clause causes it to start immediately with the resume target. Setting WantedBy=multi-user.target ensures it activates at the shell level, typically during startup. Ignoring the After directive means it won't wait for the resume process.
I’d prefer it to execute before hibernation so the disk-written image stays as compact as possible. Once it’s done afterward, it’ll maintain that size, though it won’t be essential if it runs each time before hibernating. Using a shell was a surprise—I hadn’t considered that. If I have to run this, I’ll likely write a C program for the writing process. It could be more efficient and less resource-heavy.