Yandex.Cloud
  • Services
  • Why Yandex.Cloud
  • Solutions
  • Pricing
  • Documentation
  • Contact us
Get started
Yandex Compute Cloud
  • Getting started
    • Overview
    • Creating a Linux VM
    • Creating a Windows VM
    • Creating instance groups
  • Step-by-step instructions
    • All instructions
    • Creating VMs
      • Creating a Linux VM
      • Creating a Windows VM
      • Creating a VM from a set of disks
      • Creating a VM with disks restored from snapshots
      • Creating a VM from a custom image
      • Creating a preemptible VM
      • Creating a VM with a GPU
    • DSVM
      • Overview
      • Creating a VM from a public DSVM image
    • Placement groups
      • Creating a placement group
      • Deleting a placement group
      • Creating a VM in a placement group
      • Adding a VM to a placement group
      • Removing a VM instance from a placement group
    • Images with pre-installed software
      • Creating a VM from a public image
      • Configuring software
      • Working with a VM based on a public image
      • Getting a list of public images
    • Getting information about a VM
      • Getting information about a VM
      • Viewing serial port output
    • Managing VMs
      • Stopping and starting a VM
      • Attaching a disk to a VM
      • Detaching a disk from a VM
      • Moving a VM to a different availability zone
      • Making a VM's public IP address static
      • Updating a VM
      • Changing VM computing resources
      • Deleting a VM
    • Working on VMs
      • Connecting to a VM via SSH
      • Connecting to a VM via RDP
      • Working with Yandex.Cloud from inside a VM
      • Installing NVIDIA drivers
    • Creating new disks
      • Creating an empty disk
      • Create an empty disk with a large block
    • Disk management
      • Creating a disk snapshot
      • Updating a disk
      • Deleting a disk
      • Deleting a disk snapshot
    • Creating new images
      • Uploading your image
    • Managing images
      • Deleting a disk image
    • Managing the serial console
      • Getting started
      • Connecting to a serial console via SSH
      • Connecting to a serial console via CLI
      • Start your terminal in the Windows SAC
      • Disabling access to the serial console
    • Creating instance groups
      • Creating a fixed-size instance group
      • Creating a fixed-size instance group with a network load balancer
      • Creating an automatically scaled instance group
      • Creating an instance group from Container Optimized Image
    • Getting information about instance groups
      • Getting a list of instance groups
      • Getting information about an instance group
      • Getting a list of instances in a group
    • Managing instance groups
      • Editing an instance group
      • Configuring application health check on the VM
      • Updating a instance group
        • Incremental updates
        • Uninterrupted updates
      • Stopping an instance group
      • Starting an instance group
      • Deleting an instance group
    • Dedicated hosts
      • Creating a VM in a group of dedicated hosts
      • Creating a VM on a dedicated host
  • Yandex Container Optimized Solutions
  • Scenarios
    • Configuring NTP time synchronization
    • Running instance groups with auto scaling
  • Concepts
    • Relationship between resources
    • Virtual machines
      • Overview
      • Platforms
      • vCPU performance levels
      • Graphics accelerators (GPUs)
      • Preemptible VMs
      • Network on a VM
      • Live migration
      • Placement groups
      • Statuses
      • Metadata
    • Disks
      • Overview
      • Disk snapshots
    • Images
    • Instance groups
      • Overview
      • Access
      • Instance template
      • Variables in an instance template
      • Policies
        • Overview
        • Allocation policy
        • Deployment policy
        • Scaling policy
      • Scaling types
      • Auto-healing
      • Updating
        • Overview
        • Allocating instances across zones
        • Deployment algorithm
        • Rules for updating instance groups
      • Statuses
    • Dedicated host
    • Backups
    • Quotas and limits
  • Access management
  • Pricing policy
    • Current pricing policy
    • Archive
      • Before January 1, 2019
      • From January 1 to March 1, 2019
      • From March 1 to May 1, 2019
  • Compute API reference
    • Authentication in the API
    • gRPC
      • Overview
      • DiskPlacementGroupService
      • DiskService
      • DiskTypeService
      • HostGroupService
      • HostTypeService
      • ImageService
      • InstanceService
      • PlacementGroupService
      • SnapshotService
      • ZoneService
      • InstanceGroupService
      • OperationService
    • REST
      • Overview
      • Disk
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • DiskPlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listDisks
        • listOperations
        • update
      • DiskType
        • Overview
        • get
        • list
      • HostGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listHosts
        • listInstances
        • listOperations
        • update
      • HostType
        • Overview
        • get
        • list
      • Image
        • Overview
        • create
        • delete
        • get
        • getLatestByFamily
        • list
        • listOperations
        • update
      • Instance
        • Overview
        • addOneToOneNat
        • attachDisk
        • create
        • delete
        • detachDisk
        • get
        • getSerialPortOutput
        • list
        • listOperations
        • removeOneToOneNat
        • restart
        • start
        • stop
        • update
        • updateMetadata
        • updateNetworkInterface
      • PlacementGroup
        • Overview
        • create
        • delete
        • get
        • list
        • listInstances
        • listOperations
        • update
      • Snapshot
        • Overview
        • create
        • delete
        • get
        • list
        • listOperations
        • update
      • Zone
        • Overview
        • get
        • list
      • Operation
        • Overview
        • get
      • InstanceGroup
        • Overview
        • createFromYaml
        • update
        • list
        • get
        • delete
        • start
        • stop
        • create
        • listAccessBindings
        • setAccessBindings
        • updateFromYaml
        • listLogRecords
        • listInstances
        • updateAccessBindings
        • listOperations
  • Questions and answers
    • General questions
    • Virtual machines
    • Disks and snapshots
    • Licensing
    • All questions on the same page
  1. Step-by-step instructions
  2. Managing VMs
  3. Attaching a disk to a VM

Attaching a disk to a VM

  • Attaching a disk
  • Mounting a disk created from a snapshot or image
  • Partitioning and mounting an empty disk

You can attach a disk to either a running or stopped virtual machine.

For a disk to be successfully attached to a running VM, the operating system must be ready to accept commands to attach disks. Before attaching a disk, make sure that the OS is loaded or stop the virtual machine, otherwise the attach disk operation fails. If an error occurs, stop the VM and repeat the operation.

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.

Attaching a disk

To attach a disk to a VM:

Management console
CLI
API
  1. Select the folder the VM belongs to.
  2. Select Yandex Compute Cloud.
  3. Go to Disks.
  4. Under Disks, select an unmounted disk or create a new one.
  5. Next to the desired disk, click and select Attach.
  6. In the window that opens:
    • In the VM field, select the virtual machine you want to mount your disk to.
    • Enter a Device name.
    • Select the value of the Delete automatically parameter.
  7. Click Attach.

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.

  1. View a description of the CLI attach disk command:

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

    $ yc compute instance list
    +----------------------+-----------------+---------------+---------+----------------------+
    |          ID          |       NAME      |    ZONE ID    | STATUS  |     DESCRIPTION      |
    +----------------------+-----------------+---------------+---------+----------------------+
    | fhm0b28lgfp4tkoa3jl6 | first-instance  | ru-central1-a | RUNNING | my first vm via CLI  |
    | fhm9gk85nj7gcoji2f8s | second-instance | ru-central1-a | RUNNING | my second vm via CLI |
    +----------------------+-----------------+---------------+---------+----------------------+
    
  3. Select the VM ID or NAME (for example, first-instance).

  4. Get a list of disks in the default folder:

    yc compute disk list
    

    Result:

    +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+
    |          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  |                      |                         |
    +----------------------+--------------+-------------+---------------+--------+----------------------+-------------------------+
    
  5. Select the ID or NAME of the required disk (for example, first-disk). To view a list of disks attached to the VM, run the 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 attach an empty disk, partition and mount it manually. Alternatively, instead of attaching an empty disk, you can create a snapshot of the boot disk and create a VM based on the snapshot.

    If an error occurs, stop the virtual machine:

    $ yc compute instance stop first-instance
    

    Then reattach the disk.

  7. If the virtual machine was stopped, restart it:

    $ yc compute instance start first-instance
    

Use the attachDisk method for the Instance resource.

Mounting a disk created from a snapshot or image

To use the attached disk:

Linux
Windows

Mount the disk:

  1. Connect to the VM via SSH.

  2. Run the blkid command and make sure that there are no partitions with duplicate UUIDs:

    $ sudo blkid
    /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"
    ...
    
  3. 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 the Linux images provided by Yandex.Cloud. The file system type is returned by the blkid command in the TYPE parameter.

    If you use another filesystem, run the suitable command. For example, to generate a UUID 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
    /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 the IDs must be unique. For example, if you clone a boot disk and attach it to the same VM, two partitions with the same UUIDs appear on the VM. As a result, after starting the VM, the root partition may not be the one you specified as the boot disk.

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

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

  1. Connect to the VM via RDP.

  2. Assign a letter to the attached disk. For information about how to do this, see the Microsoft documentation.

Partitioning and mounting an empty disk

To partition and mount an empty disk yourself:

Linux
Windows
  1. Check if the disk is attached as a device and get its path in the system:

    lsblk
    

    Command execution result:

    NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda    252:0    0  13G  0 disk
    ├─vda1 252:1    0   1M  0 part
    └─vda2 252:2    0  13G  0 part /
    vdb    252:16   0   1G  0 disk
    

    An empty disk is usually labeled /dev/vdb.

  2. Partition your disk. To do this, create partitions using cfdisk, fdisk, or parted.

  3. Format the disk for the appropriate file system. For example, you can use the mkfs utility.

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

    sudo mkdir /mnt
    sudo mount /dev/vdb2 /mnt
    
  5. Check the file system status:

    df
    

    Command execution result:

    Filesystem     1K-blocks    Used Available Use% Mounted on
    udev              989424       0    989424   0% /dev
    tmpfs             203524     816    202708   1% /run
    /dev/vda2       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/vdb2         523260    3080    520180   1% /mnt
    
  1. Run the Computer Management tool as an administrator.

  2. Under Storage, select Disk Management.

  3. Initialize the disk. To do this, right-click on the empty disk and select Initialize Disk. This opens the Initialize Disk dialog.

  4. Select a partition style and click ОК.

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

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

In this article:
  • Attaching a disk
  • Mounting a disk created from a snapshot or image
  • Partitioning and mounting an empty disk
Language / Region
Careers
Privacy policy
Terms of use
Brandbook
© 2021 Yandex.Cloud LLC