我正在尝试从已关闭的现有VM创建实例模板。VM是一个非常基本的Centos Linux机器。在用谷歌搜索了一下这个问题之后,我想出了以下内容,但我不知道如何格式化磁盘设备名称。我能找到的例子并不多。提前感谢你在这个问题上的任何启发。
$gcloud compute instance-templates create plainid-pocv12-cent8-autostart --source-instance ajm-centos8 --configure-disk=device-name=/dev/sda,instantiate-from=source-image,auto-delete=true
ERROR: (gcloud.compute.instance-templates.create) Could not fetch resource:
- Invalid value for field 'resource.sourceInstanceParams.diskConfigs[0].deviceName': '/dev/sda'. Device name specified in disk instantiation config not found in source instance: '/dev/sda'.
根据下面的建议,我运行了describe。看起来设备名称也是'ajm-centos8‘
$gcloud compute instances describe ajm-centos8
canIpForward: false
confidentialInstanceConfig:
enableConfidentialCompute: false
cpuPlatform: Intel Haswell
creationTimestamp: '2020-10-05T06:04:50.611-07:00'
deletionProtection: false
description: ''
disks:
- autoDelete: true
boot: true
deviceName: ajm-centos8
diskSizeGb: '30'
guestOsFeatures:
- type: UEFI_COMPATIBLE
- type: VIRTIO_SCSI_MULTIQUEUE
- type: SEV_CAPABLE
index: 0
interface: SCSI
kind: compute#attachedDisk
licenses:
- https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-8
mode: READ_WRITE
source: https://www.googleapis.com/compute/v1/projects/plainid-presales/zones/us-east1-b/disks/ajm-centos8
type: PERSISTENT
因此,我现在运行以下命令。它创建了一个模板,耶!但是,新模板上没有安装我在原始VM上安装的任何软件。
$gcloud compute instance-templates create plainid-pocv12-cent8-autostart --source-instance ajm-centos8 --configure-disk=device-name=ajm-centos8,instantiate-from=source-image,auto-delete=true
Created [https://www.googleapis.com/compute/v1/projects/plainid-presales/global/instanceTemplates/plainid-pocv12-cent8-autostart].
NAME MACHINE_TYPE PREEMPTIBLE CREATION_TIMESTAMP
plainid-pocv12-cent8-autostart custom (e2, 2 vCPU, 6.00 GiB) 2020-10-09T13:55:02.563-07:00
发布于 2021-08-30 00:04:25
为了能够将安装在虚拟机上的任何程序保留到实例模板中,必须使用原始实例中使用的映像创建实例模板。
按照以下步骤从您的原始实例创建镜像:
Create Image
.Name
。Image
作为Source
。在这里,您可以使用创建的镜像创建实例模板,并且镜像上预安装的所有应用程序或程序都将被保留。
发布于 2020-10-12 19:48:28
实例模板主要用于定义和保存机器配置,如机器类型、引导盘镜像或容器镜像、标签和其他实例属性。然后,可以立即使用该模板来创建单个VM或MIG。您可以查看Instance templates以了解更多详细信息。
creating an instance template based on an existing instance文档看起来很有帮助here.Here在此文档中,您可以查看用于覆盖磁盘在模板中的定义方式的选项。
https://stackoverflow.com/questions/64286663
复制