Create your own image to launch more instances with the same software and configuration as one you’ve already set up. You snapshot the instance’s root disk, protect the snapshot, and create an image from it.
Before you begin
- An instance whose root disk holds what you want in the image.
- The
originCLI, signed in. See CLI access.
Prepare the instance
-
Log in to the instance and clear its machine-id, so every instance launched from the image generates its own:
Terminal window sudo truncate -s 0 /etc/machine-idsudo rm -f /var/lib/dbus/machine-idIf you skip this, every instance from the image shares one machine-id, which breaks VXLAN networking between them. See Guest environment.
-
Stop the instance, so the snapshot captures a cleanly shut-down file system. See Stop and start an instance.
Snapshot the root disk
-
Find the root disk’s volume URN. In
volumeAttachments, it’s the entry withisRootDeviceset totrue:Terminal window origin compute get-instance --instance-urn <instance-urn> -
Create a snapshot of that volume:
Terminal window origin storage create-snapshot --volume-urn <volume-urn> -
Run
get-snapshotuntilstatusreadsCOMPLETED. Note itsvolumeSizeInGib:Terminal window origin storage get-snapshot --snapshot-urn <snapshot-urn> -
Protect the snapshot. Only a protected snapshot can back an image:
Terminal window origin storage protect-snapshot --snapshot-urn <snapshot-urn> -
Run
get-snapshotuntilprotectionStatusreadsPROTECTED.
For more about snapshot states, see Create and protect a snapshot.
Create the image
-
Create the image from the snapshot:
Terminal window origin compute create-image \--project-urn <project-urn> \--root-device-snapshot-urn <snapshot-urn> \--root-device-size <size-gib> \--description "Web server base"- The snapshot must be in the project you create the image in. A snapshot of another project is refused as not found.
--root-device-sizemust be at least the snapshot’svolumeSizeInGib. It defaults to 8 GiB, so set it when the volume was larger. Instances launched from the image get a root disk of at least this size.--default-usersets the account instances log in as. Omitted, it’scloud. See Guest environment.--root-device-namesets the guest device name of the root disk. It defaults tovda. Names run fromvdatovdz, without/dev/, andvdcis reserved. Any other value is refused, naming the field.
-
Verify the image. It reads
status: AVAILABLE:Terminal window origin compute get-image --image-urn <image-urn> -
Launch an instance from it to test it. See Launch an instance.
With the API, createImage takes the root device as one of a list of blockDeviceSpecs, each with a deviceName, snapshotUrn and sizeInGib. rootDeviceName must name one of them.
Update or delete an image
The description is the only field you can change:
origin compute update-image \ --image-urn <image-urn> \ --description "Web server base, hardened"To delete an image:
origin compute delete-image --image-urn <image-urn>Deleting an image doesn’t affect instances already launched from it, because each has its own copy on its root disk. The snapshot behind the image isn’t deleted. Unprotect and delete it separately when you no longer need it. See Delete a snapshot.
You can update and delete only your own images, not platform-provided ones.