Create a VM with disks restored from snapshots

    You can create a VM with disks restored from the snapshots that exist in the folder. Learn about creating a disk snapshot in Creating a disk snapshot.

    To create a VM:

    1. In the management console, select a folder to create a VM in.
    2. In the list of services, select Compute Cloud.
    3. Click Create VM.
    4. Under Basic parameters:
      • Enter a name and description for the VM. Naming requirements:

        • 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.

        Note

        The VM name is used one time only when creating a VM, to generate the FQDN. If the FQDN is important to you, choose an appropriate name for the virtual machine at the creation stage. For more information about generating the FQDN, see Hostname and FQDN.

      • (optional) Select or create a service account. By using a service account, you can flexibly configure access rights for your resources.

      • Select the availability zone to host the VM in.

    5. If you don't have a boot disk or snapshot, select a public image.
    6. To add a disk from a snapshot, click Add disk.
    7. Set the Contents toggle to Snapshot and select a snapshot from the list. Then click Add.
    8. Under Computing resources:
    9. Under Network settings:
      • Specify the subnet ID or select a cloud network from the list.
      • In the Public IP field, choose a method for assigning an IP address:
        • Auto: Assign a random IP address from the Yandex.Cloud IP pool.
        • List: Select a public IP address from the list of previously reserved static addresses. For more information, see Making a dynamic public IP address static.
        • No address: Don't assign a public IP address.
      • (optional) If necessary, enable DDoS protection.
    10. Under Access, specify the data required to access the VM:
      • Enter the username in the Login field.
      • In the SSH key field, paste the contents of the public key file. — (optional) If necessary, enable access to the serial console.
    11. Click Create VM.

    The virtual machine appears in the list. When a VM is being created, it is assigned an IP address and hostname (FQDN).

    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 parameter.

    1. View the description of the CLI command for creating a VM:

      $ yc compute instance create --help
      
    2. Prepare the snapshots of the disks, see Creating a disk snapshot.

    3. Get a list of snapshots in the default folder:

      $ yc compute snapshot list
      +----------------------+-----------------+----------------------+--------+----------------------------+
      |          ID          |       NAME      |     PRODUCT IDS      | STATUS |        DESCRIPTION         |
      +----------------------+-----------------+----------------------+--------+----------------------------+
      | fd8rlt1u2rf0lps3rqm9 | first-snapshot  | f2ecl5vhsftdean0sr6s | READY  | my first snapshot via CLI  |
      | fhmolt1u2rf0lps3lsaf | second-snapshot | f2eclmol5lps3rqmfl5f | READY  | my second snapshot via CLI |
      +----------------------+-----------------+----------------------+--------+----------------------------+
      
    4. Select the identifier (ID) or name (NAME) of the necessary snapshots.

    5. Create a VM in the default folder:

      $ yc compute instance create \
          --name first-instance \
          --zone ru-central1-a \
          --public-ip \
          --create-boot-disk snapshot-name=first-snapshot \
          --create-disk snapshot-name=second-snapshot \
          --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 the disks from the snapshots. 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.

      Note

      The VM name is used one time only when creating a VM, to generate the FQDN. If the FQDN is important to you, choose an appropriate name for the virtual machine at the creation stage. For more information about generating the FQDN, see Hostname and FQDN.

    Use the Create method for the Instance resource.