Last active
July 13, 2024 17:35
-
-
Save imharvol/c5f879fb67952c9e59b460859e44235c to your computer and use it in GitHub Desktop.
Example creation of a GCE instance with nested virtualization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Helped me a lot! Thank you! 😊