Running Confluence on Azure VM – Preparing Ubuntu image in Hyper-V [1/4]

This is a multi-post guide on how to prepare and run Confluence in an Azure VM. While there are prebuilt images for Ubuntu available in Azure this guide will show how to deploy your own image.



Enable Hyper-V from powershell:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Hyper-V -All
Code language: PowerShell (powershell)

Open Hyper-V and create a new virtual machine:

  • The disk must be VDH (fixed sized) and have a minimum size of 8GB
  • Assign an external (Internet) network card
  • Mount ISO for Ubuntu Server

Installing and configure Ubuntu

Start the VM and console into it to complete the Ubuntu installer steps:

  • For archive setup change the mirror address to
  • In storage configuration you can uncheck LVM group setup if not required
  • Install OpenSSH server

When install has finished SSH into the server to begin customizations.

# Prepare BASH environment with configuration options # Specify public key in a single line SSH_USERNAME=<your-username> SSH_PUBLICKEY="<your-publickey>"
Code language: Bash (bash)
# Disable disk swapping sudo swapoff -a sudo sed -i "/swap\.img/d" /etc/fstab sudo rm /swap.img
Code language: Bash (bash)
# Setup user SSH credentials mkdir -p ~/.ssh chmod a+rwx,g-rwx,o-rwx ~/.ssh cat >> ~/.ssh/authorized_keys << EOL ssh-rsa $SSH_PUBLICKEY EOL chmod a+rwx,u-x,g-rwx,o-rwx ~/.ssh/authorized_keys # Setup SSH server config sudo sed -i 's/#PubkeyAuthentication yes/PubkeyAuthentication yes/' /etc/ssh/sshd_config sudo sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config sudo sed -i 's/#PermitEmptyPasswords no/PermitEmptyPasswords no/' /etc/ssh/sshd_config sudo sed -i 's/X11Forwarding yes/X11Forwarding no/' /etc/ssh/sshd_config sudo sed -i 's/#TCPKeepAlive yes/TCPKeepAlive yes/' /etc/ssh/sshd_config sudo sed -i 's/#ClientAliveInterval 0/ClientAliveInterval 600/' /etc/ssh/sshd_config sudo sed -i 's/#ClientAliveCountMax 3/ClientAliveCountMax 3/' /etc/ssh/sshd_config echo 'Protocol 2' | sudo tee -a /etc/ssh/sshd_config # Verify your SSH with a new login after restart sudo service ssh restart
Code language: Bash (bash)
# Config Ubuntu respository to Azure sudo sed -i 's/http:\/\/archive\.ubuntu\.com\/ubuntu\//http:\/\/azure\.archive\.ubuntu\.com\/ubuntu\//g' /etc/apt/sources.list sudo sed -i 's/http:\/\/[a-z][a-z]\.archive\.ubuntu\.com\/ubuntu\//http:\/\/azure\.archive\.ubuntu\.com\/ubuntu\//g' /etc/apt/sources.list sudo apt-get update
Code language: Bash (bash)
# Install AdoptOpenJDK wget --quiet -O - | sudo apt-key add - echo "deb focal main" | sudo tee /etc/apt/sources.list.d/adoptopenjdk.list sudo apt-get update sudo apt-get install -y adoptopenjdk-11-hotspot-jre
Code language: Bash (bash)
# Install Postgresql wget --quiet -O - | sudo apt-key add - echo "deb $(lsb_release -sc)-pgdg main" | sudo tee /etc/apt/sources.list.d/PostgreSQL.list sudo apt update sudo apt-get install -y postgresql-10
Code language: Bash (bash)
# Install Lets Encrypt Certbot sudo apt-get install -y certbot
Code language: Bash (bash)
# Prefetch install packages for Confluence without installing wget sudo chmod a+x atlassian-confluence-7.11.0-x64.bin sudo ./atlassian-confluence-7.11.0-x64.bin -help rm atlassian-confluence-7.11.0-x64.bin
Code language: Bash (bash)
# Install Azure packages sudo apt install -y linux-azure linux-image-azure linux-headers-azure linux-tools-common linux-cloud-tools-common linux-tools-azure linux-cloud-tools-azure sudo apt full-upgrade
Code language: Bash (bash)
# Install Azure agent sudo apt install -y cloud-init walinuxagent sudo systemctl stop walinuxagent # Remove unused config sudo rm -f /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg sudo rm -f /etc/cloud/cloud.cfg.d/curtin-preserve-sources.cfg sudo rm -f /etc/cloud/ds-identify.cfg # Update package config echo 'datasource_list: [ Azure ]' | sudo tee /etc/cloud/cloud.cfg.d/90_dpkg.cfg cat << EOL | sudo tee /etc/cloud/cloud.cfg.d/90-azure.cfg system_info: package_mirrors: - arches: [i386, amd64] failsafe: primary: security: search: primary: - security: [] - arches: [armhf, armel, default] failsafe: primary: security: EOL cat << EOL | sudo tee /etc/cloud/cloud.cfg.d/10-azure-kvp.cfg reporting: logging: type: log telemetry: type: hyperv EOL sudo sed -i 's/Provisioning.Enabled=y/Provisioning.Enabled=n/g' /etc/waagent.conf sudo sed -i 's/ResourceDisk.Format=y/ResourceDisk.Format=n/g' /etc/waagent.conf sudo sed -i 's/ResourceDisk.EnableSwap=y/ResourceDisk.EnableSwap=n/g' /etc/waagent.conf echo 'Provisioning.Agent=auto' | sudo tee -a /etc/waagent.conf
Code language: Bash (bash)
# Update Ubuntu boot loader sudo sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/cGRUB_CMDLINE_LINUX_DEFAULT=\"console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 quiet splash\"" /etc/default/grub sudo update-grub
Code language: Bash (bash)
# Cleanup Ubuntu sudo apt-get -y clean sudo apt-get -y autoclean sudo apt-get -y autoremove # Cleanup cloud-init sudo cloud-init clean --logs --seed sudo rm -rf /var/lib/cloud/ sudo systemctl stop walinuxagent.service sudo rm -rf /var/lib/waagent/ sudo rm -f /var/log/waagent.log
Code language: Bash (bash)
# Prepare vm for Azure sudo waagent -force -deprovision+user rm -f ~/.bash_history export HISTSIZE=0 sudo shutdown now
Code language: Bash (bash)

Our customization of Ubuntu Server is now complete.

Proceed by copying the VM disk to a temporary folder.

In case of errors please refer to the official documentation at Prepare an Ubuntu virtual machine for Azure.

In next step we will prepare and configure a new VM in Azure using the locally created Ubuntu Server image:

Leave a comment

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