Creating a VM from a set of disks
You can create a VM from existing disks. The disks must reside in one of the availability zones and not be added to other VMs.
When you select a disk to attach to a VM, you can specify whether that disk should be deleted when deleting the VM. You can choose this option when creating a VM, updating it, or attaching a new disk to it.
To create a VM from a set of disks:
If you don't 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's create VM command:
$ yc compute instance create --help
-
Get a list of disks in the default folder:
$ yc compute disk list +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | ID | NAME | SIZE | ZONE | STATUS | INSTANCE IDS | DESCRIPTION | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+ | a7lqgbt0bb9s40tifuhc | first-disk | 20401094656 | ru-central1-a | READY | a7lcvu28njbhnkcteb5n | | | a7lv5j5hm1p1hppprga7 | second-disk | 21474836480 | ru-central1-a | READY | | | +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+
-
Select the
ID
orNAME
of the necessary disks. -
Create a VM in the default folder:
$ yc compute instance create \ --name first-instance \ --zone ru-central1-a \ --public-ip \ --use-boot-disk disk-name=first-disk \ --attach-disk disk-name=second-disk \ --ssh-key ~/.ssh/id_rsa.pub
This command creates a VM named
first-instance
in theru-central1-a
availability zone, with a public IP and two disks. To create a VM without a public IP, remove the--public-ip
flag.- The name must be unique within the folder.
- The name may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter. The last character can't be a hyphen.
- The maximum length of the name is 63 characters.
To specify whether to delete the disk when deleting the VM, set the
--auto-delete
flag:yc compute instance create \ --name first-instance \ --zone ru-central1-a \ --public-ip \ --use-boot-disk disk-name=first-disk,auto-delete=yes \ --attach-disk disk-name=second-disk,auto-delete=yes \ --ssh-key ~/.ssh/id_rsa.pub
Use the Create method for the Instance
resource.