# How to Create and Set Up Volumes for Use with Droplets 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 create and use a new volume with a Droplet, you need to create the volume, and then format and mount it to prepare it for use. [Formatting and mounting is automatic by default](#format-mount) for Droplets with [supported operating systems](https://docs.digitalocean.com/products/droplets/details/images/index.html.md), but you can choose to format and mount manually. Volumes are created in the same region and project as the Droplet they are attached to. ## Create a Volume Using Automation You can create volumes using the DigitalOcean CLI (`doctl`) or the API. ### Create a Volume via the CLI When creating a volume via the CLI, you need to provide values for the `--region` and `--size` flags, which specify the datacenter where the volume is created and the size of the volume in gigabytes. You can optionally attach the volume to a Droplet at creation time by specifying the Droplet ID. Use [`doctl compute region list`](https://docs.digitalocean.com/reference/doctl/reference/compute/region/list/index.html.md) to view available regions. ## How to Create a Block Storage 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 create`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/compute/volume/create/index.html.md) for more details: ```shell doctl compute volume create [flags] ``` The following example creates a 4TiB volume named `example-volume` in the `nyc1` region. The command also applies two tags to the volume: ```shell doctl compute volume create example-volume --region nyc1 --size 4TiB --tag frontend,backend ``` ### Create a Volume via the API To create a volume via the API, send a POST request to the volumes endpoint. ## How to Create 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`](https://docs.digitalocean.com/reference/api/digitalocean//index.html.md#operation/volumes_create). ### cURL Using cURL: ```shell curl -X POST \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \ -d '{"size_gigabytes":10, "name": "example", "description": "Block store for examples", "region": "nyc1", "filesystem_type": "ext4", "filesystem_label": "example"}' \ "https://api.digitalocean.com/v2/volumes" ``` ### 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() createRequest := &VolumeCreateRequest{ Region: "nyc1", Name: "example", Description: "Block store for examples", SizeGigaBytes: 10, } volume, _, err := client.Storage.CreateVolume(ctx, createRequest) } ``` ### 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) volume = DropletKit::Volume.new( size_gigabytes: 10, name: 'Example', description: 'Block store for examples', region: 'nyc1' ) client.volumes.create(volume) ``` ### 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 = { "size_gigabytes": 10, "name": "ext4-example", "description": "Block store for examples", "region": "nyc1", "filesystem_type": "ext4", "filesystem_label": "ext4_volume_01" } resp = client.volumes.create(body=req) ``` ## Create a Volume Using the Control Panel To create a volume, go to the [control panel](https://cloud.digitalocean.com), in the left menu, click **Volumes Block Storage**, and then click **Add Volume** to open the **Add a volume** window. ![Add a volume window showing volume size options, Droplet selection, volume name, and automatic or manual format and mount settings.](https://docs.digitalocean.com/screenshots/volumes/add-a-volume.1fc3b59fd02d9613974802c0559d3607840cef1946d63dfddb92efafcf1e922a.png) Alternatively, create and attach a new volume as you create a new Droplet, from the [**Additional Storage** section of the **Create Droplets** page](https://docs.digitalocean.com/products/droplets/how-to/create/index.html.md#add-block-storage). Volumes you create this way have automatically generated names and are attached to the Droplet, so the **Select Droplet to Attach To** and **Name Volume** sections do not display from the Droplet create page. ### Choose a Volume Size Under the **SELECT VOLUME SIZE** section, either enter a specific size in gigabytes to see the pricing per month and per hour, or choose a set size. Some teams may be limited to creating volumes below a certain size. To access larger sizes, request an increase in the amount of available storage via [support](https://cloudsupport.digitalocean.com). Alternatively, you can [increase the size of a volume](https://docs.digitalocean.com/products/volumes/how-to/increase-size/index.html.md) after you create it. ### Select Droplet to Attach Under the **SELECT DROPLET TO ATTACH TO** section, click the field to open the dropdown menu, and then choose a Droplet you want to attach the volume to. Volumes are located in the same datacenter and project as their associated Droplets. See the [volumes availability page](https://docs.digitalocean.com/products/volumes/details/availability/index.html.md) for supported datacenter regions. ### Name the Volume Under the **NAME VOLUME** section, either use the automatically generated name, or enter a name for your volume. If you don’t change the volume name, the default name is based on the volume’s datacenter, like `/mnt/volume-nyc3-01`. ### Choose a Configuration A newly-created volume has no filesystem. Formatting the volume creates a filesystem and erases any existing data. You format a volume only once, when you first create it. Mounting a formatted volume makes its filesystem accessible to a Droplet, and you must mount the volume each time you attach it. Under the **CHOOSE CONFIGURATION OPTIONS** section, choose one of these options: - **Automatically Format & Mount**: Default configurations are automatically applied. Automatic mounting uses [systemd](https://www.freedesktop.org/software/systemd/man/systemd.mount.html) on supported distributions, with mount unit files at `/etc/systemd/system/mnt-volume_*.mount` and udev rules in `/etc/udev/rules.d/99-digitalocean-automount.rules`. On non-systemd distributions, automatic mounting uses `fstab` with the same options. Volumes mount automatically under `/mnt` using the options `defaults,nofail,discard,noatime`. **Note**: When creating mount points automatically, hyphens in volume names are replaced with underscores to match systemd mount unit naming behavior. This convention also applies on non-systemd distributions for consistency. You can change these settings later via SSH. Under the **Choose a filesystem** sub-section, select the filesystem you want to use for your volume, either **Ext4** or **XFS**. - Use **Ext4** (default option) for its stability, backwards compatibility, and mature support and tooling. - Use **XFS** if you need performance support for large data files. - **Manually Format & Mount**: We attach the volume, but you manually format and mount the volume. To manually format and mount your volume after you create your volume, SSH into your Droplet, which includes the SSH command with the Droplet’s IP address filled in. If you disabled `root` logins, you need to substitute the appropriate user for `root`. Then, [format your volume once, and then mount the volume](https://docs.digitalocean.com/products/volumes/how-to/mount-unmount/index.html.md). ### Create Volume After you set up your volume, click **Create Volume**, which then takes you to the **Volumes** overview page with your new volume listed. ![Volumes page showing a volume with its region and size, options to attach it to a Droplet.](https://docs.digitalocean.com/screenshots/volumes/overview.99c05b61f6a9b0e0eb8fca2389223b111f05e3e332444a7c734e26bec4a4f039.png) Once the volume is [formatted and mounted](https://docs.digitalocean.com/products/volumes/how-to/mount-unmount/index.html.md), it is ready to use. If a Droplet is in a volume-supported datacenter, you can view your volume from the Droplet’s **Volumes** section of its overview page, where you can create another volume and manage them, if needed. After creation, you can also [move volumes between Droplets](https://docs.digitalocean.com/products/volumes/how-to/mount-unmount/index.html.md) and [increase the size of volumes](https://docs.digitalocean.com/products/volumes/how-to/increase-size/index.html.md). ## Add, Move, or Delete Files After formatting and mounting the volume, it’s accessible on your Droplet at `/mnt/`. You can use this path to do any file operations you would do with a native volume, including creating, moving, or deleting files. You can run `ls /mnt` to get a list of attached volumes and their paths.