Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 35 ยท Storage and Databases

DigitalOcean Volumes: Block Storage for Droplets

Add extra disk space to a Droplet with Volumes block storage: create, attach, format, mount permanently with fstab, resize, snapshot and move data between servers safely.

A Droplet's boot disk is tied to its size, and it disappears with the Droplet. When you need more space, or data that should outlive any single server, use a Volume. A Volume is network-attached block storage: to the operating system it looks like an empty hard drive that you format and mount. This lesson covers the full life cycle and the traps to avoid.

What makes Volumes useful

  • Independent life cycle. A Volume exists on its own. Destroy the Droplet and the Volume (and its data) remains, ready to attach to another server.
  • Resizable. You can grow a Volume (from 1 GiB up to many TiB) without recreating it. Shrinking is not possible.
  • Snapshots. You can snapshot a Volume at any time for point-in-time copies.
  • Billed by size, not by use, and billed whether or not it is attached.

Limits to remember: a Volume attaches to one Droplet at a time and only to Droplets in the same region. It is block storage, so it is not a shared network file system; two servers cannot safely mount the same ext4 Volume simultaneously. For shared files use Spaces or your own NFS server.

flowchart LR
  V[("Volume<br/>100 GiB")] -- "attached to one Droplet" --> D1["web-1"]
  V -. "detach, then attach" .-> D2["web-2 (same region)"]
  V --> S["Snapshot"]

One Volume, one Droplet at a time, same region.

Creating and attaching

In the control panel choose Create, then Volumes: pick the size, region, and optionally a filesystem type (ext4 or XFS) so DigitalOcean formats it for you, and select the Droplet. With doctl:

Terminal
doctl compute volume create data-1 --region fra1 --size 100GiB \
  --fs-type ext4 --desc "app uploads"
doctl compute volume-action attach <volume-id> <droplet-id>
doctl compute volume list --format ID,Name,Size,Region,DropletIDs

If you let DigitalOcean format and mount it when creating through the panel, a mount point is created for you, typically /mnt/<volume_name> (for example /mnt/data_1). Otherwise do it by hand.

Formatting and mounting by hand

On the Droplet the Volume appears as a device. A stable path is provided under /dev/disk/by-id/:

Terminal
ls -l /dev/disk/by-id/ | grep scsi-0DO_Volume
# scsi-0DO_Volume_data-1 -> ../../sda

# 1. Format ONCE (this erases everything on the volume)
sudo mkfs.ext4 /dev/disk/by-id/scsi-0DO_Volume_data-1

# 2. Mount it
sudo mkdir -p /mnt/data-1
sudo mount -o defaults,nofail,discard,noatime /dev/disk/by-id/scsi-0DO_Volume_data-1 /mnt/data-1

# 3. Make it permanent across reboots
echo '/dev/disk/by-id/scsi-0DO_Volume_data-1 /mnt/data-1 ext4 defaults,nofail,discard,noatime 0 2' | sudo tee -a /etc/fstab

# 4. Check
df -h /mnt/data-1

Important details:

  • Format only once. Running mkfs on a Volume with data destroys it. Check with lsblk -f first; if a filesystem is already listed, skip step 1.
  • Use /dev/disk/by-id/... rather than /dev/sda, because device letters can change between boots.
  • The nofail option lets the Droplet boot even if the Volume is not attached, instead of hanging in emergency mode.
  • Test fstab with sudo mount -a before rebooting.

Resizing a Volume

  1. Increase the size in the panel or with doctl compute volume-action resize <id> --size 200 --region fra1.
  2. Grow the filesystem inside it: sudo resize2fs /dev/disk/by-id/scsi-0DO_Volume_data-1 for ext4 (or xfs_growfs /mnt/data-1 for XFS).

Growing the Volume without growing the filesystem gives you no extra space, a classic beginner mistake.

Moving a Volume to another Droplet

Terminal
sudo umount /mnt/data-1                 # stop services using it first
doctl compute volume-action detach <volume-id> <old-droplet-id>
doctl compute volume-action attach <volume-id> <new-droplet-id>
# on the new Droplet: mkdir and mount (no mkfs!)

Always unmount cleanly before detaching so data is flushed to disk.

Stand-in: fstab and capacity helpers

The Volume itself cannot be attached here. These stand-in programs generate the correct device path and fstab line from a volume name and estimate when you will run out of space.

Python Stand-in: build device path, mount point and fstab line

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Python Stand-in: when will the volume fill up?

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Performance and safety notes

  • Volumes are network storage, so latency is higher than a Droplet's local NVMe boot disk. Databases with heavy I/O may prefer a size with fast local disk or a managed database.
  • A Volume is not a backup. If you delete files, they are gone; if a bug corrupts the filesystem, so is the copy. Take snapshots on a schedule (Snapshots and backups) and keep copies elsewhere for critical data.
  • Encrypt sensitive data at the application layer or with LUKS if you need encryption beyond the platform's encryption at rest.
  • In Kubernetes, Volumes back PersistentVolumeClaims through the DigitalOcean CSI driver (Kubernetes chapter).

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How many Droplets can a Volume be attached to at the same time?

    A Volume is block storage attached to a single Droplet at a time, within its region.
  2. 2. You enlarge a Volume in the panel but df still shows the old size. What is missing?

    The block device is larger, but the filesystem must be extended to use the space.
  3. 3. Which fstab option lets the Droplet boot when the Volume is missing?

    nofail prevents a failed mount from blocking the boot.
  4. 4. Is a Volume a backup of your data?

    Deleting files or corrupting the filesystem affects the Volume as well; back it up separately.

Summary

  • Volumes are resizable, network-attached block devices that outlive Droplets, attach to one Droplet in the same region, and are billed by size.
  • Format once, mount with /dev/disk/by-id paths, add an fstab line with nofail, and test with mount -a.
  • After growing a Volume, grow the filesystem too.
  • Volumes are not backups: schedule snapshots.

Next: Spaces: S3-Compatible Object Storage