Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Gunakan image mesin untuk menyimpan semua
konfigurasi, metadata, izin, dan data dari beberapa disk untuk instance VM
yang berjalan di Compute Engine. Instance VM yang Anda gunakan untuk membuat
image mesin disebut sebagai instance sumber VM.
Untuk mengetahui informasi tentang waktu dan cara menggunakan image mesin,
lihat Image mesin.
Dokumen ini menjelaskan langkah-langkah untuk membuat image mesin dari instance VM
sumber.
Sebelum memulai
Jika Anda belum melakukannya, siapkan autentikasi.
Autentikasi adalah
proses yang digunakan untuk memverifikasi identitas Anda untuk mengakses Google Cloud layanan dan API.
Untuk menjalankan kode atau sampel dari lingkungan pengembangan lokal, Anda dapat melakukan autentikasi ke
Compute Engine dengan memilih salah satu opsi berikut:
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
Menginstal Google Cloud CLI.
Setelah penginstalan,
lakukan inisialisasi Google Cloud CLI dengan menjalankan perintah berikut:
Jika Anda menggunakan CSEK untuk melindungi image mesin, salinan lengkap semua data disk
akan disimpan selama pembuatan image mesin. Dalam semua skenario lainnya,
data disk disimpan dalam
salinan diferensial.
Anda tidak dapat membuat image mesin dari VM sumber yang:
Memiliki disk yang terpasang lebih dari 200 TB.
Tidak memiliki disk yang terpasang.
Memiliki volume Hyperdisk yang terpasang.
Gunakan jenis mesin Z3, kecuali z3-highmem-192-highlssd-metal.
Gunakan jenis mesin C3D, H3, atau A3.
Properti instance dan disk tidak didukung oleh image mesin
Saat Anda membuat image mesin dari instance VM atau membuat instance VM dari
image mesin, properti instance dan disk berikut tidak dipertahankan
atau dipulihkan:
disks.architecture
disks.description
disks.labels
disks.locked
disks.multiWriter
disks.onUpdateAction
disks.provisionedIops
disks.shieldedInstanceInitialState
disks.sourceImage
disks.sourceImageEncryptionKey
disks.sourceInstantSnapshot
disks.sourceSnapshot
disks.sourceSnapshotEncryptionKey
privateIpv6GoogleAccess
resourceManagerTags
resourcePolicies
secure_tag
shieldedInstanceConfig
Membuat image mesin dari VM
Izin yang diperlukan untuk langkah ini
Untuk melakukan tugas ini, Anda harus memiliki izin berikut:
compute.machineImages.create pada project
compute.instances.useReadOnly pada instance sumber
Kunci enkripsi opsional. Anda dapat memilih antara Google-owned and Google-managed encryption key, kunci
Cloud Key Management Service (Cloud KMS) atau kunci
enkripsi yang disediakan pelanggan (CSEK). Jika kunci enkripsi tidak ditentukan, image mesin akan dienkripsi menggunakan
Google-owned and Google-managed encryption key.
Jika Anda ingin menggunakan image mesin untuk
cloning instance dan pembuatan snapshot,
hapus informasi OS dan aplikasi yang unik untuk instance tersebut sebelum
membuat image mesin dari instance. Misalnya, untuk instance VM Windows,
gunakan GCESysprep untuk menyiapkan sistem untuk replikasi.
Konsol
Di konsol Google Cloud , buka halaman Machine images.
Opsional: Tentukan tempat untuk menyimpan image mesin. Pilih antara penyimpanan Multi-regional
atau Regional. Untuk mengetahui informasi selengkapnya tentang lokasi, lihat
Lokasi penyimpanan image mesin.
MACHINE_IMAGE_NAME: nama image mesin
yang ingin Anda buat.
SOURCE_VM_NAME: nama instance VM
sumber tempat Anda ingin membuat image.
Contoh
Misalnya, Anda dapat menggunakan perintah gcloud berikut untuk membuat image mesin
yang disebut my-machine-image dari instance sumber yang disebut my-instance:
MACHINE_IMAGE_NAME: nama image mesin
yang ingin Anda buat.
SOURCE_INSTANCE_URL: URL lengkap atau sebagian
instance VM sumber yang ingin Anda gunakan untuk membuat image mesin.
Misalnya, jika Anda memiliki instance sumber bernama my-instance dalam
project bernama myProject. URL berikut valid:
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-08-18 UTC."],[[["\u003cp\u003eMachine images store a VM instance's configuration, metadata, permissions, and data from multiple disks, using a source VM instance as the base.\u003c/p\u003e\n"],["\u003cp\u003eMachine images can be created through the Google Cloud console, the Google Cloud CLI, or REST API, requiring specific permissions such as \u003ccode\u003ecompute.machineImages.create\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eCreating a machine image involves specifying a name, the source VM instance, and its zone, with optional settings like storage location and encryption key, with a limit of six creations per instance every 60 minutes.\u003c/p\u003e\n"],["\u003cp\u003eCertain instance and disk properties are not preserved or restored when creating or using machine images, such as \u003ccode\u003edisks.architecture\u003c/code\u003e, \u003ccode\u003edisks.description\u003c/code\u003e, and \u003ccode\u003eresourcePolicies\u003c/code\u003e, among others.\u003c/p\u003e\n"],["\u003cp\u003eMachine images can not be created from source VMs that exceed 200TB of disks, have no attached disks, any attached Hyperdisk volumes or use a C3D, H3, A3 or Z3 machine type.\u003c/p\u003e\n"]]],[],null,["# Create machine images\n\n*** ** * ** ***\n\nUse a machine image to store all the\nconfiguration, metadata, permissions, and data from multiple disks for a VM\ninstance running on Compute Engine. The VM instance that you use to create a\nmachine image is referred to as a *source VM instance*.\n\nFor information about when and how to use machine images,\nsee [Machine images](/compute/docs/machine-images).\n\nThis document describes the steps for creating a machine image from a source VM\ninstance.\n\nBefore you begin\n----------------\n\n- If you haven't already, set up [authentication](/compute/docs/authentication). Authentication verifies your identity for access to Google Cloud services and APIs. To run code or samples from a local development environment, you can authenticate to Compute Engine by selecting one of the following options:\n\n Select the tab for how you plan to use the samples on this page: \n\n ### Console\n\n\n When you use the Google Cloud console to access Google Cloud services and\n APIs, you don't need to set up authentication.\n\n ### gcloud\n\n 1.\n [Install](/sdk/docs/install) the Google Cloud CLI.\n\n After installation,\n [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command:\n\n ```bash\n gcloud init\n ```\n\n\n If you're using an external identity provider (IdP), you must first\n [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n | **Note:** If you installed the gcloud CLI previously, make sure you have the latest version by running `gcloud components update`.\n 2. [Set a default region and zone](/compute/docs/gcloud-compute#set_default_zone_and_region_in_your_local_client).\n\n ### REST\n\n\n To use the REST API samples on this page in a local development environment, you use the\n credentials you provide to the gcloud CLI.\n 1. [Install](/sdk/docs/install) the Google Cloud CLI. After installation, [initialize](/sdk/docs/initializing) the Google Cloud CLI by running the following command: \n\n ```bash\n gcloud init\n ```\n 2. If you're using an external identity provider (IdP), you must first [sign in to the gcloud CLI with your federated identity](/iam/docs/workforce-log-in-gcloud).\n\n\n For more information, see\n [Authenticate for using REST](/docs/authentication/rest)\n in the Google Cloud authentication documentation.\n\nLimitations and restrictions\n----------------------------\n\n- You can create a machine image of a specific instance at most 6 times every 60 minutes.\n- You can protect a machine image by using either [Cloud Key Management Service (Cloud KMS)](/kms/docs) or a [customer-supplied encryption key (CSEK)](/compute/docs/disks/customer-supplied-encryption). The encryption key protects the content of the disks. However, metadata isn't protected.\n- If you use a CSEK to protect your machine image, a full copy of all disk data is stored during the generation of the machine image. In all other scenarios disk data is stored in [differential copies](/compute/docs/machine-images#disk-backup).\n- You can't create machine images from source VMs that:\n\n - Have greater than 200 TB of disks attached.\n - Don't have any attached disks.\n - Have any attached Hyperdisk volumes.\n - Use Z3 machine type except for `z3-highmem-192-highlssd-metal`.\n - Use a C3D, H3, or A3 machine type.\n\n For instances that don't support the creation of machine images, you can\n instead create an OS image from the boot disk of the instance, as described in\n [Create custom images](/compute/docs/images/create-custom).\n\n### Instance and disk properties not supported by machine image\n\nWhen you create machine images from VM instances or create VM instances from\nmachine images, the following instance and disk properties are not preserved\nor restored:\n\n- `disks.architecture`\n- `disks.description`\n- `disks.labels`\n- `disks.locked`\n- `disks.multiWriter`\n- `disks.onUpdateAction`\n- `disks.provisionedIops`\n- `disks.shieldedInstanceInitialState`\n- `disks.sourceImage`\n- `disks.sourceImageEncryptionKey`\n- `disks.sourceInstantSnapshot`\n- `disks.sourceSnapshot`\n- `disks.sourceSnapshotEncryptionKey`\n- `privateIpv6GoogleAccess`\n- `resourceManagerTags`\n- `resourcePolicies`\n- `secure_tag`\n- `shieldedInstanceConfig`\n\nCreating a machine image from a VM\n----------------------------------\n\n#### Permissions required for this task\n\nTo perform this task, you must have the following\n[permissions](/iam/docs/overview#permissions):\n\n\n- `compute.machineImages.create` on the project\n- `compute.instances.useReadOnly` on the source instance\n- `compute.disks.createSnapshot` on the disk\n\nYou can create machine images using either the\n[Google Cloud console](https://console.cloud.google.com/), the\n[Google Cloud CLI](/compute/docs/gcloud-compute), or\n[REST](/compute/docs/reference/rest/v1).\n\nTo create a machine image, you need the following information:\n\n- A name for the machine image that you want to create.\n- The name of the source VM instance.\n- The zone that the source VM instance is located in.\n- An optional description.\n- An optional [`storageLocation`](/compute/docs/machine-images#storage-location). If you don't specify a location, the default storage location is the [multiregional Cloud Storage location](/storage/docs/locations#location-mr) of the source VM instance.\n- An optional encryption key. You can choose between a Google-owned and Google-managed encryption key, a [Cloud Key Management Service (Cloud KMS)](/kms/docs) key or a [customer-supplied encryption (CSEK)](/compute/docs/disks/customer-supplied-encryption) key. If no encryption key is specified, machine images are encrypted using a Google-owned and Google-managed encryption key.\n- If you want to use a machine image for\n [instance cloning and snapshotting](/compute/docs/machine-images#cloning),\n remove the OS and app information that is unique to the instance before\n generating the machine image from an instance. For example, for Windows VM\n instances, use `GCESysprep` to prepare the system for replication.\n\n### Console\n\n1. In the Google Cloud console, go to the **Machine images** page.\n\n [Go to Machine images](https://console.cloud.google.com/compute/machineImages)\n2. Click **Create Machine image**.\n\n3. Specify a **Name** for your machine image.\n\n4. Optional: Provide a **Description**.\n\n5. Select the **Source VM instance**.\n\n6. Optional: Specify where to store the machine image. Choose between **Multi-regional**\n or **Regional** storage. For more information about location, see\n [Machine image storage location](/compute/docs/machine-images#storage-location).\n\n7. Optional: Select an **Encryption** method.\n\n8. Click **Create**.\n\n### gcloud\n\nUse the\n[`gcloud compute machine-images create`](/sdk/gcloud/reference/compute/machine-images/create)\ncommand to create a machine image from an instance. \n\n```\ngcloud compute machine-images create MACHINE_IMAGE_NAME \\\n --source-instance=SOURCE_VM_NAME\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eMACHINE_IMAGE_NAME\u003c/var\u003e: name of the machine image that you want to create.\n- \u003cvar translate=\"no\"\u003eSOURCE_VM_NAME\u003c/var\u003e: name of the source VM instance that you want to create the image from.\n\n**Example**\n\nFor example, you can use the following `gcloud` command to create a machine\nimage called `my-machine-image` from a source instance called `my-instance`: \n\n```\ngcloud compute machine-images create my-machine-image \\\n --source-instance=my-instance\n```\n\nThe process takes a few minutes. When the machine image is created, you get\nan output that resembles the following: \n\n```\nCreated [https://www.googleapis.com/compute/v1/projects/project-12345/global/machineImages/my-machine-image].\nNAME STATUS\nmy-machine-image READY\n```\n\n### REST\n\nIn the API, construct a `POST` request to the\n[`machineimages.insert`](/compute/docs/reference/rest/v1/machineImages/insert)\nmethod. In the request body, include the following `POST` request: \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/machineImages\n\n{\n \"name\": \"MACHINE_IMAGE_NAME\",\n \"sourceInstance\": \"SOURCE_INSTANCE_URL\"\n}\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: [project ID](/resource-manager/docs/creating-managing-projects#identifying_projects).\n- \u003cvar translate=\"no\"\u003eMACHINE_IMAGE_NAME\u003c/var\u003e: name of the machine image that you want to create.\n- \u003cvar translate=\"no\"\u003eSOURCE_INSTANCE_URL\u003c/var\u003e: full or partial URL of\n the source VM instance that you want to use to create the machine image.\n For example, if you have a source instance called `my-instance` in\n a project called `myProject`. The following URLs are valid:\n\n - `https://www.googleapis.com/compute/v1/projects/myProject/global/instances/my-instance`\n - `projects/myProject/global/instances/my-instance`\n - `global/instances/my-instance`\n\nWhat's next?\n------------\n\n- Learn more about [machine images](/compute/docs/machine-images)\n- [Create VM instances from machine images](/compute/docs/machine-images/create-instance-from-machine-image)"]]