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, and 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 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 flag.

    1. See the description of the CLI's create VM command:

      $ yc compute instance create --help
      
    2. Get a list of disks in the default folder:

      $ yc compute disk list
      +----------------------+-------------+-------------+---------------+--------+------------------------+
      |          ID          |     NAME    |    SIZE     |     ZONE      | STATUS |      DESCRIPTION       |
      +----------------------+-------------+-------------+---------------+--------+------------------------+
      | fhm4aq4hvq5g3nepvt9b | first-disk  | 10737418240 | ru-central1-a | READY  | my first disk via CLI  |
      | fhmo6rdqg5folrc3lsaf | second-disk | 8589934592  | ru-central1-a | READY  | my second disk via CLI |
      +----------------------+-------------+-------------+---------------+--------+------------------------+
      
    3. Select the ID or NAME of the necessary disks.

    4. 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 the ru-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