Skip to content

Instantly share code, notes, and snippets.

@imharvol
Last active August 29, 2022 11:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imharvol/c5f879fb67952c9e59b460859e44235c to your computer and use it in GitHub Desktop.
Save imharvol/c5f879fb67952c9e59b460859e44235c to your computer and use it in GitHub Desktop.
Example creation of a GCE instance with nested virtualization
# Instance Launch:
gcloud beta compute \
--project=PROJECT-ID \ # Changeme
instances create virtualbox \
--zone=europe-west2-c \
--machine-type=n1-standard-2 \
--metadata=ssh-keys=imharvol:ssh-rsa\ AAAAB3NzaC1yc2EAAAADAQABAAABAQDzQ5Z5gLRJXgLvUBCTkvsTfV2xbxkh64vlHZlZCNDz7u5BPb3PsR/ggrealR7JVDeStOB5yv52pj\+XYj3o5qhRLFhf2QZlvtpjBnfiDrZIIXGMkQ3McQlAixE1nZPHEt4mzwAEAuvd2KK\+RysaAQKZ2mTuwxmGE439ZJbQjbgBMOnGkR61YGDxZywBQnDMtJZ2I9B\+/kC07tQIkmj5L0YN/kpXfebmckn8d0Eq6ckPJ4vQI9aL9izE2kJwFK8NNghz/lfRTzWto78NaItDr1ipJQnm5ssyb57YFz7gamnwP\+1zcbXUlccfizbHsuyoYJ5Bqc0nFoprrafMdDHjEclD\ imharvol@imharvol-PC \ # Changeme
--image=ubuntu-2004-focal-v20210908 \
--image-project=ubuntu-os-cloud \
--boot-disk-size=32GB \
--boot-disk-device-name=virtualbox \
--min-cpu-platform="Intel Haswell" \
--enable-nested-virtualization
# Instance Installation:
DESK_ENV="ubuntu-mate-desktop" && \
VNC_PASS="espinacas" && \
echo -e "debconf debconf/frontend select noninteractive\ndebconf debconf/priority select critical" | sudo debconf-set-selections && \
sudo apt-get update -y && sudo apt-get upgrade -y && \
sudo apt-get install $DESK_ENV -y && \
sudo apt-get install tigervnc-common tigervnc-scraping-server tigervnc-standalone-server tigervnc-viewer tigervnc-xorg-extension -y && \
mkdir -p ~/.vnc/ && touch ~/.vnc/passwd && \
echo $VNC_PASS | vncpasswd -f > ~/.vnc/passwd && \
sudo apt-get update -y && sudo apt-get upgrade -y && \
sudo apt-get install virtualbox -y && \
vncserver -PasswordFile ~/.vnc/passwd
# Connection commands:
ssh -N -C -L 5901:localhost:5901 INSTANCE-IP
vncviewer localhost:5901
# Restart VNC Server:
vncserver -kill :*
vncserver -PasswordFile ~/.vnc/passwd
@lincolnnguyen18
Copy link

Helped me a lot! Thank you! 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment