# Create and use custom disk images This guide shows you how to create custom disk images, boot disks from them, and manage custom disk images using the evroc CLI and API. ## Prerequisites - Access to an evroc organization and project - evroc CLI installed and configured ## Upload the disk image Create an evroc bucket in the same project as the boot disks that will use it. Upload the disk image as a `.qcow2`, `.vhdx` or `.raw` file to that bucket. See [the storage API guide](/products/storage/object-storage/api.html) for further instructions. ## Grant the image importer read access There is a dedicated, evroc-managed service account for each project to read the disk images. This service account is referenced as `/iam/projects/compute-custom-disk-image-importer/serviceAccounts/`. This service account must be granted the `/iam/roles/storageViewer` role for the disk image files you wish to use. The role can be granted either for specific files, or for the entire bucket. To grant read access to a single disk image, use the object's resource path (i.e. `/storage/projects//regions//buckets//objects//`): ```bash evroc iam rolebinding assign \ --principal "/iam/projects/compute-custom-disk-image-importer/serviceAccounts/" \ --role /iam/roles/storageViewer \ --resource "/storage/projects//regions//buckets/my-bucket/objects/images/mydiskimage.qcow2" ``` To grant read access to all objects in the bucket, use the bucket's resource path: ```bash evroc iam rolebinding assign \ --principal "/iam/projects/compute-custom-disk-image-importer/serviceAccounts/" \ --role /iam/roles/storageViewer \ --resource "/storage/projects//regions//buckets/my-bucket" ``` ## Create a custom disk image Create a custom disk image that references the uploaded file. ### Create a custom disk image using the CLI ```bash evroc compute customdiskimage create mydiskimage \ --bucket=my-bucket \ --path=images/mydiskimage.qcow2 \ --architecture=amd64 \ --size-amount=20 \ --size-unit=GB ``` ### Create a custom disk image using the API ```bash curl -X POST https://api.evroc.com/compute/v1beta2/projects/{projectID}/regions/{regionName}/customDiskImages \ -H "Content-Type: application/json" \ -d '{ "apiVersion": "compute/v1beta2", "kind": "CustomDiskImage", "metadata": { "id": "mydiskimage" }, "spec": { "architecture": "amd64", "defaultDiskSize": { "amount": 20, "unit": "GB" }, "source": { "bucketRef": "/storage/projects/{projectID}/regions/{regionName}/buckets/my-bucket", "path": "images/mydiskimage.qcow2" } } }' ``` See [Create a Custom Disk Image](/apis/compute.html#tag/custom-disk-images/POST/compute/v1beta2/projects/{projectID}/regions/{regionName}/customDiskImages) in the API reference. ## List custom disk images List all custom disk images in your project: ```bash evroc compute customdiskimage list ``` Use `evroc compute customdiskimage get ` for detailed information. See [List Custom Disk Images](/apis/compute.html#tag/custom-disk-images/GET/compute/v1beta2/projects/{projectID}/regions/{regionName}/customDiskImages) in the API reference. ## Create a disk from a custom disk image You can create a boot disk from a custom disk image. ### Create a boot disk from a custom disk image using the CLI ```bash evroc compute disk create mynewdisk \ --custom-image=mydiskimage \ --zone=a ``` If you don't specify a disk size, it defaults to the custom disk image's `defaultDiskSize`. ### Create a boot disk from a custom disk image using the API ```bash curl -X POST https://api.evroc.com/compute/v1beta2/projects/{projectID}/regions/{regionName}/disks \ -H "Content-Type: application/json" \ -d '{ "apiVersion": "compute/v1beta2", "kind": "Disk", "metadata": { "id": "mynewdisk" }, "spec": { "source": { "type": "image", "diskImageRef": "/compute/projects/{projectID}/regions/{regionName}/customDiskImages/mydiskimage" }, "placement": { "zone": "a" } } }' ``` See [Create a Disk](/apis/compute.html#tag/disks/POST/compute/v1beta2/projects/{projectID}/regions/{regionName}/disks) in the API reference. ## Delete a custom disk image Delete a custom disk image you no longer need: ```bash evroc compute customdiskimage delete mydiskimage ``` See [Delete a Custom Disk Image](/apis/compute.html#tag/custom-disk-images/DELETE/compute/v1beta2/projects/{projectID}/regions/{regionName}/customDiskImages/{customDiskImageID}) in the API reference. ## Debugging If a VM cannot be started from a custom disk image, check the [console logs](/products/compute/guides/vm-console-logs.html).