יצירת תמונות בהתאמה אישית

אתם יכולים ליצור קובצי אימג' בהתאמה אישית מדיסקים, קובצי אימג' או קובצי snapshot קיימים, או מקובצי אימג' שמאוחסנים ב-Cloud Storage, ולהשתמש בהם כדי ליצור מכונות וירטואליות (VM). תמונות בהתאמה אישית מתאימות למצבים שבהם יצרתם ושיניתם דיסק אתחול מתמיד או תמונה ספציפית למצב מסוים, ואתם צריכים לשמור את המצב הזה כדי ליצור מכונות וירטואליות.

לחלופין, אתם יכולים להשתמש בכלי לייבוא דיסקים וירטואליים כדי לייבא קובצי אימג' של דיסקי אתחול ל-Compute Engine מהמערכות הקיימות שלכם, ולהוסיף אותם לרשימת קובצי האימג' בהתאמה אישית.

לפני שמתחילים

תפקידים והרשאות נדרשים

כדי לקבל את ההרשאות שדרושות ליצירת קובץ אימג' בהתאמה אישית, בקשו מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

התפקידים המוגדרים מראש האלה כוללים את ההרשאות שנדרשות ליצירת קובץ אימג' בהתאמה אישית. כדי לראות בדיוק אילו הרשאות נדרשות, אפשר להרחיב את הקטע ההרשאות הנדרשות:

ההרשאות הנדרשות

כדי ליצור קובץ אימג' בהתאמה אישית, צריך את ההרשאות הבאות:

  • compute.images.create
  • כדי ליצור אימג' בהתאמה אישית מדיסק: ‫compute.disks.useReadOnly בדיסק
  • כדי ליצור אימג' בהתאמה אישית מאימג' קיים: ‫compute.images.useReadOnly באימג' המקור
  • כדי ליצור קובץ אימג' בהתאמה אישית מקובץ snapshot רגיל או מקובץ snapshot של ארכיון: ‫compute.snapshots.useReadOnly בקובץ snapshot של המקור
  • כדי להוסיף תווית לתמונה החדשה: compute.images.setLabels על התווית

יכול להיות שתקבלו את ההרשאות האלה באמצעות תפקידים בהתאמה אישית או תפקידים מוגדרים מראש אחרים.

יצירת תמונה בהתאמה אישית

בקטע הזה מוסבר איך ליצור קובץ אימג' בהתאמה אישית ב-VM של Linux. למידע על יצירת קובץ אימג' של Windows, קראו את המאמר יצירת קובץ אימג' של Windows.

בחירת מיקום לאחסון התמונות

כשיוצרים קובץ אימג' בהתאמה אישית, אפשר לציין את המיקום של קובץ האימג' ב-Cloud Storage, לא כולל מיקומים בשני אזורים. כשמציינים את מיקום האחסון של קובץ האימג', אפשר לעמוד בדרישות הרגולטוריות והתאימות של אחסון ועיבוד נתונים באופן מקומי, וגם בדרישות לזמינות גבוהה על ידי מתן יתירות בין אזורים. כדי ליצור, לשנות ולמחוק תמונות שמאוחסנות ב-Cloud Storage, צריך את ההרשאה roles/compute.storageAdmin.

התכונה "מיקום האחסון" היא אופציונלית. אם לא תבחרו מיקום, המערכת של Compute Engine תאחסן את קובץ האימג' במספר אזורים שקרובים למקור של קובץ האימג'. לדוגמה, כשיוצרים קובץ אימג' מדיסק מקור שנמצא ב-us-central1, אם לא מציינים מיקום לקובץ האימג' בהתאמה אישית, Compute Engine מאחסן את קובץ האימג' במספר האזורים us.

אם קובץ האימג' לא זמין באזור שבו אתם יוצרים מכונה וירטואלית, Compute Engine שומר את קובץ האימג' במטמון באותו אזור בפעם הראשונה שאתם יוצרים מכונה וירטואלית.

כדי לראות את המיקום שבו התמונה מאוחסנת, משתמשים בפקודה images describe מ-gcloud compute:

gcloud compute images describe IMAGE_NAME \
    --project=PROJECT_ID

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: שם התמונה.

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייכת התמונה.

כל התמונות הקיימות מלפני השקת התכונה הזו נשארות במקומן, והשינוי היחיד הוא שאתם יכולים לראות את מיקום התמונה של כל התמונות שלכם. אם יש לכם תמונה קיימת שאתם רוצים להעביר, אתם צריכים ליצור אותה מחדש במיקום החדש.

הכנת ה-VM לתמונה

אפשר ליצור קובץ אימג' מדיסק גם כשהוא מחובר למכונה וירטואלית פועלת. עם זאת, קובץ האימג' יהיה אמין יותר אם תעבירו את ה-VM למצב שקל יותר לצלם בו את קובץ האימג'. בקטע הזה מוסבר איך להכין את דיסק האתחול בשביל קובץ האימג'.

צמצום כתיבת הנתונים בדיסק אחסון מתמיד (persistent disk)

כדי לצמצם את מספר הכתיבות לדיסק, אפשר להשתמש באחד מהתהליכים הבאים:

  • עוצרים את המכונה הווירטואלית כדי שהיא תוכל להפסיק את הפעילות שלה ואת כתיבת הנתונים בדיסק הקבוע.

  • אם אתם לא יכולים לעצור את ה-VM לפני שאתם יוצרים את קובץ האימג', צמצמו את כמות הכתיבות לדיסק וסנכרנו את מערכת הקבצים. כדי לצמצם את הכתיבה ל-Persistent Disk, פועלים לפי השלבים הבאים:

    1. להשהות אפליקציות או תהליכים של מערכת ההפעלה שכותבים נתונים לדיסק הקבוע.
    2. אם צריך, מריצים את האפליקציה flush to disk. לדוגמה, ל-MySQL יש הצהרה של FLUSH. יכול להיות שבאפליקציות אחרות יש תהליכים דומים.
    3. מפסיקים את הכתיבה של האפליקציות לדיסק האחסון המתמיד (persistent disk).
    4. מריצים את sudo sync.

השבתת אפשרות המחיקה האוטומטית של הדיסק

כברירת מחדל, אפשרות המחיקה האוטומטית מופעלת בדיסקי האתחול. לפני שיוצרים קובץ אימג' מדיסק, צריך להשבית את המחיקה האוטומטית כדי למנוע את מחיקת הדיסק באופן אוטומטי כשמוחקים את ה-VM.

כדי להשבית את המחיקה האוטומטית של הדיסק, משתמשים באחת מהשיטות הבאות:

המסוף

  1. נכנסים לדף VM instances במסוף Google Cloud .

    לדף VM instances

  2. לוחצים על השם של ה-VM שמשמש כמקור ליצירת קובץ אימג'.

    הדף VM instance details נפתח.

  3. לוחצים על Edit.

  4. בקטע דיסק אתחול, מוודאים שהאפשרות Keep disk מסומנת בשדה כלל מחיקה.

  5. לוחצים על Save.

gcloud

ב-Google Cloud CLI, משתמשים בפקודה gcloud compute instances set-disk-auto-delete כדי להשבית את אפשרות המחיקה האוטומטית של הדיסק.

gcloud compute instances set-disk-auto-delete VM_NAME \
    --no-auto-delete \
    --disk=SOURCE_DISK

מחליפים את מה שכתוב בשדות הבאים:

  • ‫VM_NAME: השם של המכונה הווירטואלית.
  • ‫SOURCE_DISK: שם הדיסק שממנו רוצים ליצור את קובץ האימג'.

המשך

Go

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Go במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Go API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
)

// setDiskAutodelete sets the autodelete flag of a disk to given value.
func setDiskAutoDelete(
	w io.Writer,
	projectID, zone, instanceName, diskName string, autoDelete bool,
) error {
	// projectID := "your_project_id"
	// zone := "us-west3-b"
	// instanceName := "your_instance_name"
	// diskName := "your_disk_name"
	// autoDelete := true

	ctx := context.Background()
	instancesClient, err := compute.NewInstancesRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewInstancesRESTClient: %w", err)
	}
	defer instancesClient.Close()

	getInstanceReq := &computepb.GetInstanceRequest{
		Project:  projectID,
		Zone:     zone,
		Instance: instanceName,
	}

	instance, err := instancesClient.Get(ctx, getInstanceReq)
	if err != nil {
		return fmt.Errorf("unable to get instance: %w", err)
	}

	diskExists := false

	for _, disk := range instance.GetDisks() {
		if disk.GetDeviceName() == diskName {
			diskExists = true
			break
		}
	}

	if !diskExists {
		return fmt.Errorf(
			"instance %s doesn't have a disk named %s attached",
			instanceName,
			diskName,
		)
	}

	req := &computepb.SetDiskAutoDeleteInstanceRequest{
		Project:    projectID,
		Zone:       zone,
		Instance:   instanceName,
		DeviceName: diskName,
		AutoDelete: autoDelete,
	}

	op, err := instancesClient.SetDiskAutoDelete(ctx, req)
	if err != nil {
		return fmt.Errorf("unable to set disk autodelete field: %w", err)
	}

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "disk autoDelete field updated.\n")

	return nil
}

Java

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Java במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Java API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.


import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstancesClient;
import com.google.cloud.compute.v1.Operation;
import com.google.cloud.compute.v1.SetDiskAutoDeleteInstanceRequest;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class SetDiskAutodelete {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.

    // Project ID or project number of the Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";

    // The zone of the disk that you want to modify.
    String zone = "europe-central2-b";

    // Name of the instance the disk is attached to.
    String instanceName = "YOUR_INSTANCE_NAME";

    // The name of the disk for which you want to modify the autodelete flag.
    String diskName = "YOUR_DISK_NAME";

    // The new value of the autodelete flag.
    boolean autoDelete = true;

    setDiskAutodelete(projectId, zone, instanceName, diskName, autoDelete);
  }

  // Sets the autodelete flag of a disk to given value.
  public static void setDiskAutodelete(String projectId, String zone, String instanceName,
      String diskName, boolean autoDelete)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {

    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `instancesClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {

      // Retrieve the instance given by the instanceName.
      Instance instance = instancesClient.get(projectId, zone, instanceName);

      // Check if the instance contains a disk that matches the given diskName.
      boolean diskNameMatch = instance.getDisksList()
          .stream()
          .anyMatch(disk -> disk.getDeviceName().equals(diskName));

      if (!diskNameMatch) {
        throw new Error(
            String.format("Instance %s doesn't have a disk named %s attached", instanceName,
                diskName));
      }

      // Create the request object.
      SetDiskAutoDeleteInstanceRequest request = SetDiskAutoDeleteInstanceRequest.newBuilder()
          .setProject(projectId)
          .setZone(zone)
          .setInstance(instanceName)
          .setDeviceName(diskName)
          // Update the autodelete property.
          .setAutoDelete(autoDelete)
          .build();

      // Wait for the update instance operation to complete.
      Operation response = instancesClient.setDiskAutoDeleteAsync(request)
          .get(3, TimeUnit.MINUTES);

      if (response.hasError()) {
        System.out.println("Failed to update Disk autodelete field!" + response);
        return;
      }
      System.out.println(
          "Disk autodelete field updated. Operation Status: " + response.getStatus());
    }
  }
}

Node.js

Node.js

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Node.js במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Node.js API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

/**
 * TODO(developer): Uncomment and replace these variables before running the sample.
 */
// const projectId = 'YOUR_PROJECT_ID';
// const zone = 'europe-central2-b';
// const instanceName = 'YOUR_INSTANCE_NAME';
// const diskName = 'YOUR_DISK_NAME';
// const autoDelete = true;

const compute = require('@google-cloud/compute');

async function setDiskAutodelete() {
  const instancesClient = new compute.InstancesClient();

  const [instance] = await instancesClient.get({
    project: projectId,
    zone,
    instance: instanceName,
  });

  if (!instance.disks.some(disk => disk.deviceName === diskName)) {
    throw new Error(
      `Instance ${instanceName} doesn't have a disk named ${diskName} attached.`
    );
  }

  const [response] = await instancesClient.setDiskAutoDelete({
    project: projectId,
    zone,
    instance: instanceName,
    deviceName: diskName,
    autoDelete,
  });
  let operation = response.latestResponse;
  const operationsClient = new compute.ZoneOperationsClient();

  // Wait for the update instance operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await operationsClient.wait({
      operation: operation.name,
      project: projectId,
      zone: operation.zone.split('/').pop(),
    });
  }

  console.log('Disk autoDelete field updated.');
}

setDiskAutodelete();

Python

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Python API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

from __future__ import annotations

import sys
from typing import Any

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


def set_disk_autodelete(
    project_id: str, zone: str, instance_name: str, disk_name: str, autodelete: bool
) -> None:
    """
    Set the autodelete flag of a disk to given value.

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        zone: name of the zone in which is the disk you want to modify.
        instance_name: name of the instance the disk is attached to.
        disk_name: the name of the disk which flag you want to modify.
        autodelete: the new value of the autodelete flag.
    """
    instance_client = compute_v1.InstancesClient()
    instance = instance_client.get(
        project=project_id, zone=zone, instance=instance_name
    )

    for disk in instance.disks:
        if disk.device_name == disk_name:
            break
    else:
        raise RuntimeError(
            f"Instance {instance_name} doesn't have a disk named {disk_name} attached."
        )

    disk.auto_delete = autodelete

    operation = instance_client.update(
        project=project_id,
        zone=zone,
        instance=instance_name,
        instance_resource=instance,
    )

    wait_for_extended_operation(operation, "disk update")

REST

כדי להגדיר את אפשרות המחיקה האוטומטית של דיסק, שולחים בקשת POST אל ה-method‏ instances.setDiskAutoDelete.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME/setDiskAutoDelete?autoDelete=false&deviceName=SOURCE_DISK

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייכת ה-VM המקורית.
  • ‫ZONE: האזור שבו נמצאת ה-VM המקורית.
  • ‫VM_NAME: השם של ה-VM המקורי.
  • ‫SOURCE_DISK: שם המכשיר של הדיסק שממנו רוצים ליצור את קובץ האימג'.

אחרי שמכינים את ה-VM, יוצרים את קובץ האימג'.

יוצרים את התמונה

אפשר ליצור קובצי אימג' של דיסק מהמקורות הבאים:

  • דיסק לאחסון מתמיד, גם כשהדיסק מחובר ל-VM
  • תמונת מצב של דיסק אחסון מתמיד (persistent disk)
  • תמונה אחרת בפרויקט
  • תמונה ששותפה מפרויקט אחר
  • תמונת RAW דחוסה ב-Cloud Storage

אפשר ליצור קובץ אימג' פעם אחת בכל 10 דקות. אם רוצים לשלוח מספר גדול של בקשות ליצירת קובץ אימג' בבת אחת, אפשר לשלוח עד 6 בקשות ב-60 דקות. מידע נוסף זמין בקטע מגבלות על תדירות של תמונות מצב.

המסוף

  1. נכנסים לדף Create an image במסוף Google Cloud .

    כניסה לדף Create an image

  2. מציינים את השם (Name) של קובץ האימג'.

  3. מציינים את המקור (Source) שממנו רוצים ליצור קובץ אימג'. זה יכול להיות Persistent Disk, קובץ snapshot, קובץ אימג' אחר או קובץ disk.raw ב-Cloud Storage.

  4. אם יוצרים קובץ אימג' מדיסק שמחובר למכונה וירטואלית פועלת, בוחרים באפשרות Keep instance running כדי לאשר שרוצים ליצור את קובץ האימג' בזמן שהמכונה הווירטואלית פועלת. אתם יכולים להכין את ה-VM לפני שאתם יוצרים את קובץ האימג'.

  5. ברשימה הנפתחת Based on source disk location (default), מציינים את המיקום שבו רוצים לאחסן את קובץ האימג'. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים ב-us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine מאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

  6. אופציונלי: מציינים את המאפיינים של התמונה.

    • ‫Family: משפחת התמונות שאליה שייכת התמונה החדשה.
    • תיאור: תיאור של התמונה המותאמת אישית.
    • ‫Label: תווית לקיבוץ משאבים.
  7. מציינים את מפתח ההצפנה. אתם יכולים לבחור בין Google-owned and Google-managed encryption key, מפתח של Cloud Key Management Service (Cloud KMS) או מפתח הצפנה באספקת הלקוח (CSEK) (הוצא משימוש). אם לא מציינים מפתח הצפנה, התמונות מוצפנות באמצעות Google-owned and Google-managed encryption key.

  8. לוחצים על יצירה כדי ליצור את התמונה.

gcloud

ב-Google Cloud CLI, משתמשים בפקודה gcloud compute images create כדי ליצור קובץ אימג' בהתאמה אישית.

יצירת קובץ אימג' מדיסק מקור:

הדגל --force הוא דגל אופציונלי שמאפשר ליצור את קובץ האימג' ממכונה פועלת. כברירת מחדל, אי אפשר ליצור קובצי אימג' ממכונות פועלות. ציינו את הדגל הזה רק אם אתם בטוחים שאתם רוצים ליצור את קובץ האימג' בזמן שהמכונה פועלת.

gcloud compute images create IMAGE_NAME \
    --source-disk=SOURCE_DISK \
    --source-disk-zone=ZONE \
    [--family=IMAGE_FAMILY] \
    [--storage-location=LOCATION] \
    [--force]

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: שם לתמונה החדשה
  • ‫SOURCE_DISK: הדיסק שממנו רוצים ליצור את קובץ האימג'
  • ‫ZONE: האזור שבו נמצא הדיסק
  • ‫IMAGE_FAMILY: אופציונלי: דגל שמציין לאיזו משפחת תמונות התמונה הזו שייכת
  • ‫LOCATION: אופציונלי: דגל שמאפשר לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' במספר אזורים שהכי קרובים למיקום המקור של קובץ האימג'.

כדי ליצור תמונה שמבוססת על תמונת מקור:

gcloud compute images create IMAGE_NAME \
  --source-image=SOURCE_IMAGE \
  [--source-image-project=IMAGE_PROJECT] \
  [--family=IMAGE_FAMILY] \
  [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: שם לתמונה החדשה.
  • ‫SOURCE_IMAGE: התמונה שממנה רוצים ליצור את התמונה החדשה.
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שבו נמצאת תמונת המקור. השתמשו בפרמטר הזה אם אתם רוצים להעתיק תמונה מפרויקט אחר.
  • ‫IMAGE_FAMILY: אופציונלי: משפחת התמונות שאליה שייכת התמונה החדשה.
  • ‫LOCATION: אופציונלי: מאפשר לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים ב-us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine מאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

יצירת קובץ אימג' מ-snapshot:

gcloud compute images create IMAGE_NAME \
    --source-snapshot=SOURCE_SNAPSHOT \
    [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: שם לתמונה החדשה
  • ‫SOURCE_SNAPSHOT: קובץ ה-snapshot שממנו רוצים ליצור את קובץ האימג'
  • ‫LOCATION: אופציונלי: דגל שמאפשר לציין את האזור או את מספר האזורים שבהם התמונה מאוחסנת. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' במספר אזורים שהכי קרובים למיקום המקור של קובץ האימג'.

כדי לראות את המיקום של התמונה:

משתמשים בפקודה gcloud compute images describe כדי לראות את מיקום קובץ האימג'.

gcloud compute images describe IMAGE_NAME

מחליפים את IMAGE_NAME בשם של קובץ האימג' שרוצים לבדוק.

המשך

Go

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Go במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Go API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

import (
	"context"
	"fmt"
	"io"

	compute "cloud.google.com/go/compute/apiv1"
	computepb "cloud.google.com/go/compute/apiv1/computepb"
)

// Creates a disk image from an existing disk
func createImageFromDisk(
	w io.Writer,
	projectID, zone, sourceDiskName, imageName string,
	storageLocations []string,
	forceCreate bool,
) error {
	// projectID := "your_project_id"
	// zone := "us-central1-a"
	// sourceDiskName := "your_disk_name"
	// imageName := "my_image"
	// // If storageLocations empty, automatically selects the closest one to the source
	// storageLocations = []string{}
	// // If forceCreate is set to `true`, proceeds even if the disk is attached to
	// // a running instance. This may compromise integrity of the image!
	// forceCreate = false

	ctx := context.Background()
	disksClient, err := compute.NewDisksRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewDisksRESTClient: %w", err)
	}
	defer disksClient.Close()
	imagesClient, err := compute.NewImagesRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewImagesRESTClient: %w", err)
	}
	defer imagesClient.Close()

	// Get the source disk
	source_req := &computepb.GetDiskRequest{
		Disk:    sourceDiskName,
		Project: projectID,
		Zone:    zone,
	}

	disk, err := disksClient.Get(ctx, source_req)
	if err != nil {
		return fmt.Errorf("unable to get source disk: %w", err)
	}

	// Create the image
	req := computepb.InsertImageRequest{
		ForceCreate: &forceCreate,
		ImageResource: &computepb.Image{
			Name:             &imageName,
			SourceDisk:       disk.SelfLink,
			StorageLocations: storageLocations,
		},
		Project: projectID,
	}

	op, err := imagesClient.Insert(ctx, &req)

	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Disk image %s created\n", imageName)

	return nil
}

Java

Java

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Java במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Java API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.Image;
import com.google.cloud.compute.v1.ImagesClient;
import com.google.cloud.compute.v1.InsertImageRequest;
import com.google.cloud.compute.v1.Instance;
import com.google.cloud.compute.v1.InstancesClient;
import com.google.cloud.compute.v1.Operation;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateImage {

  public static void main(String[] args)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.

    // Project ID or project number of the Cloud project you use.
    String project = "your-project-id";
    // Zone of the disk you copy from.
    String zone = "europe-central2-b";
    // Name of the source disk you copy from.
    String sourceDiskName = "source-disk-name";
    // Name of the image you want to create.
    String imageName = "your-image-name";
    // Storage location for the image. If the value is undefined,
    // function will store the image in the multi-region closest to your image's source location.
    String storageLocation = "eu";
    // Create the image even if the source disk is attached to a running instance.
    boolean forceCreate = false;

    createImage(project, zone, sourceDiskName, imageName, storageLocation, forceCreate);
  }

  // Creates a new disk image from the specified source disk.
  public static void createImage(String project, String zone, String sourceDiskName,
      String imageName, String storageLocation, boolean forceCreate)
      throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests. After completing all of your requests, call
    // the `client.close()` method on the client to safely
    // clean up any remaining background resources.
    try (ImagesClient imagesClient = ImagesClient.create();
        InstancesClient instancesClient = InstancesClient.create();
        DisksClient disksClient = DisksClient.create()) {

      Disk disk = disksClient.get(project, zone, sourceDiskName);

      // Getting instances where source disk is attached.
      for (String fullInstanceName : disk.getUsersList()) {
        Map<String, String> instanceInfo = parseInstanceName(fullInstanceName);
        Instance instance = instancesClient.get(instanceInfo.get("instanceProjectId"),
            instanceInfo.get("instanceZone"), instanceInfo.get("instanceName"));

        // Сheck whether the instances are stopped.
        if (!Arrays.asList("TERMINATED", "STOPPED").contains(instance.getStatus())
            && !forceCreate) {
          throw new IllegalStateException(
              String.format(
                  "Instance %s should be stopped. For Windows instances please stop the instance "
                      + "using GCESysprep command. For Linux instances just shut it down normally."
                      + " You can suppress this error and create an image of the disk by setting "
                      + "'forceCreate' parameter to true (not recommended). "
                      + "More information here: "
                      + "* https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image#api"
                      + "* https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#prepare_instance_for_image",
                  instanceInfo.get("instanceName")));
        }
      }

      if (forceCreate) {
        System.out.println(
            "Warning: forceCreate option compromise the integrity of your image. "
                + "Stop the instance before you create the image if possible.");
      }

      // Create Image.
      IImageimage = IImagenewBuilder()
          .setName(imageName)
          .setSourceDisk(String.format("/zones/%s/disks/%s", zone, sourceDiskName))
          .addStorageLocations(storageLocation.isEmpty() ? "" : storageLocation)
          .build();

      IInsertImageRequestinsertImageRequest = IInsertImageRequestnewBuilder()
          .setProject(project)
          .ssetForceCreateforceCreate)
          .setImageResource(image)
          .build();

      OOperationresponse = imagesClient.insertAsync(insertImageRequest).get(5, TimeUnit.MINUTES);

      if (rresponse.hasError() {
        System.out.println("Image creation failed ! ! " + response);
        return;
      }

      System.out.println("Image created.");
    }
  }


  public static Map<String, String> parseInstanceName(String name) {
    String[] parsedName = name.split("/");
    int splitLength = parsedName.length;

    if (splitLength < 5) {
      throw new IllegalArgumentException(
          "Provide correct instance name in the following format: "
              + "https://www.googleapis.com/compute/v1/projects/PROJECT/zones/ZONE/instances/INSTANCE_NAME");
    }

    return new HashMap<>() {
      {
        put("instanceName", parsedName[splitLength - 1]);
        put("instanceZone", parsedName[splitLength - 3]);
        put("instanceProjectId", parsedName[splitLength - 5]);
      }
    };
  }

}

Python

Python

לפני שמנסים את הדוגמה הזו, צריך לפעול לפי הוראות ההגדרה של Python במדריך למתחילים של Compute Engine באמצעות ספריות לקוח. מידע נוסף מופיע במאמרי העזרה של Compute Engine Python API.

כדי לבצע אימות ב-Compute Engine, צריך להגדיר את Application Default Credentials. מידע נוסף זמין במאמר הגדרת אימות לספריות לקוח.

from __future__ import annotations

import sys
from typing import Any
import warnings

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1


def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result


STOPPED_MACHINE_STATUS = (
    compute_v1.Instance.Status.TERMINATED.name,
    compute_v1.Instance.Status.STOPPED.name,
)


def create_image_from_disk(
    project_id: str,
    zone: str,
    source_disk_name: str,
    image_name: str,
    storage_location: str | None = None,
    force_create: bool = False,
) -> compute_v1.Image:
    """
    Creates a new disk image.

    Args:
        project_id: project ID or project number of the Cloud project you use.
        zone: zone of the disk you copy from.
        source_disk_name: name of the source disk you copy from.
        image_name: name of the image you want to create.
        storage_location: storage location for the image. If the value is undefined,
            function will store the image in the multi-region closest to your image's
            source location.
        force_create: create the image even if the source disk is attached to a
            running instance.

    Returns:
        An Image object.
    """
    image_client = compute_v1.ImagesClient()
    disk_client = compute_v1.DisksClient()
    instance_client = compute_v1.InstancesClient()

    # Get source disk
    disk = disk_client.get(project=project_id, zone=zone, disk=source_disk_name)

    for disk_user in disk.users:
        instance_name = disk_user.split("/")[-1]
        instance = instance_client.get(
            project=project_id, zone=zone, instance=instance_name
        )
        if instance.status in STOPPED_MACHINE_STATUS:
            continue
        if not force_create:
            raise RuntimeError(
                f"Instance {disk_user} should be stopped. For Windows instances please "
                f"stop the instance using `GCESysprep` command. For Linux instances just "
                f"shut it down normally. You can supress this error and create an image of"
                f"the disk by setting `force_create` parameter to true (not recommended). \n"
                f"More information here: \n"
                f" * https://cloud.google.com/compute/docs/instances/windows/creating-windows-os-image#api \n"
                f" * https://cloud.google.com/compute/docs/images/create-delete-deprecate-private-images#prepare_instance_for_image"
            )
        else:
            warnings.warn(
                f"Warning: The `force_create` option may compromise the integrity of your image. "
                f"Stop the {disk_user} instance before you create the image if possible."
            )

    # Create image
    image = compute_v1.Image()
    image.source_disk = disk.self_link
    image.name = image_name
    if storage_location:
        image.storage_locations = [storage_location]

    operation = image_client.insert(project=project_id, image_resource=image)

    wait_for_extended_operation(operation, "image creation from disk")

    return image_client.get(project=project_id, image=image_name)

REST

שולחים בקשת POST ל-method‏ images().insert, עם כתובת URL בגוף הבקשה שמפנה לאובייקט המקור שממנו רוצים ליצור את קובץ האימג'. ציינו את כתובות ה-URL של המשאבים באמצעות מזהה הפרויקט ושמות המשאבים שלכם.

יצירת קובץ אימג' מדיסק אחסון מתמיד (persistent disk):

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
  "name": "IMAGE_NAME",
  "sourceDisk": "/zones/ZONE/disks/SOURCE_DISK",
  ("storageLocations": "LOCATION",)
  ("forceCreate": "TRUE")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שאליו שייכת התמונה.
  • ‫IMAGE_NAME: השם של קובץ האימג' החדש שרוצים ליצור.
  • ‫ZONE: האזור שבו נמצא דיסק המקור.
  • ‫SOURCE_DISK: הדיסק שממנו רוצים ליצור את קובץ האימג'.
  • ‫LOCATION: אופציונלי: מיקום האחסון של התמונה. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' במספר האזורים שהכי קרוב למיקום המקור של קובץ האימג'.

הפרמטר האופציונלי forceCreate מאפשר ליצור את קובץ האימג' ממכונה וירטואלית פועלת. ציינו את TRUE רק אם אתם בטוחים שאתם רוצים ליצור את קובץ האימג' ממכונה וירטואלית פועלת. הגדרת ברירת המחדל של forceCreate היא FALSE.

יצירת תמונה מתמונה אחרת:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
  "name": "IMAGE_NAME",
  "sourceImage": "/global/images/SOURCE_IMAGE",
  ("storageLocations": "LOCATION")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: הפרויקט שהתמונה שייכת אליו.
  • ‫IMAGE_NAME: השם של התמונה החדשה שרוצים ליצור.
  • ‫SOURCE_IMAGE: התמונה שממנה רוצים ליצור את התמונה.
  • ‫LOCATION: אופציונלי: מיקום האחסון של התמונה. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו, Compute Engine ישמור את קובץ האימג' במספר אזורים שקרובים למיקום המקור של קובץ האימג'.

יצירת קובץ אימג' מ-snapshot:

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images
{
  "name": "IMAGE_NAME",
  "sourceSnapshot": "(/SOURCE_PROJECT_ID)/global/snapshots/SOURCE_SNAPSHOT",
  ("storageLocations": "LOCATION")
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: הפרויקט שאליו שייכת התמונה.
  • ‫IMAGE_NAME: השם של קובץ האימג' החדש שרוצים ליצור.
  • ‫SOURCE_PROJECT_ID: אופציונלי: הפרויקט שבו נמצאת קבוצת הנתונים. צריכה להיות לכם הרשאת גישה למשאב של קובץ ה-snapshot בפרויקט הזה.
  • ‫SOURCE_SNAPSHOT: קובץ ה-snapshot שממנו רוצים ליצור את קובץ האימג'.
  • ‫LOCATION: אופציונלי, מיקום האחסון של התמונה. לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine ישמור את קובץ האימג' במספר האזורים שהכי קרוב למיקום המקור של קובץ האימג'.

למידע נוסף על הוספת תמונות, ראו חומר עזר בנושא תמונות.

שיתוף התמונה

אחרי שיוצרים קובץ אימג' בהתאמה אישית, אפשר לשתף אותו בין פרויקטים. אם אתם מאפשרים למשתמשים מפרויקט אחר להשתמש בתמונות בהתאמה אישית שלכם, הם יכולים לגשת לתמונות האלה על ידי ציון פרויקט התמונה בבקשה שלהם.

הפעלת תכונות של מערכת הפעלה אורחת בקובצי אימג' של דיסק אתחול

אתם יכולים להשתמש בתכונות של מערכת ההפעלה (OS) של האורח כדי להגדיר את האפשרויות הבאות של רשת, אבטחה, אחסון ומערכת הפעלה בתמונות בהתאמה אישית. תמונות בהתאמה אישית עם התכונות האלה משמשות כדיסקים לאתחול.

אם אתם יוצרים קובץ אימג' בהתאמה אישית למכונות Bare Metal, כדאי לקרוא גם את המאמר שימוש ב-IDPF כדי לקבל מידע על שלבי הגדרה נוספים.

gcloud

משתמשים בפקודה gcloud compute images create עם הדגל --guest-os-features כדי ליצור קובץ אימג' חדש בהתאמה אישית מקובץ אימג' קיים בהתאמה אישית.

gcloud compute images create IMAGE_NAME \
    --source-image=SOURCE_IMAGE \
    [--source-image-project=IMAGE_PROJECT] \
    --guest-os-features="FEATURES,..." \
    [--storage-location=LOCATION]

מחליפים את מה שכתוב בשדות הבאים:

  • ‫IMAGE_NAME: השם של קובץ האימג' החדש
  • ‫SOURCE_IMAGE: תמונה שעליה תתבסס התמונה החדשה
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שמכיל את קובץ האימג' של המקור

    השתמשו בפרמטר הזה כדי להעתיק תמונה מפרויקט אחר.

  • ‫FEATURES: תגים של מערכת ההפעלה של האורח להפעלת תכונות למכונות וירטואליות שנוצרות מתמונות

    כדי להוסיף כמה ערכים, צריך להפריד ביניהם באמצעות פסיקים. מגדירים אחד או יותר מהערכים הבאים:

    • VIRTIO_SCSI_MULTIQUEUE. אפשר להשתמש בממשק הזה במכשירי SSD מקומיים כחלופה ל-NVMe. למידע נוסף על קובצי אימג' שתומכים ב-SCSI, קראו את המאמר בחירת ממשק.

      בתמונות של Linux, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם גרסאות ליבה 3.17 ואילך. בתמונות של Windows, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם מנהל ההתקן של Compute Engine Windows בגרסה 1.2.

    • WINDOWS. תייגו קובצי אימג' לאתחול בהתאמה אישית של Windows Server כקובצי אימג' של Windows.
    • MULTI_IP_SUBNET. מגדירים ממשקים עם מסכת רשת שאינה /32. מידע נוסף על הגדרת מסכות רשת זמין במאמר מסכות רשת של מכונות Compute.
    • UEFI_COMPATIBLE. הפעלה באמצעות קושחת UEFI והתכונות הבאות של מכונה וירטואלית מוגנת:
    • GVNIC. תמיכה ברוחבי פס גבוהים יותר של הרשת, במהירויות של ‎50 Gbps עד ‎100 Gbps. מידע נוסף זמין במאמר שימוש ב-Google Virtual NIC.
    • IDPF. תמיכה בממשקי רשת של Intel Infrastructure Data Path Function ‏(IDPF).
    • SEV_CAPABLE או SEV_SNP_CAPABLE. השתמשו בתגים האלה אם אתם רוצים להשתמש בתמונה במכונה של Confidential VM עם תמיכה ב-AMD Secure Encrypted Virtualization ‏(SEV) או ב-AMD Secure Encrypted Virtualization-Secure Nested Paging ‏(SEV-SNP). כדי לבדוק אם הליבה תומכת ב-AMD SEV או ב-AMD SEV-SNP, קראו את פרטי הליבה של Linux.
    • SEV_LIVE_MIGRATABLE_V2. משתמשים בתג הזה אם רוצים להשתמש בתמונה במכונה של Confidential VM שתומכת במיגרציה פעילה ב-AMD SEV. כדי לבדוק אם הליבה תומכת במיגרציה פעילה, קראו את פרטי ליבת Linux.
    • TDX_CAPABLE. משתמשים בתג הזה אם רוצים להשתמש בתמונה במכונה של Confidential VM עם תמיכה ב-Intel Trust Domain Extensions ‏(TDX). כדי לבדוק אם הליבה שלך תומכת ב-Intel TDX, עיין בפרטי ליבת לינוקס.
  • ‫LOCATION: אופציונלי: האזור או מספר האזורים שבהם התמונה תאוחסן

    לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר האזורים us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine מאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

REST

משתמשים בשיטה images().insert עם הדגל guestOsFeatures כדי ליצור תמונה חדשה בהתאמה אישית מתמונה קיימת בהתאמה אישית.


POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images

{
 "name": "IMAGE_NAME",
 "sourceImage": "(projects/IMAGE_PROJECT)/global/images/SOURCE_IMAGE",
 ("storageLocations": "LOCATION",)
 "guestOsFeatures": [
  {
   "type": "FEATURES"
  }
 ]
}

מחליפים את מה שכתוב בשדות הבאים:

  • ‫PROJECT_ID: מזהה הפרויקט שבו רוצים ליצור את קובץ האימג' החדש
  • ‫IMAGE_NAME: שם לתמונה החדשה
  • ‫IMAGE_PROJECT: אופציונלי: הפרויקט שמכיל את קובץ האימג' של המקור

    השתמשו בפרמטר הזה כדי להעתיק תמונה מפרויקט אחר.

  • ‫SOURCE_IMAGE: התמונה שעליה תתבסס התמונה החדשה

  • ‫LOCATION: אופציונלי: אזור או מספר אזורים שבהם התמונה תאוחסן

    לדוגמה, מציינים את us כדי לאחסן את קובץ האימג' במספר אזורים ב-us, או את us-central1 כדי לאחסן אותו באזור us-central1. אם לא תבחרו מיקום, Compute Engine יאחסן את קובץ האימג' במספר אזורים שהכי קרוב למיקום המקור של קובץ האימג'.

  • ‫FEATURES: תגים של מערכת ההפעלה של האורח להפעלת תכונות למכונות וירטואליות שנוצרות מתמונות

    כדי להוסיף כמה ערכים, צריך להפריד ביניהם באמצעות פסיקים. מגדירים אחד או יותר מהערכים הבאים:

    • VIRTIO_SCSI_MULTIQUEUE. אפשר להשתמש בממשק הזה במכשירי SSD מקומיים כחלופה ל-NVMe. למידע נוסף על קובצי אימג' שתומכים ב-SCSI, קראו את המאמר בחירת ממשק.

      בתמונות של Linux, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם גרסאות ליבה 3.17 ואילך. בתמונות של Windows, אפשר להפעיל SCSI עם כמה תורים במכשירי SSD מקומיים בתמונות עם מנהל ההתקן של Compute Engine Windows בגרסה 1.2.

    • WINDOWS. תייגו קובצי אימג' לאתחול בהתאמה אישית של Windows Server כקובצי אימג' של Windows.
    • MULTI_IP_SUBNET. מגדירים ממשקים עם מסכת רשת שאינה /32. מידע נוסף על הגדרת מסכות רשת זמין במאמר מסכות רשת של מכונות Compute.
    • UEFI_COMPATIBLE. הפעלה באמצעות קושחת UEFI והתכונות הבאות של מכונה וירטואלית מוגנת:
    • GVNIC. תמיכה ברוחבי פס גבוהים יותר של הרשת, במהירויות של ‎50 Gbps עד ‎100 Gbps. מידע נוסף זמין במאמר שימוש ב-Google Virtual NIC.
    • IDPF. תמיכה בממשקי רשת של Intel Infrastructure Data Path Function ‏(IDPF).
    • SEV_CAPABLE או SEV_SNP_CAPABLE. השתמשו בתגים האלה אם אתם רוצים להשתמש בתמונה במכונה של Confidential VM עם תמיכה ב-AMD Secure Encrypted Virtualization ‏(SEV) או ב-AMD Secure Encrypted Virtualization-Secure Nested Paging ‏(SEV-SNP). כדי לבדוק אם הליבה תומכת ב-AMD SEV או ב-AMD SEV-SNP, קראו את פרטי הליבה של Linux.
    • SEV_LIVE_MIGRATABLE_V2. משתמשים בתג הזה אם רוצים להשתמש בתמונה במכונה של Confidential VM שתומכת במיגרציה פעילה ב-AMD SEV. כדי לבדוק אם הליבה תומכת במיגרציה פעילה, קראו את פרטי ליבת Linux.
    • TDX_CAPABLE. משתמשים בתג הזה אם רוצים להשתמש בתמונה במכונה של Confidential VM עם תמיכה ב-Intel Trust Domain Extensions ‏(TDX). כדי לבדוק אם הליבה שלך תומכת ב-Intel TDX, עיין בפרטי ליבת לינוקס.

הימנעו ממידע רגיש במשתני UEFI

משתני Unified Extensible Firmware Interface‏ (UEFI) הם משתנים של צמדי מפתח/ערך שמשמשים את קושחת ה-UEFI בזמן האתחול כדי להפעיל את מערכת ההפעלה של ה-VM. בניגוד למכונות פיזיות, שבהן המשתנים מאוחסנים בשבב חומרה, ב-Compute Engine האחסון של המשתנים האלה הוא וירטואלי. לכן, במערכות הפעלה רבות, כל האפליקציות והמשתמשים יכולים להגיע למשתנים האלה ולגשת למידע הזה.

לכן, Google ממליצה מאוד לא לכתוב או לאחסן מידע רגיש או פרטים אישיים מזהים, כמו סיסמאות או מפתחות פרטיים, במשתני UEFI.

שיקולים לגבי קובצי אימג' של Arm

‫Google מציעה את סדרות המכונות A4X,‏ C4A ו-Tau T2A, שפועלות בפלטפורמות של מעבדי Arm. אתם יכולים להפעיל VM עם אחת מסדרות המכונות האלה, ואז להשתמש ב-VM המקור הזה כדי ליצור קובץ אימג' של Arm. תהליך היצירה של קובץ אימג' בהתאמה אישית של Arm זהה לתהליך היצירה של קובץ אימג' של x86.

כדי לעזור למשתמשים להבדיל בין קובצי אימג' של Arm ו-x86, בקובצי אימג' של Arm השדה architecture יוגדר כ-ARM64. הערכים האפשריים בשדה הזה הם:

  • ARCHITECTURE_UNSPECIFIED
  • X86_64
  • ARM64

משתמשי התמונות יכולים לסנן את השדה הזה כדי למצוא תמונות שמבוססות על x86 או על Arm.

המאמרים הבאים