How to Delete Volumes
Validated on 2 Oct 2019 • Last edited on 8 Jul 2024
formatting
Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets, create disk images of them, and resize them at any time.
To remove a volume from a Droplet, you can either detach the volume or delete the volume.
Detaching a volume removes the volume from its current Droplet. You can attach the volume and all of its contents to a different Droplet as needed.
Deleting a volume permanently destroys the volume and its contents. This action cannot be reversed.
Delete a Volume Using Automation
Before deleting a volume, unmount it to prevent data loss.
How to Delete a Volume Using the DigitalOcean CLI
Install doctl
,
the DigitalOcean command-line tool.
Create a personal access token
and save it for use with doctl
.
Use the token to grant doctl
access to your
DigitalOcean account.
doctl auth init
Finally, run doctl compute volume delete
. Basic usage looks like
this, but you can read the usage docs
for more details :
doctl compute volume delete <volume-id> [flags]
The following example deletes a volume with the UUID f81d4fae-7dec-11d0-a765-00a0c91e6bf6
:
doctl compute volume delete f81d4fae-7dec-11d0-a765-00a0c91e6bf6
How to Delete a Volume Using the DigitalOcean API
Create a personal access
token and save it for use with the API.
Send a DELETE request to
https://api.digitalocean.com/v2/volumes/{volume_id}
cURL
Using cURL:
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 , the
official DigitalOcean V2 API client for 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 ,
the official DigitalOcean V2 API client for 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
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
Before deleting a volume, unmount it to prevent data loss.
You can delete a volume from the volume’s More menu, which is available on the account-level Volumes page .
When you select Delete , a window to confirm the deletion opens.
When you delete a volume, the volume and its contents will be completely deleted. This action is irreversible.
Click Confirm to delete the volume.