您可以通过操作系统映像或磁盘映像创建虚拟机 (VM) 实例。本文档介绍如何确定虚拟机的来源操作系统映像或来源磁盘映像。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
在 Google Cloud 控制台中,前往虚拟机实例页面。
点击虚拟机的名称。
来源操作系统映像或来源磁盘映像的名称位于 Storage > 启动磁盘 > 映像。
使用以下
gcloud compute instances describe
命令查看挂接到虚拟机的磁盘:gcloud compute instances describe VM_NAME
将
VM_NAME
替换为虚拟机名称。使用以下
gcloud compute disks describe
命令来查看虚拟机的来源操作系统映像或来源磁盘映像:gcloud compute disks describe DISK_NAME \ --zone=ZONE \ --format="get(SOURCE)"
替换以下内容:
DISK_NAME
:要查看其来源的磁盘的名称。ZONE
:磁盘所在的可用区。SOURCE
:一个值,用于指定是返回来源操作系统映像还是来源磁盘映像。设置为sourceDisk
或sourceImage
。指定sourceDisk
或sourceImage
时不会返回任何值,除非有相应的来源操作系统映像或来源磁盘映像。如果未返回值,请指定其他值并再次运行该命令。
使用以下
instances.get
方法来查看挂接到虚拟机的磁盘:GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
替换以下内容:
PROJECT_ID
:项目 IDZONE
:包含虚拟机的可用区VM_NAME
:虚拟机的名称
使用
disks.get
方法来查看虚拟机的来源操作系统映像或来源磁盘映像。对于具有来源操作系统映像的虚拟机,此方法会在
sourceImage
字段中返回用于创建磁盘的来源映像。对于具有来源磁盘映像的虚拟机,此方法会在sourceDisk
字段中返回来源映像。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME
替换以下内容:
PROJECT_ID
:项目 IDZONE
:包含磁盘的可用区DISK_NAME
:磁盘的名称
- 在 Compute Engine 上详细了解操作系统映像。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
查看虚拟机的来源操作系统映像或来源磁盘映像
如需查看虚拟机的来源操作系统映像或来源磁盘映像,请使用Google Cloud 控制台、Google Cloud CLI 或 Compute Engine API。
控制台
gcloud
REST
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-06-25。
-