Creating an image from a disk
To create an image from a disk:
Note
You can use the management console to create images of network SSDs and HDDs. To create an image of a non-replicated SSD or an ultra high-speed network storage with three replicas (SSD), use the CLI, Terraform, or API.
-
In the management console
, select the folder where you want to create an image. -
Select Compute Cloud.
-
In the left-hand panel, select
Disks. -
In the row with the disk, click
and select Create image. -
Enter the image name. The naming requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
-
If required, provide a text description for the image.
-
To create an optimized image, enable Optimize for deployment.
-
Click Create.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to create an image:
yc compute image create --help
-
Get a list of disks in the default folder:
yc compute disk list
Result:
+----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | PLACEMENT GROUP | DESCRIPTION | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+ | a7lqgbt0bb9s******** | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbh******** | | | | a7lv5j5hm1p1******** | second-disk | 21474836480 | ru-central1-a | READY | | | | +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
-
Select the
ID
orNAME
of the disk you need. -
Create an image in the default folder:
yc compute image create \ --name first-image \ --source-disk-name first-disk \ --description "my first image via yc"
This command will create an image named
first-image
described asmy first image via yc
from thefirst-disk
disk.To create an optimized image, use the
--pooled
flag:yc compute image create \ --name first-image \ --source-disk-name first-disk \ --description "my first image via yc" \ --pooled
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Describe the parameters of the
yandex_compute_image
resource in the configuration file.Here is an example of the configuration file structure:
resource "yandex_compute_image" "image-1" { name = "<image_name>" source_disk = "<disk_ID>" }
For more information about the resources you can create with Terraform, see the provider documentation
. -
Make sure the configuration files are correct.
-
In the command line, go to the folder where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy cloud resources.
-
Run this command:
terraform apply
-
Confirm that you want to create the resources.
All the resources you need will then be created in the specified folder. You can check the new resources and their settings using the management console
. -
- Get the list of disks using the list REST API method for the Disk resource or the DiskService/List gRPC API call.
- Create an image using the create REST API method for the Image resource or the ImageService/Create gRPC API call. Specify the disk ID in your request.
Once created, the image will get the CREATING
status. Wait until its status changes to READY
before using it.