Kali Linux persistence overlay: no built-in sync timeout before power-off
0 reputation · 13 Jun 2025, 10:38 UTC
0 reputation · 13 Jun 2025, 10:38 UTC
Kali Linux live systems booted with persistence store changes in an overlay that is only committed to the persistent partition on a clean shutdown or an explicit sync. If power is cut before that flush completes, unsaved changes can be lost and the persistent partition may need manual repair.
My goal is to make shutdown behavior deterministic for a lab of live-USB machines where users frequently power off abruptly. I want the overlay to be synchronized automatically whenever a shutdown signal is received, with a bounded grace period so the system cannot hang indefinitely if the sync stalls on slow USB media.
What I cannot find is a documented configuration option in Kali's persistence implementation for a sync timeout or an automatic flush trigger at shutdown. It appears the decision is left to the user or to custom init/shutdown scripts, which is fragile in automated or demo environments.
Is there an officially supported way to enforce overlay synchronization with a maximum wait time before power-off completes? If not, is a custom shutdown hook calling sync the accepted approach, and where should it be registered so it runs reliably before the persistent partition is unmounted? Finally, is there any upstream discussion about adding a default grace period that balances data integrity against shutdown speed?
31275 reputation · 13 Jun 2025, 14:21 UTC
No. Kali’s live‑boot persistence, which is inherited from Debian’s live‑boot package, does not expose a kernel parameter or a persistence.conf option that forces a sync with a bounded timeout when a shutdown signal is received. The default shutdown path simply runs sync and then unmounts the persistent partition; if the sync stalls, the system will wait indefinitely until the kernel decides the shutdown is complete.
Place a small service in /etc/systemd/system/persistence-sync.service that calls sync with a timeout. The unit must be ordered before the unmount of the persistent partition, which is handled by the umount.target during shutdown.
[Unit]
Description=Flush persistence overlay before unmount
DefaultDependencies=no
Before=umount.target shutdown.target
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/bin/sync
TimeoutStopSec=30
RemainAfterExit=yes
[Install]
WantedBy=shutdown.target
After creating the file, reload systemd and enable the unit:
sudo systemctl daemon-reload
sudo systemctl enable persistence-sync.service
DefaultDependencies=no removes the implicit ordering that would otherwise run the unit after shutdown.target.Before=umount.target guarantees the sync runs while the overlay and the persistent partition are still mounted.TimeoutStopSec=30 bounds the wait; adjust it if you observe longer sync times on slow USB media.dd if=/dev/zero of=/home/kali/bigfile bs=1M count=500/usr/bin/time syncTimeoutStopSec to a value a few seconds above the measured time.touch /home/kali/testfile.systemctl poweroff (or press the power button)./home/kali/testfile exists.journalctl -b -1 -u persistence-sync should show the service started and finished within the timeout./usr/share/initramfs-tools/scripts/shutdown/ that calls sync with a timeout wrapper.There is no built‑in timeout for overlay synchronization in Kali. The recommended, officially supported method is to add a systemd shutdown unit that runs sync with a bounded TimeoutStopSec before the persistent partition is unmounted. This pattern works reliably on Kali 2020.1+ and can be tuned to match the write latency of the target USB media.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.