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

# Manage a volume

> Manage existing Gcore volumes, including attachments, resizing, volume types, and deletion.

## Customer Portal

Rename, tag, attach, resize, retype, or delete an existing volume.

## Attach volumes to an existing Virtual Machine

When a volume is attached to a Virtual Machine, the VM name appears on the **Volumes** page in the **Instance** column. Otherwise, the **Attach to Instance** link appears. More than one volume can be attached to a Virtual Machine. However, volumes can only be used in the same region where the VM is created.

Volumes can be attached to a Virtual Machine either from the **Volumes** page or from the VM settings.

> [tab] From the Volumes page
>
> 1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.
>
> 2\. Select the volume to attach and click **Attach to Instance**.
>
> ![Volumes page with annotated attach to Virtual Machine link](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/attach-volume.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=840b4d98390c0f573b68e7889326f404)
>
> 3\. Select the Virtual Machine from the **Choose Instance to attach to** dropdown.
>
> 4\. (Optional) Enter a value in the **Tag** field.
>
> ![Attach volume dialog with options to select Virtual Machine and add a tag](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/attach-volume-to-instance.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=c7ce253a8d0ff151c6a3aabcaecd258f)
>
> 5\. Click **Attach volume**.
>
> The volume has been attached to the Virtual Machine.

> [tab] From Virtual Machine settings
>
> 1\. In the Gcore Customer Portal, navigate to **Cloud** > **Virtual Instances**.
>
> 2\. Select the target Virtual Machine and click its name to open it.
>
> ![Virtual Machines tab with two created instances](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/cloud-instances.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=c89369d1f8d1148b7951c1c4277777aa)
>
> 3\. Open the **Volumes** tab.
>
> 4\. Click **Add Volume**.
>
> ![Volumes tab with Add volume button highlighted](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/attach-volume-instance-settings.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=7e6e8eac120624b0007f8b24d2be8fb0)
>
> 5\. Click **Select existing** to attach an existing volume to a Virtual Machine.
>
> A new volume can also be created here. Click **Create new** and follow [Create a volume](https://docs.gcore.com/cloud/virtual-instances/volumes/create-a-volume.md).
>
> 6\. Select the volume to attach to the Virtual Machine.
>
> 7\. (Optional) Enter a value in the **Tag** field.
>
> ![Add volume menu with options to add Virtual Machine and tags](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/add-volume-to-instance.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=58378bb4b7acafe5abae298fbfaa51ca)
>
> 8\. Click **Add Volume**.
>
> The volume has been attached to the Virtual Machine.

## Manage volumes

Volume management options depend on whether the target volume is boot or regular.

When many volumes exist, filter the list by name or UUID to locate a specific volume.

### Rename a volume

Both boot and regular volumes can be renamed:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the target volume.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-regular.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=57af9929b1237cfd95919324f7696466)

3\. Click **Rename**.

4\. Enter a new name.

5\. Select **Save** to apply the changes.

![Rename volume dialog](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/rename-volume.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=6f64713e63fe4b023093f6f0c494b111)

The volume has been renamed.

### Manage volume tags

Volume tags can be added during creation or managed later from the volume context menu:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the volume.

3\. Click **Tags**.

4\. Add, edit, or remove key-value tag pairs and save the changes.

### Detach a volume from a Virtual Machine

Only regular volumes can be detached. The boot volume cannot be detached from a Virtual Machine as long as the VM exists. To detach a boot volume, delete the VM first.

To detach a volume:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the target volume.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-attached.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=ccbbd1b77cccc0099ca941fb3e725520)

3\. Click **Detach**.

4\. In the confirmation dialog, click **Detach** again to confirm.

![Detach volume confirmation dialog](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/detach-volume-dialog.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=35425cdbbacacf9ab22888a99de2cb16)

The volume has been detached from the Virtual Machine.

> [!WARNING]
>
> Detaching a volume does not stop billing unless the volume is deleted. A detached volume can be attached to any Virtual Machine at any time.

### Resize a volume

Both boot and regular volumes can be resized:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the target volume.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-regular.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=57af9929b1237cfd95919324f7696466)

3\. In the **Resize volume** dialog that opens, the current volume size in GB is shown. Enter the new size.

4\. Click **Resize** to apply the changes.

![Dialog asking for a new volume size](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/resize-volume.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=32ce1b9124f3fbf15cc777c6a150780a)

The volume size has been changed.

> [!WARNING]
>
> When snapshots exist for a volume, increasing the size prevents a revert to the [latest snapshot](https://docs.gcore.com/cloud/virtual-instances/snapshots/take-a-snapshot-of-your-file-system.md#revert-a-volume-to-the-latest-snapshot). Only a new volume can be created from this volume's snapshot.

### Change volume type

**Retype** changes a Standard volume to High IOPS SSD, or a High IOPS SSD volume to Standard. The action is available for a regular volume and for a boot volume.

> [!NOTE]
>
> The volume can stay attached to the Virtual Machine. **Retype** is in the volume menu while the status is **In Use**, and the Virtual Machine keeps running.

To retype a volume:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the target volume.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-regular.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=57af9929b1237cfd95919324f7696466)

3\. Click **Retype**.

4\. Select the desired volume type and then click **Retype** to apply the updates.

![Dialog asking to select a new volume type](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/retype-volume.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=55a62eddafdb5c978ede4433550113c9)

The volume type has been changed.

When multiple volumes are attached to one Virtual Machine, use the `rsync` and `cp` utilities to migrate data between volumes within an operating system.

### Create an image from a bootable volume

An image can be created from a boot volume and used to create a new Virtual Machine.

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the volume to use as the image source.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-boot.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=46259b81c486fd1b5e8c3b7ecf3fe200)

3\. Select **Create Image**.

4\. Specify the image name.

5\. Select architecture.

6\. Click **Create Image**.

![Dialog to select image and and architecture](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/create-image.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=ff4442f1a8534b82ba6fc63982f97ce6)

Within a few minutes, the image will be created and available on the **Images** page.

### Delete volume

A regular volume that is not attached to a Virtual Machine can be deleted. Boot volumes cannot be deleted directly. They must be detached first, which requires deleting the Virtual Machine. When the VM is deleted, the boot volume is retained by default and can be reused to create a new Virtual Machine.

To delete a volume:

1\. In the Gcore Customer Portal, navigate to **Cloud** > **Storage**.

2\. Click the three-dot icon next to the volume to delete.

![Volumes tab with expanded settings menu](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/three-dot-menu-regular.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=57af9929b1237cfd95919324f7696466)

3\. Click **Delete**.

4\. Type "Delete" in the confirmation field.

5\. Click **Delete Volume**.

![Dialog asking to confirm volume deletion](https://mintcdn.com/gcore/sgf4_7UBAOp9SmxG/images/docs/cloud/virtual-instances/volumes/manage-a-volume/delete-volume.png?fit=max\&auto=format\&n=sgf4_7UBAOp9SmxG\&q=85\&s=db2db8624423a8970115c44f8773b8ac)

The volume has been removed from the Gcore Customer Portal.

> [!TIP]
>
> The **Group actions** button deletes multiple volumes at once. This option is available when at least one regular volume is not attached to a Virtual Machine.

## REST API

Attach, resize, detach, or delete an existing volume.

> [!NOTE]
>
> An [API token](https://docs.gcore.com/account-settings/api-tokens.md) is required, along with a [project ID](https://docs.gcore.com/api-reference/cloud/projects/list-projects.md) and a [region ID](https://docs.gcore.com/api-reference/cloud/regions/list-regions.md).

Open a bash terminal and set these as environment variables before running the examples:

```bash theme={null}
export GCORE_API_KEY="{YOUR_API_KEY}"
export GCORE_CLOUD_PROJECT_ID="{YOUR_PROJECT_ID}"
export GCORE_CLOUD_REGION_ID="{YOUR_REGION_ID}"
export VOLUME_ID="{VOLUME_ID}"
export INSTANCE_ID="{INSTANCE_ID}"
```

`VOLUME_ID` is the UUID of a volume created in [Create a volume](https://docs.gcore.com/cloud/virtual-instances/volumes/create-a-volume.md). `INSTANCE_ID` is required for attach and detach.

## Attach a volume

A volume attaches to one Virtual Machine at a time. Both must be in the same region. After attachment the operating system sees a new block device, `/dev/sdb`.

| Parameter | Required | Description |
| - | - | - |
| `instance_id` | Yes | UUID of the target Virtual Machine. |

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> client.cloud.volumes.attach_to_instance_and_poll(
>     os.environ["VOLUME_ID"],
>     instance_id=os.environ["INSTANCE_ID"],
> )
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cloud"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>
>     err := client.Cloud.Volumes.AttachToInstanceAndPoll(ctx, os.Getenv("VOLUME_ID"), cloud.VolumeAttachToInstanceParams{
>         InstanceID: os.Getenv("INSTANCE_ID"),
>     })
>     if err != nil {
>         log.Fatalf("attach volume: %v", err)
>     }
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X POST \
>   "https://api.gcore.com/cloud/v2/volumes/$GCORE_CLOUD_PROJECT_ID/$GCORE_CLOUD_REGION_ID/$VOLUME_ID/attach" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d "{\"instance_id\": \"$INSTANCE_ID\"}"
> ```
>
> The response is a task ID. Poll `GET /cloud/v1/tasks/` every 5 seconds until `state` is `FINISHED`. The volume status changes to `in-use`.

## Resize a volume

> [!WARNING]
>
> Wait a few minutes before resizing a newly created SSD Low-Latency volume.

Volume size can only be increased. Resizing works while the volume is attached to a running Virtual Machine.

| Parameter | Required | Description |
| - | - | - |
| `size` | Yes | New size in GiB. Must be greater than the current size. |

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> volume = client.cloud.volumes.resize_and_poll(os.environ["VOLUME_ID"], size=20)
> print(f"New size: {volume.size} GiB")
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "fmt"
>     "log"
>     "os"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cloud"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>
>     resized, err := client.Cloud.Volumes.ResizeAndPoll(ctx, os.Getenv("VOLUME_ID"), cloud.VolumeResizeParams{
>         Size: 20,
>     })
>     if err != nil {
>         log.Fatalf("resize volume: %v", err)
>     }
>     fmt.Printf("New size: %d GiB\n", resized.Size)
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X POST \
>   "https://api.gcore.com/cloud/v1/volumes/$GCORE_CLOUD_PROJECT_ID/$GCORE_CLOUD_REGION_ID/$VOLUME_ID/extend" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d "{\"size\": 20}"
> ```
>
> The response is a task ID. Poll `GET /cloud/v1/tasks/` every 5 seconds until `state` is `FINISHED`.

After resizing, extend the filesystem inside the operating system so it can use the new space. On ext4, run `resize2fs`. On XFS, run `xfs_growfs`.

> [!WARNING]
>
> If the volume has snapshots, resizing it prevents reverting to those snapshots. Only snapshots taken after the resize can be used. Reversion is described in [Take a snapshot](https://docs.gcore.com/cloud/virtual-instances/snapshots/take-a-snapshot-of-your-file-system.md#revert-a-volume-to-the-latest-snapshot).

## Detach a volume

Only a non-boot volume can be detached. Detaching keeps the data. The volume status returns to `available`, and the volume can be attached to another Virtual Machine in the same region.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> client.cloud.volumes.detach_from_instance_and_poll(
>     os.environ["VOLUME_ID"],
>     instance_id=os.environ["INSTANCE_ID"],
> )
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cloud"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>
>     err := client.Cloud.Volumes.DetachFromInstanceAndPoll(ctx, os.Getenv("VOLUME_ID"), cloud.VolumeDetachFromInstanceParams{
>         InstanceID: os.Getenv("INSTANCE_ID"),
>     })
>     if err != nil {
>         log.Fatalf("detach volume: %v", err)
>     }
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X POST \
>   "https://api.gcore.com/cloud/v2/volumes/$GCORE_CLOUD_PROJECT_ID/$GCORE_CLOUD_REGION_ID/$VOLUME_ID/detach" \
>   -H "Authorization: APIKey $GCORE_API_KEY" \
>   -H "Content-Type: application/json" \
>   -d "{\"instance_id\": \"$INSTANCE_ID\"}"
> ```
>
> The response is a task ID. Poll `GET /cloud/v1/tasks/` every 5 seconds until `state` is `FINISHED`.

## Delete a volume

Only a detached volume can be deleted. A boot volume cannot be deleted directly. It is retained when the Virtual Machine is deleted.

> [tab] Python SDK
>
> ```python theme={null}
> import os
>
> from gcore import Gcore
>
> client = Gcore()
> client.cloud.volumes.delete_and_poll(os.environ["VOLUME_ID"])
> ```

> [tab] Go SDK
>
> ```go theme={null}
> package main
>
> import (
>     "context"
>     "log"
>     "os"
>
>     gcore "github.com/G-Core/gcore-go"
>     "github.com/G-Core/gcore-go/cloud"
> )
>
> func main() {
>     client := gcore.NewClient()
>     ctx := context.Background()
>
>     err := client.Cloud.Volumes.DeleteAndPoll(ctx, os.Getenv("VOLUME_ID"), cloud.VolumeDeleteParams{})
>     if err != nil {
>         log.Fatalf("delete volume: %v", err)
>     }
> }
> ```

> [tab] curl
>
> ```bash theme={null}
> curl -X DELETE \
>   "https://api.gcore.com/cloud/v1/volumes/$GCORE_CLOUD_PROJECT_ID/$GCORE_CLOUD_REGION_ID/$VOLUME_ID" \
>   -H "Authorization: APIKey $GCORE_API_KEY"
> ```
>
> The response is a task ID. Poll `GET /cloud/v1/tasks/` every 5 seconds until `state` is `FINISHED`. Billing for the volume stops after deletion.

## Terraform

Attach, resize, retype, or delete an existing volume using the [`gcore_cloud_volume`](https://registry.terraform.io/providers/G-Core/gcore/latest/docs/resources/cloud_volume) resource.

## Attach to a Virtual Machine

Set `instance_id_to_attach_to` to attach the volume to a [Virtual Machine](https://docs.gcore.com/cloud/virtual-instances/create-an-instance.md). Both the volume and the Virtual Machine must be in the same region.

```hcl theme={null}
resource "gcore_cloud_volume" "example" {
  project_id               = var.project_id
  region_id                = var.region_id
  name                     = "data-volume"
  source                   = "new-volume"
  size                     = 10
  type_name                = "standard"
  instance_id_to_attach_to = var.instance_id
}
```

To detach, remove the `instance_id_to_attach_to` attribute and run `terraform apply`.

## Resize a volume

> [!WARNING]
>
> Wait a few minutes before resizing a newly created SSD Low-Latency volume.

Increase `size` and run `terraform apply`. Volume size can only be increased.

```hcl theme={null}
resource "gcore_cloud_volume" "example" {
  project_id = var.project_id
  region_id  = var.region_id
  name       = "data-volume"
  source     = "new-volume"
  size       = 20
  type_name  = "standard"
}
```

```bash theme={null}
terraform apply
```

## Change volume type

Change `type_name` and run `terraform apply`.

> [!WARNING]
>
> Changing `type_name` recreates the volume. The existing volume is deleted and a new one is created with a new ID. Detach the volume from any Virtual Machine before this change.

```hcl theme={null}
resource "gcore_cloud_volume" "example" {
  project_id = var.project_id
  region_id  = var.region_id
  name       = "data-volume"
  source     = "new-volume"
  size       = 20
  type_name  = "ssd_hiiops"
}
```

```bash theme={null}
terraform apply
```

## Delete a volume

Remove the resource block. Terraform deletes the volume on the next `terraform apply`.

```hcl theme={null}
# Remove or comment out this block:
# resource "gcore_cloud_volume" "example" {
#   name      = "data-volume"
#   source    = "new-volume"
#   size      = 20
#   type_name = "ssd_hiiops"
#   ...
# }
```

```bash theme={null}
terraform apply
```

## Import a volume

Import brings a volume that was created outside Terraform under management as code.

```hcl theme={null}
resource "gcore_cloud_volume" "example" {
  project_id = var.project_id
  region_id  = var.region_id
  name       = "data-volume"
  source     = "new-volume"
  size       = 20
  type_name  = "standard"
}
```

```bash theme={null}
terraform import gcore_cloud_volume.example '<project_id>/<region_id>/<volume_id>'
```
