Skip to content

Instantly share code, notes, and snippets.

@arschles
Last active October 5, 2019 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arschles/1d7b9b84dbc39d3286119fa7095e7a77 to your computer and use it in GitHub Desktop.
Save arschles/1d7b9b84dbc39d3286119fa7095e7a77 to your computer and use it in GitHub Desktop.
Installing PhantomOS on Azure, kinda
export RES_GROUP=photon
export AZURE_STORAGE_ACCOUNT=photonimages
export AZURE_STORAGE_CONTAINER_NAME=photonimages
export BLOB_NAME=photon3.vhd
export ADMIN_USERNAME=arschles
export VM_NAME=photon3
export LOCATION=eastus2
export PHOTON_VHD_PATH=photon3.vhd
#!/bin/sh
# https://github.com/vmware/photon/wiki/Running-Photon-OS-on-Microsoft-Azure
set pipefail
set -eou
DL_URL="http://dl.bintray.com/vmware/photon/3.0/GA/azure/photon-azure-3.0-26156e2.vhd.tar.gz"
LOCAL_FILE_TGZ="photon-3-0.tar.gz"
LOCAL_FILE_VHD="photon-3-0.vhd"
echo "Downloading Photon 3.0 from $DL_URL"
curl -L -o photon-3-0.tgz $DL_URL
echo "Unzipping Photon"
mkdir photon3-unzip
tar -xvzf photon3.tgz
LOCATION="eastus2"
echo "Creating new resource group $RES_GROUP in $LOCATION"
echo "If the group is already created, this will print a failure, but you can ignore it and move on :)"
az group create --name $RES_GROUP --location $LOCATION || true
# echo "Creating new storage account & container"
az storage account create -g $RES_GROUP --location eastus2 --name $AZURE_STORAGE_ACCOUNT --kind Storage --sku Standard_LRS
az storage container create -n $AZURE_STORAGE_CONTAINER_NAME --account-name $AZURE_STORAGE_ACCOUNT
# set these for the operations against containers and blobs
export AZURE_STORAGE_KEY=$(az storage account keys list -g $RES_GROUP --account-name $AZURE_STORAGE_ACCOUNT | jq -r '.[0].value')
echo "Uploading Photon VHD"
az storage blob upload \
--container-name $AZURE_STORAGE_CONTAINER_NAME \
--type page \
--file $PHOTON_VHD_PATH \
--name $BLOB_NAME
echo "Getting Photon VHD Image URL in Blob Storage"
# use jq -r to strip the leading and trailing quotes from this URL. az vm create
# won't work if you give it a URL with quotes around it womp womp
VHD_URL=$(az storage blob url -c $STORAGE_CONTAINER_NAME -n $BLOB_NAME | jq -r)
echo "The VHD is at $VHD_URL"
SSH_PUBKEY_FILE="$HOME/.ssh/id_rsa.pub"
ADMIN_USERNAME="arschles"
echo "Creating new Azure VM from public key at $SSH_PUBKEY_FILE with admin username $ADMIN_USERNAME"
az vm create \
--resource-group $RES_GROUP \
--location $LOCATION \
--name $VM_NAME \
--storage-account $STORAGE_ACCOUNT_NAME \
--os-type linux \
--admin-username $ADMIN_USERNAME \
--ssh-key-value $SSH_PUBKEY_FILE \
--image $VHD_URL \
--use-unmanaged-disk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment