Attaching and mounting block storage volumes on DigitalOcean is surprisingly easy, but the real magic is how it lets you scale your storage independently of your compute instances.

Let’s see it in action. Imagine you have a Droplet running a web server, and it’s running out of disk space for user uploads. Instead of resizing the Droplet (which is a disruptive operation), you can just add a new Block Storage volume.

First, in the DigitalOcean control panel, you’d navigate to "Storage" and then "Block Storage." Click "Create Block Storage Volume." You’ll pick a region (ideally the same as your Droplet for low latency), give it a name (like my-app-uploads), and choose a size. For a 100GB volume, you’d select "100 GB."

Once created, you’ll see it in the list. Now, click on the volume, and you’ll find an "Attach to Droplet" button. Select your web server Droplet from the dropdown. DigitalOcean handles the networking and makes the raw block device available to your Droplet’s operating system.

On the Droplet itself, you’ll need to log in via SSH. The first time you attach a volume, it won’t be automatically mounted. You need to format it and then mount it.

To see the new device, run:

lsblk

You’ll likely see a new device, something like vdb or sdc, depending on how many disks your Droplet already has. Let’s assume it’s vdb.

Next, you need to format this new volume with a filesystem. ext4 is a common and robust choice:

sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/vdb

The -m 0 reserves no space for the super-user, and the discard option is important for SSD-backed volumes as it enables TRIM, which helps maintain performance over time by informing the underlying storage about deleted blocks.

Now, create a mount point. This is just an empty directory where the contents of your new volume will appear:

sudo mkdir -p /mnt/my_uploads

Finally, mount the volume:

sudo mount -t ext4 /dev/vdb /mnt/my_uploads

To make this mount persistent across reboots, you need to add an entry to /etc/fstab:

echo '/dev/vdb /mnt/my_uploads ext4 defaults,nofail,discard 0 2' | sudo tee -a /etc/fstab

The nofail option is crucial here; it prevents your Droplet from failing to boot if the volume is somehow unavailable. The discard option again ensures TRIM is enabled for the mounted filesystem.

Now, any files written to /mnt/my_uploads will be stored on your separate Block Storage volume. You can verify it’s mounted and see its capacity with:

df -h

You should see /dev/vdb mounted on /mnt/my_uploads with the size you provisioned.

The real power here is that you can detach this volume from one Droplet and attach it to another. This is invaluable for migrations, disaster recovery, or simply upgrading your Droplet without touching your data. Just ensure the nofail and discard options are used in /etc/fstab for robustness.

The next step in managing storage is often understanding how to snapshot these volumes for backup purposes.

Want structured learning?

Take the full Digitalocean course →