Skip to content

Instantly share code, notes, and snippets.

@Himura2la
Created September 20, 2022 12:03
Show Gist options
  • Save Himura2la/11d8335ed8ac0822b52af09b334d4451 to your computer and use it in GitHub Desktop.
Save Himura2la/11d8335ed8ac0822b52af09b334d4451 to your computer and use it in GitHub Desktop.
Use Azure temporary disk for swap without waagent (on Debian)
cat <<'EOF' | sudo tee /usr/local/sbin/addswap.sh
#!/bin/sh
if [ ! -f /mnt/swapfile ]
then
/usr/bin/fallocate -l 30G /mnt/swapfile
/usr/bin/chmod 600 /mnt/swapfile
/usr/sbin/mkswap /mnt/swapfile
/usr/sbin/swapon /mnt/swapfile
fi
EOF
sudo chmod 744 /usr/local/sbin/addswap.sh
cat <<'EOF' | sudo tee /etc/systemd/system/addswap.service
[Unit]
Description=Enable 30G swap on Azure temp-disk
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/addswap.sh
[Install]
WantedBy=multi-user.target
EOF
sudo chmod 644 /etc/systemd/system/addswap.service
sudo systemctl enable addswap.service
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment