GCP

GCE(Google Compute Engine) 인스턴스 내부에서 Virtualbox 실행

misankim 2023. 4. 30. 00:40

GCE(Google Compute Engine) 인스턴스 내부에서 Virtualbox 실행


# 중첩된 가상화를 사용하는 ubuntu vm 생성

-> 중첩된 가상화를 사용할 수 있는 최소 CPU 사양을 만족하도록 --min-cpu-platform 옵션 지정

-> 중첩된 가상화를 사용할 수 있도록 --enable-nested-virtualization 옵션 지정


https://cloud.google.com/compute/docs/instances/nested-virtualization/enabling?hl=ko 

gcloud compute instances create premisan-test-ubuntu \
    --project=premisan-test \
    --zone=asia-northeast3-a \
    --machine-type=n1-custom-4-8192 \
    --network-interface=subnet=premisan-test-subnet,no-address \
    --maintenance-policy=MIGRATE \
    --provisioning-model=STANDARD \
    --service-account=500090000610-compute@developer.gserviceaccount.com \
    --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append \
    --enable-display-device \
    --create-disk=auto-delete=yes,boot=yes,device-name=premisan-test-ubuntu,image=projects/ubuntu-os-cloud/global/images/ubuntu-2204-jammy-v20230421,mode=rw,size=100,type=projects/premisan-test/zones/asia-northeast3-a/diskTypes/pd-balanced \
    --no-shielded-secure-boot \
    --shielded-vtpm \
    --shielded-integrity-monitoring \
    --labels=ec-src=vm_add-gcloud \
    --reservation-affinity=any \
    --enable-nested-virtualization \
    --min-cpu-platform="Intel Haswell"



확인(0 이외의 응답은 중첩된 가상화가 사용 설정된 것)

grep -cw vmx /proc/cpuinfo




# virtualbox 사용을 위한 디펜던시 패키지 설치

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential
sudo apt-get install -y linux-headers-$(uname -r)




# gcc 12 설치
-> virtualbox 설정 초기화(vboxconfig) 실행 시 필요


https://itslinuxfoss.com/install-gcc-ubuntu-22-04/ 

sudo apt install gcc-12



버전 확인

gcc-12 --version



virtualbox 설정 초기화

sudo vboxconfig




# virtualbox 설치

-> 최신 버전 확인하여 설치 파일 링크 수정할 것


https://www.virtualbox.org/wiki/Linux_Downloads

curl -O https://download.virtualbox.org/virtualbox/7.0.8/virtualbox-7.0_7.0.8-156879~Ubuntu~jammy_amd64.deb

sudo apt-get install ./virtualbox-7.0_7.0.8-156879~Ubuntu~jammy_amd64.deb




# chrome 원격 데스크탑 설치

https://cloud.google.com/architecture/chrome-desktop-remote-on-compute-engine?hl=ko 

curl -L -o chrome-remote-desktop_current_amd64.deb     https://dl.google.com/linux/direct/chrome-remote-desktop_current_amd64.deb

sudo DEBIAN_FRONTEND=noninteractive     apt-get install --assume-yes ./chrome-remote-desktop_current_amd64.deb




# gnome 데스크탑 설치

sudo DEBIAN_FRONTEND=noninteractive \
    apt install --assume-yes  task-gnome-desktop

sudo bash -c 'echo "exec /etc/X11/Xsession /usr/bin/gnome-session" > /etc/chrome-remote-desktop-session'

sudo systemctl disable gdm3.service

curl -L -o google-chrome-stable_current_amd64.deb \
https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo apt install --assume-yes ./google-chrome-stable_current_amd64.deb


설치 완료 후 리부트 진행


# chrome 원격 데스크탑 연결

로컬 PC에서 접속하여 설정 진행
https://remotedesktop.google.com/headless?hl=ko 

아래와 같은 커맨드가 출력되면 ubuntu vm 에서 실행(아래는 샘플 커맨드)

DISPLAY= /opt/google/chrome-remote-desktop/start-host --code="4/00000tk4L0000j5_8nKL0T0000a-wX00007Px63Y20000ReKVS0000y08J0000_6n0000DA" --redirect-url="https://remotedesktop.google.com/_/oauthredirect" --name=$(hostname)


-> 임의의 6자리 이상의 핀번호 설정

서비스 상태 확인

sudo systemctl status chrome-remote-desktop@$USER


원격 액세스
https://remotedesktop.google.com/access?hl=ko