Yandex Cloud
Search
Contact UsGet started
  • Blog
  • Pricing
  • Documentation
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • ML & AI
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Customer Stories
    • Gateway to Russia
    • Cloud for Startups
    • Education and Science
  • Blog
  • Pricing
  • Documentation
Yandex project
© 2025 Yandex.Cloud LLC
Yandex Compute Cloud
    • All guides
      • Stopping and starting a VM
      • Resetting a Windows Server VM user password
      • Attaching a disk to a VM
      • Detaching a disk from a VM
      • Moving a VM to a different availability zone
      • Moving a VM to a different folder
      • Moving a VM to a different cloud
      • Adding another network interface to a VM
      • Deleting a network interface from a VM
      • Assigning a public IP address to a VM
      • Unassigning a public IP address from a VM
      • Making a VM public IP address static
      • Reassigning a public IP address from one VM to another
      • Updating the VM internal IP address
      • Updating a VM
      • Changing VM computing resources
      • Changing VM security groups
      • VM maintenance policy management
      • Configuring VM access permissions
      • Linking a service account to a VM
      • Deleting a VM
    • Viewing operations with resources
  • Yandex Container Solution
  • Access management
  • Terraform reference
  • Monitoring metrics
  • Audit Trails events
  • Release notes

In this article:

  • Attaching a disk
  • Mounting a disk created from a snapshot or image
  • Partitioning and mounting an empty disk
  1. Step-by-step guides
  2. Managing a VM
  3. Attaching a disk to a VM

Attaching a disk to a VM

Written by
Yandex Cloud
Improved by
Updated at May 5, 2025
  • Attaching a disk
  • Mounting a disk created from a snapshot or image
  • Partitioning and mounting an empty disk

You can attach a secondary disk to either a running or stopped VM.

On a Linux VM deployed from Cloud Marketplace or custom images with the driver kit installed, a secondary disk you attach will be available as a new device without rebooting the VM.

To successfully attach a disk, the VM operating system must be fully booted or stopped; otherwise the operation will fail. If an error occurs, stop the VM and try again.

On a Windows VM, a secondary disk you attach will only show up as a new device after a reboot.

When selecting a disk to attach to your VM, you can specify whether to delete that disk when deleting the VM. You can enable this option when creating or updating a VM, or when attaching a new disk to it.

Attaching a diskAttaching a disk

Note

You can only attach a local disk to a VM on a dedicated host while creating it. For more information, see these guides.

Management console
CLI
Terraform
API
  1. In the management console, select the folder the VM belongs to.
  2. Select Compute Cloud.
  3. In the left-hand panel, select Disks.
  4. Select an unattached disk or create a new one.
  5. Next to the disk you want to attach, click and select Attach.
  6. In the window that opens:
    • In the VM field, select the virtual machine you want to attach your disk to.
    • To attach an encrypted disk, select a service account with the kms.keys.encrypterDecrypter role for the KMS key that was used to encrypt the disk.
    • Enter the device name.
    • Enable Delete along with the virtual machine, if required.
  7. Click Attach.

If you do not have the Yandex Cloud CLI yet, install and initialize it.

The folder specified when creating the CLI profile is used by default. To change the default folder, use the yc config set folder-id <folder_ID> command. You can specify a different folder using the --folder-name or --folder-id parameter.

  1. See the description of the CLI command for attaching disks:

    yc compute instance attach-disk --help
    
  2. Get a list of VMs in the default folder:

    yc compute instance list
    

    Result:

    +----------------------+-----------------+---------------+---------+----------------------+
    |          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 |
    +----------------------+-----------------+---------------+---------+----------------------+
    
  3. Select ID or NAME of the VM, e.g., first-instance.

  4. 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  |                      |                 |             |
    +----------------------+--------------+-------------+-------------------+--------+----------------------+-----------------+-------------+
    
  5. Select ID or NAME of the disk, e.g., first-disk. To view a list of disks attached to the VM, run this command:

    yc compute instance get --full first-instance
    
  6. Attach the disk to the VM:

    yc compute instance attach-disk first-instance \
      --disk-name first-disk \
      --mode rw
    

    To automatically delete the disk when deleting the VM, set the --auto-delete flag.

    Note

    Empty disks do not have a file system. If you are attaching an empty disk, partition and mount it manually. Alternatively, rather than attaching an empty disk, you can create a snapshot of the boot disk and use it to create a VM.

    If an error occurs, stop the VM:

    yc compute instance stop first-instance
    

    Then, try to attach the disk once again.

  7. If the VM was stopped, restart it:

    yc compute instance start first-instance
    

With Terraform, you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.

Terraform is distributed under the Business Source License. The Yandex Cloud provider for Terraform is distributed under the MPL-2.0 license.

For more information about the provider resources, see the documentation on the Terraform website or mirror website.

If you do not have Terraform yet, install it and configure its Yandex Cloud provider.

  1. If you have already created a secondary disk, get its ID.

  2. Open the Terraform configuration file with the description of the VM you want to attach the secondary disk to. See an example of the VM configuration file.

  3. Depending on whether the secondary disk is already created, follow these steps:

    • If the disk is already created, add the secondary_disk parameter to the yandex_compute_instance resource description section and specify the secondary disk ID in the disk_id value:

      resource "yandex_compute_instance" "vm-1" {
         ...
         secondary_disk {
            disk_id = "<disk_ID>"
         }
         ...
      }
      
    • If the disk is not created, add a new section with the yandex_compute_disk resource description to the configuration file, add the secondary_disk parameter to the yandex_compute_instance resource description section, and specify the link to the ID of the created secondary disk in the disk_id value:

      resource "yandex_compute_disk" "secondary-disk-1" {
          name     = "secondary-disk-1"
          type     = "network-hdd"
          zone     = "<availability_zone>"
          size     = "<disk_size>"
      }
      
      resource "yandex_compute_instance" "vm-1" {
         ...
         secondary_disk {
            disk_id = yandex_compute_disk.secondary-disk-1.id
         }
         ...
      }
      

    Note

    The secondary disk and VM must be in the same availability zone.

    For more information about the yandex_compute_disk resource parameters, see this Terraform article.

  4. Create the resources:

    1. In the terminal, change to the folder where you edited the configuration file.

    2. Make sure the configuration file is correct using the command:

      terraform validate
      

      If the configuration is correct, the following message is returned:

      Success! The configuration is valid.
      
    3. Run the command:

      terraform plan
      

      The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.

    4. Apply the configuration changes:

      terraform apply
      
    5. Confirm the changes: type yes in the terminal and press Enter.

    Terraform will create all the required resources. You can check the new resources using the management console.

Use the attachDisk REST API method for the Instance resource or the InstanceService/AttachDisk gRPC API call.

Mounting a disk created from a snapshot or imageMounting a disk created from a snapshot or image

Linux
Windows
  1. Attach the disk to the VM.

  2. Connect to the VM via SSH.

  3. Run the blkid command and make sure there are no partitions with the same UUIDs:

    sudo blkid
    

    Result:

    /dev/vda2: UUID="0d6dfef0-542d-47ba-b55b-18ab5f5f9210" TYPE="ext4" PARTUUID="752aa845-94ee-4850-9188-71c2f919ee7b"
    /dev/vdb2: UUID="0d6dfef0-542d-47ba-b55b-18ab5f5f9210" TYPE="ext4" PARTUUID="752aa845-94ee-4850-9188-71c2f919ee7b"
    ...
    
  4. If there are, generate a new UUID for the duplicates that come last in the blkid command output. In the example from the previous step, you need to generate a UUID for the /dev/vdb2 partition:

    sudo e2fsck -f /dev/vdb2
    sudo tune2fs -U $(uuidgen) /dev/vdb2
    

    This method works for partitions with ext2, ext3, and ext4 file systems. The latter is used in Linux images provided by Yandex Cloud. The file system type is returned by the blkid command in the TYPE parameter.

    If you have a different file system, use the appropriate commands. For example, for XFS, run the following:

    sudo xfs_admin -U generate /dev/vdb2
    

    To see if the UUID changed, run the blkid command again:

    sudo blkid
    

    Result:

    /dev/vda2: UUID="0d6dfef0-542d-47ba-b55b-18ab5f5f9210" TYPE="ext4" PARTUUID="752aa845-94ee-4850-9188-71c2f919ee7b"
    /dev/vdb2: UUID="ea004485-07fb-4128-b20d-e408db1e8ae8" TYPE="ext4" PARTUUID="752aa845-94ee-4850-9188-71c2f919ee7b"
    ...
    

    When creating a snapshot or image in Linux, the UUID and PARTUUID of disk partitions are saved. Linux uses this data when mounting partitions, including the root one, so these IDs must be unique. For example, if you clone a boot disk and attach it to the same VM, the VM will have two partitions with identical UUIDs. As a result, the VM may boot from the root partition of the wrong disk, rather than the one you specified as the boot disk.

  5. Mount disk partitions using the mount utility. For example, mount the vdb2 partition to the /mnt directory:

    sudo mkdir /mnt/vdb2
    sudo mount /dev/vdb2 /mnt/vdb2
    
  6. Run the df command to check the state of the file system.

  1. Connect to the VM via RDP.

  2. Run Computer Management (the compmgmt.msc snap-in) as an administrator.

  3. Under Storage, select Disk Management.

    Note

    When you attach a disk to a running VM, it might not appear in the list. In that case, restart the OS and repeat the steps in this guide.

  4. If the attached disk is Offline, right-click it and select Online.

  5. Assign a drive letter to the attached disk, if required. To learn how to do this, see the relevant Microsoft documentation.

  6. Open Explorer to check that the attached disk is properly mounted and available.

Partitioning and mounting an empty diskPartitioning and mounting an empty disk

Linux
Windows
  1. Attach an empty disk to the VM.

  2. Connect to the VM via SSH.

  3. Check whether the disk is attached as a device and get its path in the system:

    ls -la /dev/disk/by-id
    

    Result:

    total 0
    drwxr-xr-x 2 root root 140 Jan 16 12:09 .
    drwxr-xr-x 6 root root 120 Jan 13 13:51 ..
    lrwxrwxrwx 1 root root   9 Jan 16 12:09 virtio-fhm1dn62tm5d******** -> ../../vdc
    lrwxrwxrwx 1 root root   9 Jan 13 13:51 virtio-fhm4ev6dodt9******** -> ../../vdb
    lrwxrwxrwx 1 root root  10 Jan 13 13:51 virtio-fhm4ev6dodt9********-part1 -> ../../vdb1
    lrwxrwxrwx 1 root root  10 Jan 13 13:51 virtio-fhm4ev6dodt9********-part2 -> ../../vdb2
    lrwxrwxrwx 1 root root   9 Jan 13 13:51 virtio-nvme-disk-0 -> ../../vda
    

    Where:

    • Network disks have links in virtio-<disk_ID> format. For example, virtio-fhm1dn62tm5d******** -> ../../vdc means that an unpartitioned disk with the fhm1dn62tm5d******** ID is labeled vdc.
    • On dedicated hosts, local disks have links in virtio-nvme-disk-<disk_number> format (if you attached the disks to the VM when creating it). Disk numbering starts from zero. For example, virtio-nvme-disk-0 -> ../../vda means that the first local disk (numbered zero) is labeled vda.
  4. Partition your disk. To do this, create partitions on the disk using the cfdisk utility, the fdisk utility, or the parted utility.

    Run commands as a superuser. To do this, use sudo in each command, or before you start, run the sudo su - command to switch your terminal to superuser mode. For example, let's create partitions using fdisk:

    1. Run the utility:

      sudo fdisk /dev/<disk_label>
      

      Where <disk_label> is the label of the disk you want to partition, e.g., vdb or vdc.

      You will be taken to the fdisk menu. To get a list of available commands, type m and press Enter.

    2. Create a new partition: type n and press Enter.

    3. Set the partition as primary: type p and press Enter.

    4. You will be prompted to select a number for the partition. Press Enter to create partition 1.

    5. Leave the default values for the numbers of the first and last sectors of the partition: press Enter twice.

    6. Make sure the partition was successfully created. For this, request a list of disk partitions: type p and press Enter.

      Result:

      Device     Boot Start      End  Sectors Size Id Type
      /dev/vdc1        2048 41943039 41940992  20G 83 Linux
      

      Where vdc1 is the partition label consisting of the disk label and the partition number. You will need the partition label for further partition operations.

    7. To save your changes, type w and press Enter.

  5. Format the partition to the required file system. To do this, you can use the mkfs utility. For example, to format the partition to ext4, run the following command, specifying the label of the partition you created earlier:

    sudo mkfs.ext4 /dev/<partition_label>
    

    Result:

    Creating filesystem with 261888 4k blocks and 65536 inodes
    Filesystem UUID: 584a800c-e1fc-4f66-9228-a444f2d7440d
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376
    
    Allocating group tables: done
    Writing inode tables: done
    Creating journal (4096 blocks): done
    Writing superblocks and filesystem accounting information: done
    

    Where Filesystem UUID is the unique partition ID. You will need the partition ID when setting up automatic mounting of this partition to the system. You can also get the partition ID using the sudo blkid /dev/<partition_label> command.

  6. Mount the disk partition using the mount utility. To mount the /dev/<partition_label> partition to the /mnt/new_disk directory, run the following command:

    sudo mkdir /mnt/new_disk && sudo mount /dev/<partition_label> /mnt/new_disk
    
  7. Configure the partition write and read permissions using the chmod utility. For example, to allow all users to write to the partition, run the following command:

    sudo chmod a+w /mnt/new_disk
    
  8. Configure automatic mounting of the partition to the mnt/new_disk directory when the VM starts:

    1. Open the /etc/fstab file, e.g., using the nano text editor:

      sudo nano /etc/fstab
      
    2. Add the following line to the end of the file, specifying the ID of your partition in the UUID parameter:

      UUID=<partition_ID> /mnt/new_disk ext4 defaults 0 2
      

      Where UUID is the unique partition ID obtained earlier during formatting, e.g., 584a800c-e1fc-4f66-9228-a444f2d7440d.

    3. Save the changes and close the file.

  9. Check the state of your file systems:

    df
    

    Result:

    Filesystem     1K-blocks    Used Available Use% Mounted on
    udev              989424       0    989424   0% /dev
    tmpfs             203524     816    202708   1% /run
    /dev/vdb2       13354932 2754792  10015688  22% /
    tmpfs            1017608       0   1017608   0% /dev/shm
    tmpfs               5120       0      5120   0% /run/lock
    tmpfs            1017608       0   1017608   0% /sys/fs/cgroup
    tmpfs             203520       0    203520   0% /run/user/1000
    /dev/vdc1         523260    3080    520180   1% /mnt/vdc1
    
  1. Connect to the VM via RDP.

  2. Run Computer Management (the compmgmt.msc snap-in) as an administrator.

  3. Under Storage, select Disk Management.

    Note

    When you attach a disk to a running VM, it might not appear in the list. In that case, restart the OS and repeat the steps in this guide.

  4. If the attached disk is Offline, right-click it and select Online.

  5. Initialize the disk. To do this, right-click it and select Initialize Disk. This will open the Initialize Disk dialog box.

  6. Select the partition style and click OK.

  7. Create partitions on the disk. To do this, right-click an empty disk and select New Simple Volume.

  8. Use the New Simple Volume Wizard to set the partition size, assign a drive letter, and specify the file system type.

  9. Open Explorer to check that the attached disk is properly mounted and available.

Was the article helpful?

Previous
Resetting a Windows Server VM user password
Next
Detaching a disk from a VM
Yandex project
© 2025 Yandex.Cloud LLC