> **For AI agents:** The documentation index is at [https://docs.digitalocean.com/llms.txt](https://docs.digitalocean.com/llms.txt). Markdown versions of pages use the same URL with `index.html.md` in place of the HTML page (for example, append `index.html.md` to the directory path instead of opening the HTML document). # How to Detach and Delete Volumes Volumes are network-attached block storage. You can use them with Droplets or Kubernetes clusters, move or resize them, and create snapshots at any time. To remove a volume from a Droplet, you can either: - [Detach the volume](#detach-a-volume-using-the-control-panel), which removes it from the Droplet, but keeps the volume and its data so you can reattach it to another Droplet at any time. - [Delete a volume](#delete-a-volume-using-the-control-panel), which permanently removes the volume and all of its data. This option cannot be undone, and you’re no longer billed for the volume. If you remove a volume from a running Droplet, you may lose data or cause errors on your Droplet. First, turn off the Droplet, or make sure it’s not writing to the volume. You can check whether the volume is in use by listing open files on the mount point with `lsof`. Then, [unmount your volume](https://docs.digitalocean.com/products/volumes/how-to/mount-unmount/index.html.md). ## Detach a Volume Using Automation You can detach volumes from Droplets via the DigitalOcean CLI or API. ### Detach a Volume via the CLI To detach a volume via the CLI, use `doctl compute volume-action detach` and provide the volume ID and Droplet ID. ## How to Detach a Volume Using the DigitalOcean CLI 1. [Install `doctl`](https://docs.digitalocean.com/reference/doctl/how-to/install/index.html.md), the official DigitalOcean CLI. 2. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with `doctl`. 3. Use the token to grant `doctl` access to your DigitalOcean account. ```shell doctl auth init ``` 4. Finally, run `doctl compute volume-action detach`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/compute/volume-action/detach/index.html.md) for more details: ```shell doctl compute volume-action detach [flags] ``` The following example detaches a volume with the UUID `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` from a Droplet with the ID `386734086`: ```shell doctl compute volume-action detach f81d4fae-7dec-11d0-a765-00a0c91e6bf6 386734086 ``` ### Detach a Volume via the API To detach a volume via the API, send a POST request to the volume actions endpoint with a detach action. ## How to Detach a Volume Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a POST request to [`https://api.digitalocean.com/v2/volumes/{volume_id}/actions`](https://docs.digitalocean.com/reference/api/reference/block-storage-actions/index.html.md#volumeActions_post_byId). ### cURL Using cURL: ```shell # Attach a Volume to a Droplet by ID curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -d '{"type": "attach", "droplet_id": 11612190, "region": "nyc1", "tags":["aninterestingtag"]}' \ "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions" # Remove a Volume from a Droplet by ID curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -d '{"type": "detach", "droplet_id": "11612190", "region": "nyc1"}' \ "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions" # Resize a Volume curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -d '{"type":"resize","size_gigabytes": 100, "region":"nyc1"}' \ "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions" ``` ### Go Using [Godo](https://github.com/digitalocean/godo), the official DigitalOcean API client for Go: ```go import ( "context" "os" "github.com/digitalocean/godo" ) func main() { token := os.Getenv("DIGITALOCEAN_TOKEN") client := godo.NewFromToken(token) ctx := context.TODO() // Attach a Volume to a Droplet by ID action, _, err := client.StorageActions.Attach(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 11612190) // Remove a Volume from a Droplet by ID // action, _, err := client.StorageActions.Detach(ctx, "7724db7c-e098-11e5-b522-000f53304e51") // Resize a Volume // action, _, err := client.StorageActions.Resize(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 100, "nyc1") } ``` ### Ruby Using [DropletKit](https://github.com/digitalocean/droplet_kit), the official DigitalOcean API client for Ruby: ```ruby require 'droplet_kit' token = ENV['DIGITALOCEAN_TOKEN'] client = DropletKit::Client.new(access_token: token) # Attach a Volume to a Droplet by ID client.volume_actions.attach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1' # Remove a Volume from a Droplet by ID # client.volume_actions.detach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1' ``` ### Python Using [PyDo](https://github.com/digitalocean/pydo), the official DigitalOcean API client for Python: ```python import os from pydo import Client client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN")) req = { "type": "attach", "droplet_id": 11612190, "region": "nyc1", "tags": [ "aninterestingtag" ] } resp = client.volume_actions.post_by_id(volume_id="7724db7c", body=req) ``` ## Detach a Volume Using the Control Panel To detach a volume, go to the [control panel](https://cloud.digitalocean.com/), in the left menu, click **Volumes Block Storage**, in the **Volumes** overview page, find the volume you want to detach, click **More**, and then click **Detach from Droplet** to open the confirmation window. Then, click **Confirm** to detach the volume. You can then [attach the volume to a different Droplet](https://docs.digitalocean.com/products/volumes/how-to/mount-unmount/index.html.md) as needed. If you detach an auto-mounted volume, you should also delete the corresponding systemd mount unit file from the Droplet, which is located at `/etc/systemd/system/mnt-volume_*.mount`. To do this, remove the file using `rm`, and then reload the systemd configuration with `systemctl daemon-reload`. After detaching a volume, you can access it from the **Volumes** overview page. You continue to be billed for the volume until you [delete it](https://docs.digitalocean.com/products/volumes/how-to/delete-detach/index.html.md#delete). ## Delete a Volume Using Automation You can delete volumes via the DigitalOcean CLI or API. ### Delete a Volume via the CLI To delete a volume via the CLI, use `doctl compute volume delete` and specify the ID or name of the volume you want to remove. ## How to Delete a Volume Using the DigitalOcean CLI 1. [Install `doctl`](https://docs.digitalocean.com/reference/doctl/how-to/install/index.html.md), the official DigitalOcean CLI. 2. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with `doctl`. 3. Use the token to grant `doctl` access to your DigitalOcean account. ```shell doctl auth init ``` 4. Finally, run `doctl compute volume delete`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/compute/volume/delete/index.html.md) for more details: ```shell doctl compute volume delete [flags] ``` The following example deletes a volume with the UUID `f81d4fae-7dec-11d0-a765-00a0c91e6bf6`: ```shell doctl compute volume delete f81d4fae-7dec-11d0-a765-00a0c91e6bf6 ``` ### Delete a Volume via the API To delete a volume via the API, send a DELETE request to the volume’s endpoint. ## How to Delete a Volume Using the DigitalOcean API 1. [Create a personal access token](https://docs.digitalocean.com/reference/api/create-personal-access-token/index.html.md) and save it for use with the API. 2. Send a DELETE request to [`https://api.digitalocean.com/v2/volumes/{volume_id}`](https://docs.digitalocean.com/reference/api/reference/block-storage/index.html.md#volumes_delete). ### cURL Using cURL: ```shell curl -X DELETE \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51" ``` ### Go Using [Godo](https://github.com/digitalocean/godo), the official DigitalOcean API client for Go: ```go import ( "context" "os" "github.com/digitalocean/godo" ) func main() { token := os.Getenv("DIGITALOCEAN_TOKEN") client := godo.NewFromToken(token) ctx := context.TODO() _, err := client.Storage.DeleteVolume(ctx, "7724db7c-e098-11e5-b522-000f53304e51") } ``` ### Ruby Using [DropletKit](https://github.com/digitalocean/droplet_kit), the official DigitalOcean API client for Ruby: ```ruby require 'droplet_kit' token = ENV['DIGITALOCEAN_TOKEN'] client = DropletKit::Client.new(access_token: token) client.volumes.delete(id: '7724db7c-e098-11e5-b522-000f53304e51') ``` ### Python Using [PyDo](https://github.com/digitalocean/pydo), the official DigitalOcean API client for Python: ```python import os from pydo import Client client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN")) resp = client.volumes.delete(volume_id="7724db7c") ``` ## Delete a Volume Using the Control Panel When you delete a volume, the volume and its contents are deleted. Deleting a volume is irreversible. To delete a volume, go to the [control panel](https://cloud.digitalocean.com/), in the left menu, click **Volumes Block Storage**, in the **Volumes** overview page, find the volume you want to delete, click **More**, and then click **Delete** to open the confirmation window. Then, click **Confirm** to delete the volume.