We hope you find this tutorial helpful. In addition to guides like this one, we provide simple cloud infrastructure for developers. Learn more →

An Introduction to DigitalOcean Block Storage

UpdatedMarch 30, 2018 197.9k views DigitalOcean Block Storage Storage Product Documentation

Introduction

DigitalOcean's Block Storage allows you to create and attach additional storage volumes to your DigitalOcean Droplets. Volumes are an independent resource that can be moved from one Droplet to another within the same datacenter. Attached volumes act like locally connected storage drives, allowing you to manage them with the same tools and techniques.

Block Storage is useful when you need more space but do not need the additional processing power or memory that a larger Droplet would provide. Volumes can be created, destroyed, or expanded as your needs change, simplifying initial planning around your storage requirements.

Since Block Storage is not a specialized resource, it can be used for just about anything that would benefit from additional disk space. Examples include:

  • As the document root or media uploads directory for a web server
  • To house database files for a database server
  • As a target location for backups
  • As expanded storage for personal file hosting platforms like ownCloud
  • As components for building more advanced storage solutions, like RAID arrays

With these points in mind, let's take a look at how to use DigitalOcean Block Storage.

Block Storage Volumes at a Glance

  • Price: Volumes are charged at a rate of $0.10 per GB per month. For example, if you created a 100GB volume, you would be charged an additional $10 per month. A volume is billed in hourly increments from the moment it is created until the time of deletion, just like Droplets.
  • Storage media: Like Droplets, block storage volumes are backed by SSDs.
  • Encryption: Block Storage volumes are encrypted using the LUKS (Linux Unified Key Setup) specification. The entire storage cluster is encrypted, which ensures that snapshots of volumes are also encrypted at rest.
  • Redundancy: Block Storage stores data on hardware that is separated from the Droplet and replicated multiple times across different racks, reducing the chances of data loss in the event of hardware failure.
  • Available sizes: Storage volumes can be created in sizes ranging from 1GB to 16TB.
  • Region Support: Currently, volumes are available in NYC1, NYC3, SFO2, FRA1, SGP1, TOR1, BLR1, LON1, and AMS3. Volumes can be moved freely between Droplets within a region and migrated to new regions using snapshots.

  • Limits:

    • Volumes cannot be renamed.
    • A volume can only be attached to one Droplet at a time. However, up to seven volumes can be attached to a single Droplet.
    • Volumes are not included in Droplet backups.

Note: The NYC3 region contains both block storage-capable hardware and legacy hardware that does not yet support attaching block storage volumes. If your Droplet is placed on legacy hardware, you will be unable to attach a volume without migrating to a new server.

To guarantee that your Droplet will be able to use block storage in NYC3, attach a volume during the Droplet creation process. If you don't need it right away, you can detach or destroy it and add a volume later.

Creating and Attaching New Volumes

You can create and attach new volumes in four main contexts:

When Creating New Droplets
You can create and attach a new volume or attach an existing volume at the same time you create a Droplet in the Add Block Storage section. When you choose to add a volume, the selection of regions for the Droplet will be automatically limited to those regions where block storage is available.

Screenshot of Add Block Storage section

From the Create Menu
You can create a new volume and attach it to an existing Droplet at any time from the Create menu.

Screenshot of Create menu

On Existing Droplets
When you've already created a Droplet and it is located in a region with block storage support, you can create and manage volumes on its Volumes page:
Screenshot of the Volumes tab

From the Droplets Page
You can manage all the volumes associated with your account by following the Droplets link in the main navigation and selecting the Volumes tab:

Screenshot of the Droplets page

No matter how you create a new volume, before it's ready for use for the first time, you'll need to format and mount it.

Format and Mount Automatically

You can choose to automatically format and mount a volume for first-time use on the following images:

Linux distributions:

  • Ubuntu
  • Fedora
  • Debian 8+
  • CentOS

Container Distributions:

  • Fedora Atomic

FreeBSD, CoreOS, RancherOS, and One-click apps do not support automatic formatting and mounting.

Screenshot of the Add volume screen

When auto-mounting is available, it is selected by default. Otherwise, it will be greyed out and the manual option will be selected. Ext4, popular because of its stability, backwards compatibility and mature support and tooling, is selected as the default filesystem. You can also choose XFS, which specializes in performance for large data files.

The volume is auto-mounted with the defaults,nofail,discard,noatime options into the /mnt directory, using the same commands and options that are provided for manual formatting and mounting.

Format and Mount Manually

All volumes can be manually formatted and mounted. Droplet-specific directions are available in the volume's More menu under Config instructions.

Screenshot of Volume More menu

These customized directions have three parts that are ready to cut and paste into a terminal from your local machine:

  1. SSH to your Droplet: The SSH command with the Droplet's IP address filled in. Note that if you've disabled root logins or are working with CoreOS, FreeBSD, or RancherOS, you'll need to substitute the appropriate user for root in the SSH command.

  2. Format the volume: One time only: These directions are for an Ext4 filesystem with the Droplet's IP address and the SCSI ID of the volume pre-filled. Generally, this is a one-time-only task; when you format a volume it destroys all existing data. If you prefer, you can choose to use a different file system. You can use the same commands to format the volume with XFS by changing mkfs.ext4 to mkfs.xfs. For other filesystems and a detailed explanation of formatting and mounting volumes, see How To Partition and Format DigitalOcean Block Storage Volumes in Linux and How To Partition and Format Storage Devices in Linux. Note that DigitalOcean volumes have better performance and are easier to move and resize if they are not partitioned.

  3. Mount the volume: These commands create a mount point, mount the volume, and set the volume to automatically mount when you reboot. The specific SCSI ID of the volume is pre-filled.

Once these steps are complete, the volume will be ready to use.

Unmounting Volumes

When resizing or detaching a volume, unmounting it first can protect data integrity by ensuring the volume isn't being actively written to. To unmount a volume:

Use df to list mount points if you need to:

  • sudo df --human-readable --print-type

The volume mount point will look something like:

Output
Filesystem Type Size Used Avail Use% Mounted on . . . /dev/sda ext4 99G 60M 94G 1% /mnt/volume-sfo2-01 . . .

Locate the mount point for your volume and substitute it in the command below to unmount it:

  • sudo umount --verbose /mnt/mount_point

If it's busy, the command will provide feedback similar to:

Output
umount: /mnt/mount_point: target is busy (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1).)

If the volume is safe to unmount, it will return:

  • umount: /mnt/mount_point unmounted

With the volume unmounted, you can safely proceed to resize or detach it.

Resizing Volumes

One major benefits of volumes is that you can increase their size without powering down the Droplet.

To do this, you will:

  • Increase the size in the Control Panel by opening the volume's More menu, choosing Resize, and selecting the new size.
  • Log into the Droplet
  • Make sure the volume is not being written to by unmounting it or powering down the Droplet.
  • If the volume was partitioned, adjust the partition table
  • Expand the filesystem on the Droplet.

Note that when a volume is unformatted, you can both increase and decrease its size. When it is formatted, however, you can only increase the size because of the high risk of data loss or corruption. How To Increase the Size of a DigitalOcean Block Storage Volume provides detailed instructions for resizing.

Moving Volumes: Attaching and Detaching

Another benefit of a block storage volume is being able to move it from one Droplet to another. A volume can only be attached to one Droplet at a time, so to move it, you'd first detach it if needed, then attach it to the new Droplet and mount it. This can all be managed from the Volumes page:

An Attach to a Droplet link appears in the Droplet column if a volume isn't attached.

When it is attached, information about the Droplet appears in the Droplet column and a Detach link is available in the More menu.

Screenshot of one attached  and one detached volume on the Volumes page

Attaching

To attach an unattached volume, click the link. Search and select the Droplet you want to connect to. Note that Droplets in other regions are visible but are greyed out and cannot be selected. Droplets in the same region as the volume are darker and you can choose one of them to attach to.

Once you've attached the volume to a new Droplet, you will need to mount it again. You can revisit the Config instructions and follow the mount directions, but DO NOT format the volume or you will destroy all existing data.

Detaching

To detach a volume:

  1. Make sure the volume is not being written to by unmounting it or powering down the Droplet.
  2. Then, open the volume's More menu and choose Detach.

Once the volume is detached, it can be attached and configured on a new Droplet in the same region.

Moving a Volume to a New Region with Snapshots

Snapshots allow you to make exact copies of volume. They're ideal for on-demand backups or to make a volume available in a different region.

To use the volume in a different region, you can take a snapshot of it and use that snapshot to create a new volume in the desired region. An Introduction to DigitalOcean Snapshots provides more detail on how to take volume snapshots and create new volumes based on them.

Note: Volumes are not included in weekly DigitalOcean backups.

Deleting Volumes

To delete a volume, locate it on the account-level Volumes page or the Volumes page for an individual Droplet, open its More menu, and click Delete. This is permanent and cannot be reversed.

Next Steps

In this tutorial we've given an overview of how to create, format, mount, attach, detach, snapshot, and delete DigitalOcean block storage volumes.

The DigitalOcean API

The DigitalOcean API can also be used for Block Storage management tasks. While using the API is out of scope for this guide, you can learn more about how to control your storage resources programmatically by viewing our API documentation.

doctl: DigitalOcean's Official Command Line Tool

An alternative to using DigitalOcean's API directly is to use doctl, the DigitalOcean command line client. Block Storage volumes can be created, deleted, and managed with doctl in much the same way as other DigitalOcean resources. You can find out more in the guide How To Work with DigitalOcean Block Storage Using Doctl.

80 Comments

Creative Commons License