Skip to content

Instantly share code, notes, and snippets.

@aivanise
Created July 7, 2021 09:14
Show Gist options
  • Save aivanise/8a53492e6a2b12604c1d98dd4b5bd414 to your computer and use it in GitHub Desktop.
Save aivanise/8a53492e6a2b12604c1d98dd4b5bd414 to your computer and use it in GitHub Desktop.
#!/bin/bash
# zero all the free blocks on a (mounted) root fs to TRIM it
# and/or make it more compressible for backups
# during this process the machine is basically dead (only ssh works)
# reboots at the end
systemctl isolate rescue-ssh
sleep 3
systemctl stop systemd-journald.socket
systemctl stop systemd-journald-audit.socket
systemctl stop systemd-journald-dev-log.socket
systemctl stop systemd-journald
systemctl stop systemd-udevd-control.socket
systemctl stop systemd-udevd-kernel.socket
systemctl stop systemd-udevd
sleep 10
systemctl stop systemd-journald.socket
systemctl stop systemd-journald-audit.socket
systemctl stop systemd-journald-dev-log.socket
systemctl stop systemd-journald
systemctl stop systemd-udevd-control.socket
systemctl stop systemd-udevd-kernel.socket
systemctl stop systemd-udevd
echo s > /proc/sysrq-trigger
sleep 1
echo u > /proc/sysrq-trigger
sleep 1
zerofree $(findmnt -no SOURCE /)
systemctl reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment