Ubuntu Linux Cloud Install (Scripted)

This is a faster, scripted method of configuring a new Ubuntu Linux 20.04 LTS server as outlined in my detailed post Ubuntu Linux Cloud Install

Download the Script

wget -O /tmp/Ubuntu20Setup.sh https://raw.githubusercontent.com/alexlewislnk/Ubuntu-Setup/main/Ubuntu20Setup.sh
chmod +rx /tmp/Ubuntu20Setup.sh

Run the Script


Sample output

Be sure to check the logfile for any errors, then reboot the server.


Swap File

If on Azure, see the instruction below for Swap File on Azure.

If a swap partition was not created by the deployment, create one based on the amount of RAM installed.

Installed RAM (GB)Swap File (GB)
2 or less1
3 – 62
7 – 123
13 – 204

Create swap file (example for 1GB swap file)

fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Swap File on Azure

The Azure WALinuxAgent will automatically create a swap file on the resource (temporary) drive.

cp /etc/waagent.conf /etc/waagent.conf.save
sed -i '/ResourceDisk.Format/c\ResourceDisk.Format=y' /etc/waagent.conf
sed -i '/ResourceDisk.EnableSwap/c\ResourceDisk.EnableSwap=y' /etc/waagent.conf
sed -i '/ResourceDisk.SwapSizeMB/c\ResourceDisk.SwapSizeMB=4096' /etc/waagent.conf
service walinuxagent restart

Install LTS Enablement Stack for for latest kernel updates

apt -y install --install-recommends linux-virtual-hwe-20.04

reboot and reconnect with putty as root user


Remove old kernel packages and dependencies

apt -y autoremove ; apt -y purge linux-generic linux-headers-generic linux-image-generic linux-virtual linux-headers-virtual linux-image-virtual ; apt -y autoremove

Suggested Next Step

Scroll to Top