[Yandex Cloud documentation](../../../index.md) > [Yandex Compute Cloud](../../index.md) > [Step-by-step guides](../index.md) > Managing a VM > Moving a VM to a different availability zone

# Moving a VM to a different availability zone

When creating a VM, you can select a Yandex Cloud [availability zone](../../../overview/concepts/geo-scope.md) to place it in.

You can move a VM to a different availability zone by creating its copy in the target availability zone using disk snapshots.

You can also move a VM from the `ru-central1-a` and `ru-central1-b` zones to the `ru-central1-d` zone using a special [CLI](../../../cli/cli-ref/compute/cli-ref/instance/relocate.md) command.


{% note warning %}

To monitor the migration progress and avoid potential issues, use [disk snapshots](../disk-control/create-snapshot.md) or backups from [Cloud Backup](../../../backup/operations/backup-vm/create.md). This way, you can decide when to shut down your VM in the source availability zone and when to make it appear in the target availability zone. You can keep the VM in the source availability zone running until you make sure the VM you created from the snapshot in the new zone works correctly. For detailed recommendations, see [Migrating resources to a different availability zone](../../../overview/concepts/zone-migration.md).

Currently, you can use the `yc compute instance relocate` command to migrate VMs and disks only to the `ru-central1-d` zone from any other zone.

{% endnote %}


{% note warning %}

The `ru-central1-d` zone does not support VMs based on the Intel Broadwell [platform](../../concepts/vm-platforms.md). To move such VMs to the `ru-central1-d` zone, do one of the following:

* Take a disk snapshot and use it to create a new VM in the `ru-central1-d` zone on a different platform.
* Stop the VM, change the platform, and move the VM by running `yc compute instance relocate`.

{% endnote %}

## Moving a VM using disk snapshots {#relocate-snapshots}

To move a VM to a different availability zone using snapshots, create its copy in the target availability zone and delete the source VM.

### Create a snapshot of each of the VM disks {#create-snapshot}

#### Prepare the disks {#prepare-disks}

A disk snapshot only contains the data that was written to the disk at the time its snapshot was created. If the disk is attached to a running VM, the OS and app cache will not be included in the snapshot.

To ensure the snapshot data integrity:

{% list tabs group=operating_system %}

- Linux {#linux}

  1. Stop all disk write operations in applications.

  1. Write the OS cache to the disk:

      ```bash
      sync
      ```

  1. Freeze the file system:

      ```bash
      sudo fsfreeze --freeze <mount_point>
      ```
      Where `--freeze` is the parameter to freeze the file system. Replace `<mount_point>` with the folder where the file system is mounted, e.g., `/mnt/vdc2`.

  1. Create a snapshot by following the steps [below](#create).

  1. Unfreeze the file system:

      ```bash
      sudo fsfreeze --unfreeze <mount_point>
      ```
      Where `--unfreeze` is the parameter to unfreeze the file system. Replace `<mount_point>` with the folder where the file system is mounted, e.g., `/mnt/vdc2`.

- Other operating systems {#other}

  1. Stop the VM (see [Stopping](vm-stop-and-start.md#stop)).
  1. Wait until the VM status changes to `STOPPED`.

{% endlist %}

#### Create snapshots {#create}

To [create](../disk-control/create-snapshot.md) a disk snapshot:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder containing the disk.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/hard-drive.svg) **Disks**.
  1. In the line with the disk, click ![image](../../../_assets/console-icons/ellipsis.svg) and select **Create snapshot**.
  1. Enter a name for the snapshot. The naming requirements are as follows:

      * Length: between 3 and 63 characters.
      * It can only contain lowercase Latin letters, numbers, and hyphens.
      * It must start with a letter and cannot end with a hyphen.

  1. Provide a description for the snapshot, if required.
  1. Click **Create**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI commands for creating snapshots:

      ```bash
      yc compute snapshot create --help
      ```

  1. Select the disk to create a snapshot of. To get a list of disks in the default folder, run this command:

      ```bash
      yc compute disk list
      ```
      
      Result:
      
      ```text
      +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
      |          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  |                      |                 |             |
      +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
      ```

  1. Create a snapshot in the default folder:

      ```bash
      yc compute snapshot create \
        --name first-snapshot \
        --description "my first snapshot via CLI" \
        --disk-id fhm4aq4hvq5g******** \
        --hardware-generation-id <hardware_generation> \
        --hardware-features pci_topology=<PCI_topology>
      ```

      Where:
      * `--name`: Snapshot name. The naming requirements are as follows:

          * Length: between 3 and 63 characters.
          * It can only contain lowercase Latin letters, numbers, and hyphens.
          * It must start with a letter and cannot end with a hyphen.

      * `--description`: Description of the new snapshot. This is an optional setting.
      * `--disk-id`: ID of the disk to create the snapshot for. Instead of the ID, you can provide its name in `--disk-name`.
      * `--hardware-generation-id`: Virtualized hardware [generation](../../concepts/hardware-generations.md#configurations) assigned to the snapshot. This is an optional setting. The possible values are:

          * `legacy`: `Gen 1`. If you select this generation, you can also specify the PCI topology in the `--hardware-features` parameter.
          * `generation2`: `Gen 2`. If you select this generation, you do not need to specify `--hardware-features`.

          If not specified, the snapshot will get the same hardware generation assigned as the source disk.
      * `--hardware-features`: Additional settings for `Gen 1`. This is an optional setting. The possible values are:

          * `pci_topology=v1`: `PCI_TOPOLOGY_V1` topology.
          * `pci_topology=v2`: Adopts the `PCI_TOPOLOGY_V2` topology.

          If the source disk has `Gen 2` assigned, by default, the new snapshot will get `--hardware-features` set to `pci_topology=v1`.

          If the source disk has `Gen 1` assigned, by default, the new snapshot will get the same `--hardware-features` value as the source disk.

      Result:

      ```text
      done (19s)
      id: fd81qi89ldop********
      folder_id: b1gt6g8ht345********
      created_at: "2025-06-23T09:56:04Z"
      name: first-snapshot
      description: my first snapshot via CLI
      storage_size: "3116367872"
      disk_size: "21474836480"
      product_ids:
        - f2evcrm9ti79********
      status: READY
      source_disk_id: epd8lmcncidv********
      hardware_generation:
        legacy_features:
          pci_topology: PCI_TOPOLOGY_V2
      ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  1. Define the parameters of the `yandex_compute_snapshot` resource in the configuration file.

     Here is an example of the configuration file structure:
     
     ```hcl
     resource "yandex_compute_snapshot" "snapshot-1" {
       name           = "disk-snapshot"
       source_disk_id = "<disk_ID>"
       hardware_generation {
         legacy_features {
           pci_topology = "<PCI_topology>"
         }
       }
     }
     ```

      Where:
      * `name`: Snapshot name. The naming requirements are as follows:

          * Length: between 3 and 63 characters.
          * It can only contain lowercase Latin letters, numbers, and hyphens.
          * It must start with a letter and cannot end with a hyphen.

      * `source_disk_id`: ID of the disk to create the snapshot for.
      * `hardware_generation`: Block of settings describing the virtualized hardware [generation](../../concepts/hardware-generations.md#configurations) assigned to the snapshot. This is an optional setting. It includes the following blocks of settings:

          * `legacy_features`: Settings with the description of parameters for `Gen 1`:
          
              * `pci_topology`: Selecting the PCI topology. The possible values are:
          
                  * `PCI_TOPOLOGY_V1`
                  * `PCI_TOPOLOGY_V2`
          
              The `legacy_features` and `generation2_features` sections are mutually exclusive.
          * `generation2_features`: Settings for `Gen 2`. If you select `Gen 2`, you do not need to specify any additional settings.
          
              The `generation2_features` and `legacy_features` sections are mutually exclusive.

          {% note info %}

          If the `hardware_generation` settings are not specified, the snapshot will get the same hardware generation assigned as the source disk.

          {% endnote %}

     For more information about `yandex_compute_snapshot`, see [this provider guide](../../../terraform/resources/compute_snapshot.md).

  1. Make sure the configuration files are correct.

     1. In the terminal, navigate to the directory where you created your configuration file.
     1. Run a check using this command:

        ```bash
        terraform plan
        ```

     If the configuration is correct, the terminal will display a list of the resources and their settings. Otherwise, Terraform will show any detected errors. 

  1. Deploy the cloud resources.

     1. If the configuration is correct, run this command:

        ```bash
        terraform apply
        ```

     1. Confirm creating the resources.

     This will create all the resources you need in the specified folder. You can check the new resources and their settings using the [management console](https://console.yandex.cloud).

- API {#api}

  1. Get a list of disks using the [list](../../api-ref/Disk/list.md) REST API method for the [Disk](../../api-ref/Disk/index.md) resource or the [DiskService/List](../../api-ref/grpc/Disk/list.md) gRPC API call.
  1. Create a snapshot using the [create](../../api-ref/Snapshot/create.md) REST API method for the [Snapshot](../../api-ref/Snapshot/index.md) resource or the [SnapshotService/Create](../../api-ref/grpc/Snapshot/create.md) gRPC API call. In your request, specify the source disk ID, and optionally the desired virtualized hardware [generation](../../concepts/hardware-generations.md#configurations) in the [`hardwareGeneration` object](../../api-ref/Snapshot/create.md#yandex.cloud.compute.v1.HardwareGeneration) ([`hardware_generation`](../../api-ref/grpc/Snapshot/create.md#yandex.cloud.compute.v1.HardwareGeneration) if using the gRPC API).

{% endlist %}

Repeat the steps above to create snapshots of all the disks.

### Create a VM in a different availability zone with the disks from the snapshots {#create-vm}

To [create](../vm-create/create-from-snapshots.md) a VM in a different availability zone with disks from snapshots:

{% list tabs group=instructions %}

- Management console {#console}



  1. In the [management console](https://console.yandex.cloud), select the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) where you want to create your VM.
  1. Navigate to **Compute Cloud**.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/server.svg) **Virtual machines**.
  1. Click **Create virtual machine**.
  1. Under **Boot disk image**:

      * Navigate to the **Custom** tab.
      * Click ![image](../../../_assets/console-icons/pencil.svg), and, in the window that opens, select **Create**.
      * In the **Contents** field, select `Snapshot` and then select the disk snapshot you need from the list below. Optionally, use the filter.
      * Enter a name for the new boot disk.
      * Select the [disk type](../../concepts/disk.md#disks_types).
      * Specify the required disk and block size.
      * Optionally, enable **Additional** in the **Delete along with the virtual machine** field if you need this disk automatically deleted when deleting the VM.
      * Click **Add disk**.

  1. Under **Location**, select an [availability zone](../../../overview/concepts/geo-scope.md) where your VM will reside.
  1. Add a secondary [disk](../../concepts/disk.md):

      * Under **Disks and file storages**, click **Add**.
      * In the window that opens, select **Disk** → `Create new`.
      * In the **Contents** field, select `Snapshot`.
      * Enter a name for the new disk.
      * Select the [disk type](../../concepts/disk.md#disks_types).
      * Specify the required disk and block size.
      * Optionally, enable **Additional** in the **Delete along with the virtual machine** field if you need this disk automatically deleted when deleting the VM.
      * Click **Add disk**.

  1. Optionally, to [encrypt](../../concepts/encryption.md) a boot disk or a secondary disk, under **Disks and file storages**, click ![image](../../../_assets/console-icons/pencil.svg) to the right of the disk name and configure encryption parameters for the disk:
     
     * Select **Encrypted disk**.
     * In the **KMS key** field, select the [key](../../../kms/concepts/key.md) you want to use to encrypt the disk. To [create](../../../kms/operations/key.md#create) a new key, click **Create**.
     
     To create an encrypted disk, you need the `kms.keys.user` [role](../../../kms/security/index.md#kms-keys-user) or higher.
     
     {% note warning %}
     
     You can specify encryption settings only when creating a disk. You cannot disable or change disk encryption. You also cannot enable encryption for an existing disk.
     
     {% endnote %}
     
     If you deactivate the key used to encrypt a disk, image, or snapshot, access to the data will be suspended until you reactivate the key.
     
     {% note alert %}
     
     If you destroy the key or its [version](../../../kms/concepts/version.md) used to encrypt a disk, image, or snapshot, you will irrevocably lose access to the data. For details, see [Destroying key version](../../../kms/concepts/version.md#version-distruct).
     
     {% endnote %}
  1. Optionally, connect a [file storage](../../concepts/filesystem.md):
     
     * Under **Disks and file storages**, click **Add**.
     
         * In the window that opens, select **File storage** and choose the storage you want to connect from the list.
     
         * Click **Add file storage**.
  1. Under **Computing resources**, select one of the preset configurations or create a custom one. To create a custom configuration:
     
     * Go to the **Custom** tab.
     * Select a [platform](../../concepts/vm-platforms.md).
     * Specify the [guaranteed performance](../../concepts/performance-levels.md) and required number of vCPUs, as well as RAM size.
     * Enable a [software-accelerated network](../../concepts/software-accelerated-network.md) if needed.
     * Make your VM [preemptible](../../concepts/preemptible-vm.md), if required.
  1. Under **Network settings**:
     
     * In the **Subnet** field, enter the ID of a subnet in the new VM’s availability zone. Alternatively, select a [cloud network](../../../vpc/concepts/network.md#network) from the list.
     
         * Each network must have at least one [subnet](../../../vpc/concepts/network.md#subnet). If your network has no subnets, create one by selecting **Create subnet**.
         * If there are no networks in the list, click **Create network** to create one:
     
             * In the window that opens, specify the network name and select the folder where it will be created.
             * Optionally, enable the **Create subnets** setting to automatically create subnets in all availability zones.
             * Click **Create network**.
     
     * In the **Public IP address** field, select the IP address assignment method:
     
         * `Auto`: To assign a random IP address from the Yandex Cloud IP address pool. In this case, you can enable [DDoS protection](../../../vpc/ddos-protection/index.md) using the option below.
         * `List`: To select a public IP address from the list of previously reserved static addresses. For more information, see [Converting a dynamic public IP address to static](../../../vpc/operations/set-static-ip.md).
         * `No address`: Do not assign a public IP address.
     
     * Select [relevant security groups](../../../vpc/concepts/security-groups.md):
     
         * To connect to a virtual machine over `SSH`, the security group must allow incoming network traffic over `TCP` and `UDP` on port `22`.
     
         * To connect to a virtual machine over `RDP`, the security group must allow incoming network traffic over `TCP` and `UDP` on port `3389`.
         
         If you leave the field empty, the virtual machine will be automatically assigned the [default security group](../../../vpc/concepts/security-groups.md#default-security-group) allowing connections to the VM over `SSH` and `RDP`.
     
     * Expand **Additional** and select a method for assigning internal addresses in the **Internal IPv4 address** field:
     
         * `Auto`: To assign a random IP address from the pool of IP addresses available in the selected subnet.
         * `Manual`: To manually assign a private IP address to the VM.
         * Enable **DDoS protection**, if required. The option is available if you previously selected the automatic IP assignment method in the public address settings.
     
     * Optionally, create records for your VM in the [DNS zone](../../../dns/concepts/dns-zone.md):
     
         * Expand **DNS settings for internal addresses** and click **Add record**.
         * Specify a zone, FQDN, and TTL for the record. When setting the FQDN, you can enable `Detect automatically` for the zone.
           You can add multiple records to [internal DNS zones](../../../dns/concepts/dns-zone.md). For more information, see [Yandex Cloud DNS integration with Yandex Compute Cloud](../../../dns/concepts/compute-integration.md).
         * To create another record, click **Add record**.
     
     If you want to add another [network interface](../../concepts/network.md) to your VM, click **Add network interface** and repeat the settings from this step for the new interface. You can add up to eight network interfaces to a single VM.
  1. Under **Access**:
     
     * Select **Access by OS Login** to [connect](../vm-connect/os-login.md) and manage access to the new VM using [OS Login](../../../organization/concepts/os-login.md) in Yandex Identity Hub.
     
         With OS Login, you can connect to VMs using SSH keys and SSH certificates via a standard SSH client or the [Yandex Cloud CLI](../../../cli/quickstart.md). OS Login enables rotating the SSH keys used to access VMs, providing the most [secure](../../../security/domains/iaas-checklist.md#vm-security) access option.
     
     * If you prefer not to use OS Login, select **SSH key** and specify the following VM access data:
     
         * In the **Login** field, enter the username.
     
             {% note alert %}
     
             Do not use `root` or other [OS-reserved usernames](https://github.com/canonical/subiquity/blob/main/reserved-usernames). To perform operations requiring root privileges, use the `sudo` command.
     
             {% endnote %}
     
         * In the **SSH key** field, select the SSH key saved in your [organization user](../../../organization/concepts/membership.md) profile.
           
           If there are no SSH keys in your profile or you want to add a new key:
           
           1. Click **Add key**.
           1. Enter a name for the SSH key.
           1. Select one of the following:
           
               * `Enter manually`: Paste the contents of the public SSH key. You need to [create](../vm-connect/ssh.md#creating-ssh-keys) an SSH key pair on your own.
               * `Load from file`: Upload the public part of the SSH key. You need to create an SSH key pair on your own.
               * `Generate key`: Automatically create an SSH key pair.
               
                 When adding a new SSH key, an archive containing the key pair will be created and downloaded. In Linux or macOS-based operating systems, unpack the archive to the `/home/<user_name>/.ssh` directory. In Windows, unpack the archive to the `C:\Users\<user_name>/.ssh` directory. You do not need additionally enter the public key in the management console.
           
           1. Click **Add**.
           
           The system will add the SSH key to your organization user profile. If the organization has [disabled](../../../organization/operations/os-login-access.md) the ability for users to add SSH keys to their profiles, the added public SSH key will only be saved in the user profile inside the newly created resource.
     
     If you want to add multiple users with SSH keys to the VM at the same time, [specify](../../concepts/metadata/sending-metadata.md) these users' data under **Metadata**. You can also use metadata to [install additional software](../vm-create/create-with-cloud-init-scripts.md) on a VM when creating it.
     
     In public Linux images provided by Yandex Cloud, the functionality of connecting over SSH using login and password is disabled by default.
  1. Optionally, enable the **Backup** option and, in the **Backup policies** field, select or create a [backup policy](../../../backup/concepts/policy.md) to back up your VMs automatically using [Cloud Backup](../../../backup/index.md).
     
     To create a new VM with a Cloud Backup connection, your account must have the `backup.user` [role](../../../backup/security/index.md#backup-user) or higher for the [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) you are creating the VM in.
     
     {% note info %}
     
     If your account does not have the `backup.user` role or higher, you can connect the VM to Cloud Backup using a [service account](../../../iam/concepts/users/service-accounts.md) which has that role. 
     
     To do this, expand the **Additional** section and select the service account under **Service account**. If required, [create](../../../iam/operations/sa/create.md) a new service account and [assign](../../../iam/operations/sa/assign-role-for-sa.md) it the `backup.user` [role](../../../backup/security/index.md#backup-user).
     
     {% endnote %}
     
     {% note tip %}
     
     Installing a Cloud Backup agent is a resource-intensive operation. If you want to use a VM in the minimum possible configuration or, for example, a VM with a [vCPU performance level](../../concepts/performance-levels.md) below 100%, we recommend increasing the VM's resources during the Cloud Backup agent installation.
     
     {% endnote %}
     
     For more information, see [Connecting Compute Cloud VMs and Yandex BareMetal servers to Cloud Backup](../../../backup/concepts/vm-connection.md). 
  1. Under **General information**, enter a name for the VM:

      * Length: between 3 and 63 characters.
      * It can only contain lowercase Latin letters, numbers, and hyphens.
      * It must start with a letter and cannot end with a hyphen.

      {% note info %}
      
      The VM name is used to generate an [internal FQDN](../../concepts/network.md#hostname), which is set only once, when you create the VM. If the internal FQDN is important to you, make sure to choose an appropriate name for your VM.
      
      {% endnote %}

  1. Under **Additional**:
     
     * Optionally, select or create a [service account](../../../iam/concepts/users/service-accounts.md). With a service account, you can flexibly configure access permissions for your resources.
     * Optionally, enable access to the [serial console](../../concepts/serial-console.md).
     * Optionally, to configure delivering [Linux metrics](../../../monitoring/operations/unified-agent/linux_metrics.md) and any additional metrics from your apps, enable **Monitoring** under **Agent for delivering metrics** and select:
       * **Yandex Monitoring**: [Install an agent](../../../monitoring/concepts/data-collection/unified-agent/index.md) to collect additional metrics from VM instances and apps.
       * **Yandex Managed Service for Prometheus®**: [Install and configure an agent](../../../monitoring/operations/prometheus/ingestion/prometheus-agent.md) to collect additional metrics from VM instances and apps in Prometheus format:
          * Select or create a workspace to store your metrics.
          * Optionally, describe the [delivery parameters](../../../monitoring/operations/prometheus/ingestion/prometheus-agent.md) for your custom metrics, in JSON format.
     * Optionally, under **Placement**, select a VM [placement group](../../concepts/placement-groups.md).
  1. Click **Create VM**.

  The VM will appear in the list. Every new VM gets an [IP address](../../../vpc/concepts/address.md) and [host name](../../../vpc/concepts/address.md#fqdn) (FQDN).

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

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

      ```
      yc compute instance create --help
      ```

  1. Prepare snapshots of the disks you need by following the steps in [Creating a disk snapshot](../disk-control/create-snapshot.md).
  1. Get a list of snapshots in the default folder:

      ```bash
      yc compute snapshot list
      ```
      
      Result:
      
      ```text
      +----------------------+-----------------+----------------------+--------+----------------------------+
      |          ID          |       NAME      |     PRODUCT IDS      | STATUS |        DESCRIPTION         |
      +----------------------+-----------------+----------------------+--------+----------------------------+
      | fd8rlt1u2rf0l******* | first-snapshot  | f2ecl5vhsftd******** | READY  | my first snapshot via CLI  |
      | fhmolt1u2rf0******** | second-snapshot | f2eclmol5lps******** | READY  | my second snapshot via CLI |
      +----------------------+-----------------+----------------------+--------+----------------------------+
      ```

  1. Select `ID` or `NAME` of the snapshots you need.
  1. 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,kms-key-id=<key_ID> \
        --create-disk snapshot-name=second-snapshot,kms-key-id=<key_ID> \
        --ssh-key ~/.ssh/id_ed25519.pub
      ```

      Where:

      * `--name`: VM name. The naming requirements are as follows:

          * Length: between 3 and 63 characters.
          * It can only contain lowercase Latin letters, numbers, and hyphens.
          * It must start with a letter and cannot end with a hyphen.

          {% note info %}
          
          The VM name is used to generate an [internal FQDN](../../concepts/network.md#hostname), which is set only once, when you create the VM. If the internal FQDN is important to you, make sure to choose an appropriate name for your VM.
          
          {% endnote %}

      * `--zone`: [Availability zone](../../../overview/concepts/geo-scope.md).
      * `--public-ip`: Connecting a public IP address. Remove this flag to create a VM without a public IP address.
      * `--create-boot-disk`: VM boot disk settings:

          * `snapshot-name`: Disk snapshot name.
          * `kms-key-id`: ID of the [KMS symmetric key](../../../kms/concepts/key.md) to create an encrypted boot disk. This is an optional setting.

            To create an encrypted disk, you need the `kms.keys.user` [role](../../../kms/security/index.md#kms-keys-user) or higher.

            {% note warning %}
            
            You can specify encryption settings only when creating a disk. You cannot disable or change disk encryption. You also cannot enable encryption for an existing disk.
            
            {% endnote %}

            If you deactivate the key used to encrypt a disk, image, or snapshot, access to the data will be suspended until you reactivate the key.
            
            {% note alert %}
            
            If you destroy the key or its [version](../../../kms/concepts/version.md) used to encrypt a disk, image, or snapshot, you will irrevocably lose access to the data. For details, see [Destroying key version](../../../kms/concepts/version.md#version-distruct).
            
            {% endnote %}

      * `--create-disk`: Secondary disk settings:

          * `snapshot-name`: Disk snapshot name.
          * `kms-key-id`: ID of the [KMS symmetric key](../../../kms/concepts/key.md) to create an encrypted disk. This is an optional setting.

      * `--ssh-key`: Path to the file with the [public SSH key](../vm-connect/ssh.md#creating-ssh-keys). The VM will automatically create a user named `yc-user` for this key.

          When creating a VM from a [Yandex Cloud Marketplace](https://yandex.cloud/en/marketplace) public image, make sure to provide an SSH key, as SSH access with a username and password is disabled by default for such images.

      The above command will create a VM named `first-instance` in the `ru-central1-a` availability zone, with a public IP address and disks from the snapshots.

      If you want to add multiple [network interfaces](../../concepts/network.md) to your VM, specify the `--network-interface` parameter as many times as you need. You can add up to eight network interfaces to a single VM.

- API {#api}

  Use the [create](../../api-ref/Instance/create.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Create](../../api-ref/grpc/Instance/create.md) gRPC API call.

{% endlist %}

### Delete the source VM {#delete-vm}

To [delete](vm-delete.md) a source VM:

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select the folder this VM belongs to.
  1. Navigate to **Compute Cloud**.
  1. Next to the VM you want to delete, click ![image](../../../_assets/console-icons/ellipsis.svg) → **Delete**.

     To delete multiple VMs, select them from the list and click **Delete** at the bottom of the screen.

  1. In the window that opens, click **Delete**.

- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for deleting a VM:

     ```bash
     yc compute instance delete --help
     ```

  1. Get a list of VMs in the default folder:

     ```bash
     yc compute instance list
     ```
     
     Result:
     ```text
     +----------------------+-----------------+---------------+---------+----------------------+
     |          ID          |       NAME      |    ZONE ID    | STATUS  |     DESCRIPTION      |
     +----------------------+-----------------+---------------+---------+----------------------+
     | fhm0b28lgfp4******** | first-instance  | ru-central1-a | RUNNING | my first vm via CLI  |
     | fhm9gk85nj7g******** | second-instance | ru-central1-a | RUNNING | my second vm via CLI |
     +----------------------+-----------------+---------------+---------+----------------------+
     ```

  1. Select the `ID` or `NAME` of the VM, e.g., `first-instance`.
  1. Delete the VM:

     ```bash
     yc compute instance delete first-instance
     ```

- Terraform {#tf}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.

  To delete a VM created using Terraform, follow these steps:
  1. In the command line, navigate to the directory with the Terraform configuration file.
  1. Delete the resources using this command:

     ```bash
     terraform destroy
     ```

     {% note alert %}

     Terraform will delete all the resources you created in the current configuration, such as clusters, networks, subnets, and VMs.

     {% endnote %}

  1. Type `yes` and press **Enter**.

- API {#api}

  Use the [delete](../../api-ref/Instance/delete.md) REST API method for the [Instance](../../api-ref/Instance/index.md) resource or the [InstanceService/Delete](../../api-ref/grpc/Instance/delete.md) gRPC API call.

{% endlist %}

## Moving a VM instance to the ru-central1-d zone using a special command {#relocate-command}

The special CLI command can be used to move a VM instance only to the `ru-central1-d` availability zone. The instance moved this way preserves its ID and metadata. All disks attached to the VM will also be transferred to the new availability zone.

{% note info %}

The time it takes to move a VM to a different availability zone depends on the size of its disks. A 100 GB disk typically takes more than 10 minutes to move.

{% endnote %}

{% list tabs group=instructions %}


- CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for moving a VM to a different availability zone:

      ```bash
      yc compute instance relocate --help
      ```

  1. Get a list of all subnets in the default folder:

      ```bash
      yc vpc subnet list
      ```

      Result:

      ```text
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      |          ID          |         NAME          |      NETWORK ID      | ROUTE TABLE ID |     ZONE      |      RANGE      |
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      | e2l5iit0t6dr******** | default-ru-central1-b | enpnohfm8jb5******** |                | ru-central1-b | [10.129.0.0/24] |
      | e9b2ljn7h9pj******** | default-ru-central1-a | enpnohfm8jb5******** |                | ru-central1-a | [10.128.0.0/24] |
      | fl8in4sila9i******** | default-ru-central1-d | enpnohfm8jb5******** |                | ru-central1-d | [10.130.0.0/24] |
      +----------------------+-----------------------+----------------------+----------------+---------------+-----------------+
      ```

  1. Get a list of all security groups in the default folder:

      ```bash
      yc vpc sg list
      ```

      Result:

      ```text
      +----------------------+---------------------------------+--------------------------------+----------------------+
      |          ID          |              NAME               |          DESCRIPTION           |      NETWORK-ID      |
      +----------------------+---------------------------------+--------------------------------+----------------------+
      | enpagmu40nj5******** | my-sg-group                     |                                | enpnohfm8jb5******** |
      | enpe9n88cell******** | default-sg-enpnohfm8jb5******** | Default security group for     | enpnohfm8jb5******** |
      |                      |                                 | network                        |                      |
      +----------------------+---------------------------------+--------------------------------+----------------------+
      ```

  1. Get a list of all VMs in the default folder:

      ```bash
      yc compute instance list
      ```

      Result:

      ```text
      +----------------------+---------+---------------+---------+--------------+-------------+
      |          ID          |  NAME   |    ZONE ID    | STATUS  | EXTERNAL IP  | INTERNAL IP |
      +----------------------+---------+---------------+---------+--------------+-------------+
      | epdi9vnr8i6n******** | my-vm-1 | ru-central1-b | RUNNING | 84.201.166.2 | 10.129.0.31 |
      | epdjhkhtqjfp******** | my-vm-2 | ru-central1-d | RUNNING |              | 10.130.0.6  |
      +----------------------+---------+---------------+---------+--------------+-------------+
      ```

  1. Get a list of [network interfaces](../../concepts/network.md) of the VM in question by specifying the VM ID:

     ```bash
     yc compute instance get <VM_ID>
     ```

     Result:

     ```yml
     ...
     network_interfaces:
       - index: "0"
         mac_address: d0:0d:12:4f:ef:b4
         subnet_id: e2l5iit0t6dr********
         primary_v4_address:
           address: 10.129.0.31
           one_to_one_nat:
             address: 84.201.166.2
             ip_version: IPV4
     ...
     ```

  1. Move the VM to a different availability zone:

      ```bash
      yc compute instance relocate <VM_ID> \
        --destination-zone-id ru-central1-d \
        --network-interface subnet-id=<subnet_ID>,security-group-ids=<security_group_ID>
      ```

      Where:

      * `<VM_ID>`: ID of the VM to move to a different availability zone.
      * `--destination-zone-id`: [Availability zone](../../../overview/concepts/geo-scope.md) ID. Only `ru-central1-d` is supported.
      * `--network-interface`: VM [network interface](../../concepts/network.md) settings:
          * `subnet-id`: ID of the subnet in the availability zone to move the VM to.
          * `security-group-ids`: ID of the [security group](../../../vpc/concepts/security-groups.md) to link to the VM you are moving. You can link multiple security groups to a single VM by providing a comma-separated list of security group IDs in `[id1,id2]` format.

          If a VM has multiple network interfaces, specify the `--network-interface` parameter as many times as needed (for each network interface).

      For more information about the `yc compute instance relocate` command, see the [CLI reference](../../../cli/cli-ref/compute/cli-ref/instance/relocate.md).

      If you are moving a VM with a [disk in a placement group](../../concepts/disk-placement-group.md), use this command:

      ```bash
      yc compute instance relocate <VM_ID> \
        --destination-zone-id ru-central1-d \
        --network-interface subnet-id=<subnet_ID>,security-group-ids=<security_group_ID> \
        --boot-disk-placement-group-id <disk_placement_group_ID> \
        --boot-disk-placement-group-partition <partition_number> \
        --secondary-disk-placement disk-name=<disk_name>,disk-placement-group-id=<disk_placement_group_ID>,disk-placement-group-partition=<partition_number>
      ```

      Where:

      * `--boot-disk-placement-group-id`: Disk placement group ID.
      * `--boot-disk-placement-group-partition`: Partition number in the disk placement group with the [partition placement](../../concepts/disk-placement-group.md#partition) strategy.
      * `--secondary-disk-placement`: Placement policy for secondary disks. Settings:

        * `disk-name`: Disk name.
        * `disk-placement-group-id`: ID of the disk placement group to place the disk in.
        * `disk-placement-group-partition`: Partition number in the disk placement group.

      For more information about the `yc compute instance relocate` command, see the [CLI reference](../../../cli/cli-ref/compute/cli-ref/instance/relocate.md).

  Please note that connecting VM [network interfaces](../../concepts/network.md) to new subnets changes their IP addressing. If you need to specify internal IP addresses for the VM network interfaces, use the `ipv4-address=<internal_IP_address>` property of the `network-interface` parameter; for public IP addresses, use the `nat-address=<public_IP_address>` property. Other than that, setting up network interface parameters when moving a VM to a different availability zone is similar to setting up the same parameters when creating a VM.

{% endlist %}

{% note info %}

Active writes to the VM disks being moved may cause the migration to fail. In this case, stop writing to the disks or shut down the VM and restart the migration.

{% endnote %}

### Examples {#examples}

#### Moving a VM to a different zone {#jump-from-a-to-d}

In this example, we are moving a VM named `my-vm-1` from the `ru-central1-b` availability zone to `ru-central1-d`.

```bash
yc compute instance relocate epdi9vnr8i6n******** \
  --destination-zone-id ru-central1-d \
  --network-interface subnet-id=fl8in4sila9i********,security-group-ids=enpagmu40nj5********
```

Result:

```text
done (1m28s)
id: epdi9vnr8i6n********
folder_id: b1g0ijbfaqsn********
created_at: "2025-11-04T18:44:29Z"
name: my-vm-1
zone_id: ru-central1-d
platform_id: standard-v3
resources:
  memory: "2147483648"
  cores: "2"
  core_fraction: "50"
status: RUNNING
metadata_options:
  gce_http_endpoint: ENABLED
  aws_v1_http_endpoint: ENABLED
  gce_http_token: ENABLED
  aws_v1_http_token: DISABLED
boot_disk:
  mode: READ_WRITE
  device_name: epdkl5gn20gv********
  auto_delete: true
  disk_id: epdkl5gn20gv********
network_interfaces:
  - index: "0"
    mac_address: d0:0d:12:4f:ef:b4
    subnet_id: fl8in4sila9i********
    primary_v4_address:
      address: 10.130.0.8
    security_group_ids:
      - enpagmu40nj5********
serial_port_settings:
  ssh_authorization: OS_LOGIN
gpu_settings: {}
fqdn: my-vm-1.ru-central1.internal
scheduling_policy: {}
network_settings:
  type: STANDARD
placement_policy: {}
hardware_generation:
  legacy_features:
    pci_topology: PCI_TOPOLOGY_V1
application: {}
```

#### Moving a VM with disks in a placement group {#jump-with-disk-placement-group}

In this example, we are moving a VM named `my-vm-1` with two disks in the placement group from the `ru-central1-b` availability zone to `ru-central1-d`.

```bash
yc compute instance relocate epd6qtn128k1******** \
  --destination-zone-id ru-central1-d \
  --network-interface \
    subnet-id=fl8glc5v0lqj********,security-group-ids=enp1gjh3q042******** \
  --boot-disk-placement-group-id fv4pfmor782v******** \
  --boot-disk-placement-group-partition 1 \
  --secondary-disk-placement \
    disk-name=disk-two,fv4pfmor782v********,disk-placement-group-partition=2
```

Result:

```text
done (9m0s)
id: epd6qtn128k1********
folder_id: b1gmit33ngp3********
created_at: "2023-12-07T19:30:20Z"
name: my-vm-1
zone_id: ru-central1-d
platform_id: standard-v3
resources:
  memory: "2147483648"
  cores: "2"
  core_fraction: "100"
status: RUNNING
metadata_options:
  gce_http_endpoint: ENABLED
  aws_v1_http_endpoint: ENABLED
  gce_http_token: ENABLED
  aws_v1_http_token: DISABLED
boot_disk:
  mode: READ_WRITE
  device_name: epdeqrm6g38j********
  auto_delete: true
  disk_id: epdeqrm6g38j********
secondary_disks:
  - mode: READ_WRITE
    device_name: epdi54snn7t6********
    disk_id: epdi54snn7t6********
network_interfaces:
  - index: "0"
    mac_address: d0:0d:6d:76:e1:12
    subnet_id: fl8glc5v0lqj********
    primary_v4_address:
      address: 10.130.0.12
    security_group_ids:
      - enp1gjh3q042********
gpu_settings: {}
fqdn: my-vm-1.ru-central1.internal
scheduling_policy: {}
network_settings:
  type: STANDARD
placement_policy: {}
```