> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Attaching and mounting Compute volumes to VMs

In this article, you will learn how to use [Compute disks and shared filesystems](./types) on virtual machines (VMs).

<Note>
  This article only covers additional volumes: non-boot disks and shared filesystems. You add a boot disk when you create a VM.
</Note>

After [creating a disk](./manage#how-to-create-a-disk) or a [shared filesystem](./manage#how-to-create-a-shared-filesystem), you need to do the following to use it on a VM:

1. [Attach it to the VM](#how-to-attach-volumes-to-vms) by using Nebius AI Cloud interfaces.
2. [Mount it to the VM](#how-to-mount-volumes-to-vms) inside the VM's operating system.

A VM and its volumes must be located in the same project. For more details about projects and resource hierarchy in Nebius AI Cloud, see [How resources, identities and access are managed in Nebius AI Cloud](/iam/overview).

## How to attach volumes to VMs

To attach disks or shared filesystems to a VM:

<Tabs group="interfaces">
  <Tab title="Web console">
    * **New VM**

      On the VM creation page (<Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/compute.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=b91340217b08a1456d88ae0347f281d1" width="16" height="16" data-path="_assets/sidebar/compute.svg" /> **Compute** → **Virtual machines** → **Create virtual machine**), do the following:

      1. Click **Attach disk** or **Attach shared filesystem**.

      2. Set up the volume:

         1. Select whether you want to add a new or existing volume.

            If an existing disk is already added to another VM, you cannot add it to the new VM. A filesystem can be shared by multiple VMs.

         2. For a new volume, set its [parameters](/compute/storage/manage#volume-parameters).

         3. Set a device ID if you are adding a disk, or a mount tag if you are attaching a filesystem. Device IDs and mount tags are used to [mount volumes to VMs](/compute/storage/use#how-to-mount-volumes-to-vms).

      3. Click the attach-volume button at the end of the window.

             <Warning>
               When you click **Create and add disk** or **Create and attach filesystem**, the disk or filesystem is created immediately and [charged](../resources/pricing#volumes-disks-and-shared-filesystems) separately even if you remove it from the VM later or do not proceed with creating the VM.
             </Warning>

      4. If you want to [manually mount the filesystem](#shared-filesystems) that you added to the VM, turn off the **Auto mount** option for the filesystem.

         By default, Compute automatically mounts filesystems that you add to VMs via the web console.

         If you add a disk, you always need to [mount it manually](#disks).

    * **Existing VM**

      **Disks**

      1. In the sidebar, go to <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/compute.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=b91340217b08a1456d88ae0347f281d1" width="16" height="16" data-path="_assets/sidebar/compute.svg" /> **Compute** → **Virtual machines**.

      2. Open the page of the required VM.

      3. Switch to the **Disks** tab.

      4. Click **Attach resource** → **Disk**.

      5. Select whether you want to attach a new or existing disk.

         If an existing disk is already attached to another VM, you cannot attach it to a new VM.

      6. For a new disk, set its [parameters](/compute/storage/manage#volume-parameters).

      7. Set a device ID for the disk. Device IDs are used to [mount disks to VMs](/compute/storage/use#how-to-mount-volumes-to-vms).

      8. Click the attach-volume button at the end of the window.

      **Shared filesystems**

      1. In the sidebar, go to <Icon icon="https://mintcdn.com/nebius-ai-cloud/1Ha0sWR6e1mnIaHS/_assets/sidebar/compute.svg?fit=max&auto=format&n=1Ha0sWR6e1mnIaHS&q=85&s=b91340217b08a1456d88ae0347f281d1" width="16" height="16" data-path="_assets/sidebar/compute.svg" /> **Compute** → **Virtual machines**.

      2. Open the page of the required VM.

      3. If the VM is not in the `Stopped` status, click **Stop VM** and then confirm the action.

      4. After the VM has the `Stopped` status, switch to the **Filesystems** tab.

      5. Click **Attach resource** → **Filesystem**.

      6. Select whether you want to attach a new or existing filesystem.

         A filesystem can be shared by multiple VMs.

      7. For a new filesystem, set its [parameters](/compute/storage/manage#volume-parameters).

      8. Set a mount tag for the filesystem. Mount tags are used to [mount filesystems to VMs](/compute/storage/use#how-to-mount-volumes-to-vms).

      9. Click the attach-volume button at the end of the window.
  </Tab>

  <Tab title="CLI">
    1. [Create the volumes](./manage).

    2. Create the following files locally:

       * `secondary_disk.json` to attach disks:

         ```json theme={null}
         [
           {
             "attach_mode": "<READ_ONLY|READ_WRITE>",
             "existing_disk": {
               "id": "<disk_ID>"
             },
             "device_id": "<device_ID>"
           }
         ]
         ```

         Where:

         * Write permission, `READ_WRITE` (default) or `READ_ONLY`.
         * `existing_disk.id`: Disk ID to be added. To get the ID, run `nebius compute disk list`.
         * `device_id`: Disk device ID. This parameter is different from `existing_disk.id`, as `device_id` is used for [mounting a disk to a VM](/compute/storage/use#disks).

           Create your own device ID, such as `my-disk`. Make sure that it is unique within a VM.

           If you do not specify the device ID, it takes the `disk-N` default value where `N` is an integer. For example, `disk-0`.

       * `filesystem.json` to attach shared filesystems:

         ```json theme={null}
         [
           {
             "attach_mode": "<READ_ONLY|READ_WRITE>",
             "existing_filesystem": {
               "id": "<filesystem_ID>"
             },
             "mount_tag": "<filesystem_tag>"
           }
         ]
         ```

         Where:

         * Write permission, `READ_WRITE` (default) or `READ_ONLY`.
         * `existing_filesystem.id`: Filesystem ID to be attached. To get the ID, run <code>nebius compute filesystem list</code>.
         * `mount_tag`: Tag for [mounting a filesystem to a VM](#shared-filesystems).

           Create your own tag, such as `my-filesystem`. Make sure that it is unique within a VM.

           If you do not specify the tag, it takes the `filesystem-N` default value where `N` is an integer. For example, `filesystem-0`.

    3. Create or update a VM with the volumes configured:

       * To **create a VM**, run the following command:

         ```bash theme={null}
         nebius compute instance create \
           --secondary-disks "$(cat secondary_disk.json)" \
           --filesystems "$(cat filesystem.json)" \
           <other_parameters>
         ```

       * To **attach disks to an existing VM**, run the following command:

         ```bash theme={null}
         nebius compute instance update <VM_ID> \
           --patch \
           --secondary-disks "$(cat secondary_disk.json)"
         ```

         To get the ID of an existing VM, run <code>nebius compute instance list</code>.

         The `--patch` parameter allows you to only update the specified parameters. Without it, the command resets the VM settings to their default values.

       * To **attach shared filesystems to an existing VM**, stop the VM first:

         ```bash theme={null}
         nebius compute instance stop --id <VM_ID>
         ```

         Then update the VM:

         ```bash theme={null}
         nebius compute instance update <VM_ID> \
           --patch \
           --filesystems "$(cat filesystem.json)"
         ```

         After the update, start the VM:

         ```bash theme={null}
         nebius compute instance start --id <VM_ID>
         ```
  </Tab>
</Tabs>

## How to mount volumes to VMs

### Disks

1. [Attach the disk to a VM](#how-to-attach-volumes-to-vms).

2. If you have not saved the disk's device ID, for example, when adding it to the VM, get it from the information about the VM:

   ```bash theme={null}
   nebius compute instance get --id <VM_ID> --format json \
     | jq -r --arg disk_id <disk_ID> \
       '.spec.secondary_disks[]
       | select(.existing_disk.id == $disk_id)
       | .device_id'
   ```

   To get the VM ID, run <code>nebius compute instance list</code>. To get the disk ID, run <code>nebius compute disk list</code>.

3. [Connect to the VM over SSH](../virtual-machines/connect#connect-to-the-vm-using-ssh).

4. Switch to the `root` user:

   ```bash theme={null}
   sudo su -
   ```

5. Partition the device. For example, you can use `cfdisk`. In the example below, we assume that you have named the device `disk-0`; for disks, all device IDs are prefixed with `virtio-`:

   1. Run `cfdisk`:

      ```bash theme={null}
      cfdisk /dev/disk/by-id/virtio-disk-0
      ```

      <Note>
        Referring to a device by its name, e.g., `/dev/vdb`, does not guarantee it will function properly. Use the device ID instead, e.g., `/dev/disk/by-id/virtio-disk-0`.
      </Note>

   2. Under **Select label type**, select **gpt** and press **Enter**.

   3. Select **New** (partition) and press **Enter**.

   4. Enter the partition size and press **Enter**. This will create a `/dev/disk/by-id/virtio-disk-0-part1` partition.

   5. Select **Write** (the partition table to the device) and press **Enter**, then type `yes` and press **Enter**.

   6. Select **Quit** and press **Enter**.

6. Format the partition:

   ```bash theme={null}
   mkfs.ext4 /dev/disk/by-id/virtio-disk-0-part1
   ```

7. Mount the partition and configure permissions for it by using `chmod`. In the example below, the partition is mounted at `/mnt/disk-0`, and all VM users are granted write access to it:

   ```bash theme={null}
   mkdir /mnt/disk-0
   mount /dev/disk/by-id/virtio-disk-0-part1 /mnt/disk-0
   chmod a+w /mnt/disk-0
   ```

8. If you want the partition to be mounted automatically after every VM restart, add it to `/etc/fstab` by its UUID:

   ```bash theme={null}
   echo "UUID=$(blkid -s UUID -o value /dev/disk/by-id/virtio-disk-0-part1) /mnt/disk-0 ext4 defaults,nofail 0 2" >> /etc/fstab
   ```

   <Warning>
     Do not omit `nofail`. If it is not specified and the VM cannot find the partition on restart (for example, the disk has been repartitioned), the VM will not boot.
   </Warning>

9. Exit the `root` user shell:

   ```bash theme={null}
   exit
   ```

### Shared filesystems

If you create a VM in the web console, you can automatically attach and mount a shared filesystem to the VM by using the **Auto mount** option. If you do not use it, mount the filesystem manually. To do this:

1. [Attach the shared filesystem to a VM](#how-to-attach-volumes-to-vms).

2. If you have not saved the filesystem's mount tag, for example, when adding it to the VM, get the mount tag from the information about the VM:

   ```bash theme={null}
   nebius compute instance get --id <VM_ID> --format json \
     | jq -r --arg fs_id <filesystem_ID> \
       '.spec.filesystems[]
       | select(.existing_filesystem.id == $fs_id)
       | .mount_tag'
   ```

   To get the VM ID, run <code>nebius compute instance list</code>. To get the disk ID, run <code>nebius compute filesystem list</code>.

3. [Connect to the VM over SSH](../virtual-machines/connect#connect-to-the-vm-using-ssh).

4. Switch to the `root` user:

   ```bash theme={null}
   sudo su -
   ```

5. Mount the filesystem as a `virtiofs` device and configure permissions for it by using `chmod`. In the example below, a filesystem has the mount tag `filesystem-0` and is mounted at `/mnt/fs`. All VM users are granted write access to it:

   ```bash theme={null}
   mkdir /mnt/fs
   mount -t virtiofs filesystem-0 /mnt/fs
   chmod a+w /mnt/fs
   ```

6. If you want the filesystem to be mounted automatically after every VM restart, add it to `/etc/fstab`:

   ```bash theme={null}
   echo "filesystem-0 /mnt/fs virtiofs rw,nofail 0 0" >> /etc/fstab
   ```

   <Warning>
     Do not omit `nofail`. If it is not specified and the VM cannot find the filesystem on restart (for example, it has been deleted), the VM will not boot.
   </Warning>

7. Exit the `root` user shell:

   ```bash theme={null}
   exit
   ```

## See also

* [How to detach additional volumes from virtual machines](./detach-volume)
* [Types of storage volumes in Compute](./types)
* [Creating and resizing Compute volumes](./manage)
* [How to create a virtual machine in Nebius AI Cloud](../virtual-machines/manage)
