如何让嵌套虚拟化在 e2-micro GCP VM 上运行?
How can I get nested virtualization working on e2-micro GCP VM?
我正在尝试在 Google 云平台 (GCP) 上使用嵌套虚拟化功能,但是我在尝试使用它时没有成功。根据 GCP documentation:
,这是我遵循的程序
- 创建新磁盘,基于 Ubuntu 18 LTS 映像
- 从磁盘创建新映像,应用 vmx 许可证
- 从映像创建新的 VM 实例
- 检查是否支持嵌套虚拟化,使用Ubuntu
中的cpu-checker
包
gcloud compute disks create disk1 --image-project ubuntu-os-cloud --image-family ubuntu-1804-lts --zone us-central1-a
gcloud compute images create nested-vm-image --source-disk disk1 --source-disk-zone us-central1-a --licenses "https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
gcloud compute instances create firecracker --description firecracker --image nested-vm-image --zone us-central1-a --preemptible --machine-type e2-micro
根据 运行 sudo kvm-ok
命令,我收到此消息:
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
疑难解答
确保我使用的是 Haswell CPU
我使用 gcloud compute instances describe
命令确认我的 e2-micro
VM 正在使用 Intel Haswell CPU,根据 GCP,这是嵌套虚拟化工作所需的最低要求文档。
(base) ➜ ~ gcloud compute instances describe firecracker
No zone specified. Using zone [us-central1-a] for instance: [firecracker].
canIpForward: false
cpuPlatform: Intel Haswell
creationTimestamp: 'xxxxxxxxxxxxxxx'
deletionProtection: false
description: firecracker
disks:
- autoDelete: true
boot: true
deviceName: persistent-disk-0
guestOsFeatures:
- type: VIRTIO_SCSI_MULTIQUEUE
index: 0
interface: SCSI
kind: compute#attachedDisk
licenses:
- https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-1804-lts
- https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx
mode: READ_WRITE
source: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/disks/firecracker
type: PERSISTENT
id: 'xxxxxxxxxxxxxxxxxxxxx'
kind: compute#instance
labelFingerprint: xxxxxxxxxxxxxx
machineType: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/machineTypes/e2-micro
metadata:
fingerprint: xxxxxxxxxxxxxxx
kind: compute#metadata
name: firecracker
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: external-nat
natIP: xxxxxxxxxxx
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: xxxxxxxxxxxxxx
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/global/networks/default
networkIP: xxxxxxxxxxxxxx
subnetwork: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/regions/us-central1/subnetworks/default
scheduling:
automaticRestart: false
onHostMaintenance: TERMINATE
preemptible: true
selfLink: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/instances/firecracker
serviceAccounts:
- email: xxxxxxxx@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/pubsub
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/trace.append
startRestricted: false
status: RUNNING
tags:
fingerprint: xxxxxxxxxxxxxxxx
zone: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a
已尝试 Ubuntu 16.04 LTS
根据文档,我还尝试了使用 Ubuntu 16.04 LTS 的相同过程,并收到了与使用 Ubuntu 18.04 LTS 相同的结果。
问题
问题:如何成功启动支持嵌套虚拟化的 GCP VM?据我所知,我遵循了文档的要求,但无法正常工作。
我知道文档没有明确指出他们使用 Ubuntu 18 LTS 测试嵌套虚拟化,但这并不一定意味着它不会工作。
这是一个猜答案...如果错了,post评论,它将被删除...
如果我们在 Machine Types 下查看,我们会发现以下内容:
Shared-core machine types are available in the N1 and E2 families.
These machine types timeshare a physical core. This can be a
cost-effective method for running small, non-resource intensive
applications.
N1: f1-micro and g1-small shared-core machine types have up to 1 vCPU available for short periods of bursting.
E2: e2-micro, e2-small, and e2-medium shared-core machine types have 2 vCPUs available for short periods of bursting.
在您的故事中,您说您使用的是 e2-micro 机器类型。 Machine this all together 我们看到您选择了一种似乎执行共享核心处理的机器类型,并正在尝试启用嵌套虚拟化。我的直觉是共享核心意味着你的 CPU 运行 你的 OS/app 是在其他用户 运行 他们的 OS/app 之间分割的时间......而这个概念嵌套虚拟化(我认为)要求您拥有 CPU 的专有所有权,正如 "normal" 家庭成员中所见。我建议 运行 您使用 n1-standard-2 机器类型的配方,看看您应用的相同配方是否有效。如果确实如此……那么我们可能可以得出一个初步结论,即 micro/small 共享核心处理器可能不支持嵌套虚拟化。
我尝试了与您相同的命令,但使用的是 Ubuntu 16.04 和 18.04 LTS,而且我的 VM 一开始也不支持 KVM。
我决定检查 documentation 再试一次:
启动盘(和你的一样)
gcloud compute disks create disk1 --image-project ubuntu-os-cloud \
--image-family ubuntu-1804-lts --zone us-central1-a
自定义图像(与您的相同)
gcloud compute images create nested-vm-image \
--source-disk disk1 --source-disk-zone us-central1-a \
--licenses "https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
VM n1-standard-1(根据官方文档)
gcloud compute instances create example-nested-vm --zone us-central1-b \
--min-cpu-platform "Intel Haswell" \
--image nested-vm-image
嵌套虚拟化正常工作:
$ grep -cw vmx /proc/cpuinfo
1
$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
它也适用于抢占式虚拟机:
gcloud compute instances create preemptible-nested-vm \
--zone us-central1-a --preemptible \
--min-cpu-platform "Intel Haswell" \
--image nested-vm-image
我在第 3 步尝试设置其他机器类型,但出现错误:
gcloud compute instances create e2-nested-vm --zone us-central1-a \
--machine-type e2-standard-2 \
--min-cpu-platform "Intel Haswell" \
--image nested-vm-image
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Setting minimum CPU platform is not supported for the selected machine type e2-
standard-2.
但是 此命令不遵循 documentation。
因此,如果您逐步按照指南 machine-type e2-standard-2 doesn't support nested virtualization,嵌套虚拟化适用于 Ubuntu 16.04 和 18.04。
我正在尝试在 Google 云平台 (GCP) 上使用嵌套虚拟化功能,但是我在尝试使用它时没有成功。根据 GCP documentation:
,这是我遵循的程序- 创建新磁盘,基于 Ubuntu 18 LTS 映像
- 从磁盘创建新映像,应用 vmx 许可证
- 从映像创建新的 VM 实例
- 检查是否支持嵌套虚拟化,使用Ubuntu 中的
cpu-checker
包
gcloud compute disks create disk1 --image-project ubuntu-os-cloud --image-family ubuntu-1804-lts --zone us-central1-a
gcloud compute images create nested-vm-image --source-disk disk1 --source-disk-zone us-central1-a --licenses "https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
gcloud compute instances create firecracker --description firecracker --image nested-vm-image --zone us-central1-a --preemptible --machine-type e2-micro
根据 运行 sudo kvm-ok
命令,我收到此消息:
INFO: Your CPU does not support KVM extensions
KVM acceleration can NOT be used
疑难解答
确保我使用的是 Haswell CPU
我使用 gcloud compute instances describe
命令确认我的 e2-micro
VM 正在使用 Intel Haswell CPU,根据 GCP,这是嵌套虚拟化工作所需的最低要求文档。
(base) ➜ ~ gcloud compute instances describe firecracker
No zone specified. Using zone [us-central1-a] for instance: [firecracker].
canIpForward: false
cpuPlatform: Intel Haswell
creationTimestamp: 'xxxxxxxxxxxxxxx'
deletionProtection: false
description: firecracker
disks:
- autoDelete: true
boot: true
deviceName: persistent-disk-0
guestOsFeatures:
- type: VIRTIO_SCSI_MULTIQUEUE
index: 0
interface: SCSI
kind: compute#attachedDisk
licenses:
- https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/licenses/ubuntu-1804-lts
- https://www.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx
mode: READ_WRITE
source: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/disks/firecracker
type: PERSISTENT
id: 'xxxxxxxxxxxxxxxxxxxxx'
kind: compute#instance
labelFingerprint: xxxxxxxxxxxxxx
machineType: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/machineTypes/e2-micro
metadata:
fingerprint: xxxxxxxxxxxxxxx
kind: compute#metadata
name: firecracker
networkInterfaces:
- accessConfigs:
- kind: compute#accessConfig
name: external-nat
natIP: xxxxxxxxxxx
networkTier: PREMIUM
type: ONE_TO_ONE_NAT
fingerprint: xxxxxxxxxxxxxx
kind: compute#networkInterface
name: nic0
network: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/global/networks/default
networkIP: xxxxxxxxxxxxxx
subnetwork: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/regions/us-central1/subnetworks/default
scheduling:
automaticRestart: false
onHostMaintenance: TERMINATE
preemptible: true
selfLink: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a/instances/firecracker
serviceAccounts:
- email: xxxxxxxx@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/pubsub
- https://www.googleapis.com/auth/service.management.readonly
- https://www.googleapis.com/auth/servicecontrol
- https://www.googleapis.com/auth/trace.append
startRestricted: false
status: RUNNING
tags:
fingerprint: xxxxxxxxxxxxxxxx
zone: https://www.googleapis.com/compute/v1/projects/xxxxxxxx/zones/us-central1-a
已尝试 Ubuntu 16.04 LTS
根据文档,我还尝试了使用 Ubuntu 16.04 LTS 的相同过程,并收到了与使用 Ubuntu 18.04 LTS 相同的结果。
问题
问题:如何成功启动支持嵌套虚拟化的 GCP VM?据我所知,我遵循了文档的要求,但无法正常工作。
我知道文档没有明确指出他们使用 Ubuntu 18 LTS 测试嵌套虚拟化,但这并不一定意味着它不会工作。
这是一个猜答案...如果错了,post评论,它将被删除...
如果我们在 Machine Types 下查看,我们会发现以下内容:
Shared-core machine types are available in the N1 and E2 families. These machine types timeshare a physical core. This can be a cost-effective method for running small, non-resource intensive applications.
N1: f1-micro and g1-small shared-core machine types have up to 1 vCPU available for short periods of bursting.
E2: e2-micro, e2-small, and e2-medium shared-core machine types have 2 vCPUs available for short periods of bursting.
在您的故事中,您说您使用的是 e2-micro 机器类型。 Machine this all together 我们看到您选择了一种似乎执行共享核心处理的机器类型,并正在尝试启用嵌套虚拟化。我的直觉是共享核心意味着你的 CPU 运行 你的 OS/app 是在其他用户 运行 他们的 OS/app 之间分割的时间......而这个概念嵌套虚拟化(我认为)要求您拥有 CPU 的专有所有权,正如 "normal" 家庭成员中所见。我建议 运行 您使用 n1-standard-2 机器类型的配方,看看您应用的相同配方是否有效。如果确实如此……那么我们可能可以得出一个初步结论,即 micro/small 共享核心处理器可能不支持嵌套虚拟化。
我尝试了与您相同的命令,但使用的是 Ubuntu 16.04 和 18.04 LTS,而且我的 VM 一开始也不支持 KVM。
我决定检查 documentation 再试一次:
启动盘(和你的一样)
gcloud compute disks create disk1 --image-project ubuntu-os-cloud \ --image-family ubuntu-1804-lts --zone us-central1-a
自定义图像(与您的相同)
gcloud compute images create nested-vm-image \ --source-disk disk1 --source-disk-zone us-central1-a \ --licenses "https://compute.googleapis.com/compute/v1/projects/vm-options/global/licenses/enable-vmx"
VM n1-standard-1(根据官方文档)
gcloud compute instances create example-nested-vm --zone us-central1-b \ --min-cpu-platform "Intel Haswell" \ --image nested-vm-image
嵌套虚拟化正常工作:
$ grep -cw vmx /proc/cpuinfo
1
$ sudo kvm-ok
INFO: /dev/kvm exists
KVM acceleration can be used
它也适用于抢占式虚拟机:
gcloud compute instances create preemptible-nested-vm \
--zone us-central1-a --preemptible \
--min-cpu-platform "Intel Haswell" \
--image nested-vm-image
我在第 3 步尝试设置其他机器类型,但出现错误:
gcloud compute instances create e2-nested-vm --zone us-central1-a \
--machine-type e2-standard-2 \
--min-cpu-platform "Intel Haswell" \
--image nested-vm-image
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Setting minimum CPU platform is not supported for the selected machine type e2-
standard-2.
但是 此命令不遵循 documentation。
因此,如果您逐步按照指南 machine-type e2-standard-2 doesn't support nested virtualization,嵌套虚拟化适用于 Ubuntu 16.04 和 18.04。