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
Prepare the instance
-
Log in to the instance and clear its machine-id, so every instance launched from the image generates its own:
terminal sudo truncate -s 0 /etc/machine-id sudo 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 origin compute get-instance --instance-urn <instance-urn> -
Create a snapshot of that volume:
terminal origin storage create-snapshot --volume-urn <volume-urn> -
Run
get-snapshotuntilstatusreadsCOMPLETED. Note itsvolumeSizeInGib:terminal origin storage get-snapshot --snapshot-urn <snapshot-urn> -
Protect the snapshot. Only a protected snapshot can back an image:
terminal 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
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.
Then check the result:
-
Verify the image. It reads
status: AVAILABLE:terminal 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.
What keeping an image costs
An image keeps two billed resources alive for as long as you use it:
- The snapshot behind it. Completed snapshots are billed for the size of the volume they were taken from, and the snapshot must stay protected for the image’s whole life. Once you unprotect or delete it, launches from the image are refused, although the image still reads
AVAILABLE. - The source volume. A volume can’t be deleted while any of its snapshots exists, so the root disk you snapshotted stays billed too.
To remove everything, work in this order: delete the image, unprotect and delete the snapshot, then delete the volume. See Pricing for the rates.
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.