Debian cloud-init userdata

When you spin up a cloud VM at Google Compute or Digital Ocean there’s an option to specify user data, this is my goto script to update Debian and setup a  2G swapfile.

#!/usr/bin/env bash
dd if=/dev/zero of=/swap bs=1M count=2048
chmod 600 /swap
mkswap /swap
swapon /swap
echo "/swap swap swap defaults 0 0" >> /etc/fstab
apt update
apt -y upgrade
shutdown -r now

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.