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?
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!
Accepted Answer
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:
Outputcurl 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:
sudo yum install curl
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.
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:
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"
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
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
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.