Question

Create Volume in detached state

When creating a Digitalocean Volume, it is required to specify a droplet to attache the volume to. Is it possible to instead create a standalone Volume, and attach it to a droplet at a later stage?


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi,

You can create detached volume with DO API. I tested it using both curl and Ruby. Let’s focus on curl because it is usually installed by default on most of Linux distros. ####Prerequisites####

1. You must have curl installed. To check if you have curl installed run following command

curl --version

If you have it installed, you will get the response like that:

Output
curl 7.29.0 (x86_64-redhat-linux-gnu) libcurl/7.29.0 NSS/3.53.1 zlib/1.2.7 libidn/1.28 libssh2/1.8.0 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smtp smtps telnet tftp Features: AsynchDNS GSS-Negotiate IDN IPv6 Largefile NTLM NTLM_WB SSL libz unix-sockets

If you do not have it installed, you can install it with your distro’s standard package manager. Two examples below:

CentOS 7
sudo yum install curl
Ubuntu 20.04
sudo apt update && sudo apt install curl

2. You must have DO Personal Access Token set up. If you do not have it, go to API section in DO control panel and generate new token accordingly to the DO tutorial.

Important
Copy your new personal access token. It is visible just after its creation. 
Keep it secret !!!

####Creating a detached volume####

I am using an example from DO’s API documentation. To create a detached volume, run the command below. But before you will do it, customize its parameters. The parameters are well described in previously mentioned DO’s API documentation, however, I am highlighting some of them:

  • Bearer is your Personal Access Token
  • size_gigabytes is a volume size
  • name is a volume name you will see in DO control panel; you may use it for mounting the volume to your droplet
  • region is a slug identifier for a region where your volume will be created; bear in mind that you can attach a volume to the droplets located in the same datacenter
  • filesystem_type - you provide it if you want to have your new volume automatically formatted to specified filesystem. Currently available options are ext4 and xfs
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer 123456789abcdef1234567890abcdef1234567890abcdef" -d '{"size_gigabytes":10, "name": "example", "description": "Volume for testing", "region": "nyc1", "filesystem_type": "ext4", "filesystem_label": "example"}' "https://api.digitalocean.com/v2/volumes"

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.