How to Increase the Size of DigitalOcean Volumes Block Storage

Volumes are network-based block devices that provide additional data storage for Droplets. You can move them between Droplets, create disk images of them, and resize them at any time.


If you need more storage space than your current volume provides, you can attach additional volumes to the same Droplet or expand the size of a current volume.

Increasing the size of a volume has two steps:

  1. Resize the volume to make its disk larger.
  2. Expand the filesystem on the volume to use the new space, then reboot your Droplet if necessary.

Considerations Before Resizing

  • You cannot decrease the size of a volume. In other words, volume resizes are irreversible.

    Data is not always sequentially written in memory, so reducing the available space would risk data loss and filesystem corruption. To decrease the size of a volume, create a smaller volume and transfer the contents of an existing volume to it using a tool like SnapShooter or rsync.

  • We strongly recommend taking a snapshot of the volume before resizing.

    Any changes to a filesystem can lead to data loss if something goes wrong. We strongly recommend backing up the volume’s data before resizing. If you use snapshots, you can delete the snapshot after confirming that the resize was successful.

Resize the Volume Using Automation

Before detaching a volume, unmount it to avoid data loss.

How to Resize a Volume Using the DigitalOcean CLI
  1. Install doctl, the DigitalOcean command-line tool.

  2. Create a personal access token and save it for use with doctl.

  3. Use the token to grant doctl access to your DigitalOcean account.

              doctl auth init
              
  4. Finally, run doctl compute volume-action resize. Basic usage looks like this, but you can read the usage docs for more details:

                doctl compute volume-action resize <volume-id> [flags]
              

    The following example resizes a volume with the UUID f81d4fae-7dec-11d0-a765-00a0c91e6bf6 to 120 GiB in the nyc1 region:

                  doctl compute volume-action resize f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --size 120 --region nyc1
                

To resize a volume using the API, use the volume actions endpoints and set the type field to resize and the size_gigabytes field to the number of GiB you want the volume to be.

How to Resize a Volume Using the DigitalOcean API
  1. Create a personal access token and save it for use with the API.

  2. Send a POST request to https://api.digitalocean.com/v2/volumes/{volume_id}/actions

    cURL

    Using cURL:

                    # Attach a Volume to a Droplet by ID
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type": "attach", "droplet_id": 11612190, "region": "nyc1", "tags":["aninterestingtag"]}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
    
    # Remove a Volume from a Droplet by ID
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type": "detach", "droplet_id": "11612190", "region": "nyc1"}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
    
    # Resize a Volume
    curl -X POST \
      -H "Content-Type: application/json" \
      -H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
      -d '{"type":"resize","size_gigabytes": 100, "region":"nyc1"}' \
      "https://api.digitalocean.com/v2/volumes/7724db7c-e098-11e5-b522-000f53304e51/actions"
                  

    Go

    Using Godo, the official DigitalOcean V2 API client for Go:

                    import (
        "context"
        "os"
    
        "github.com/digitalocean/godo"
    )
    
    func main() {
        token := os.Getenv("DIGITALOCEAN_TOKEN")
    
        client := godo.NewFromToken(token)
        ctx := context.TODO()
    
      // Attach a Volume to a Droplet by ID
        action, _, err := client.StorageActions.Attach(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 11612190)
    
      // Remove a Volume from a Droplet by ID
      // action, _, err := client.StorageActions.Detach(ctx, "7724db7c-e098-11e5-b522-000f53304e51")
    
      // Resize a Volume
      // action, _, err := client.StorageActions.Resize(ctx, "7724db7c-e098-11e5-b522-000f53304e51", 100, "nyc1")
    }
                  

    Ruby

    Using DropletKit, the official DigitalOcean V2 API client for Ruby:

                    require 'droplet_kit'
    token = ENV['DIGITALOCEAN_TOKEN']
    client = DropletKit::Client.new(access_token: token)
    
    # Attach a Volume to a Droplet by ID
    client.volume_actions.attach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1'
    
    
    # Remove a Volume from a Droplet by ID
    # client.volume_actions.detach(volume_id:'7724db7c-e098-11e5-b522-000f53304e51', droplet_id: 11612190, region: 'nyc1'
                  

    Python

                    import os
    from pydo import Client
    
    client = Client(token=os.environ.get("DIGITALOCEAN_TOKEN"))
    
    req = {
      "type": "attach",
      "droplet_id": 11612190,
      "region": "nyc1",
      "tags": [
        "aninterestingtag"
      ]
    }
    
    resp = client.volume_actions.post_by_id(volume_id="7724db7c", body=req)
                  

Resize the Volume Using the Control Panel

After you create a backup of the volume, you can increase the volume’s size in the control panel. From the volume’s More menu, choose Increase size.

Volumes more menu

In the window that opens, select a new size for the volume. You can choose any size at least 1 GB larger than the volume’s current size.

Increase volume size window

Click Resize volume to change the volume to the selected size.

Expand the Filesystem

To use the additional space, you need to expand the volume’s filesystem. You can check which kind of filesystem is on the volume with df -T /mnt/your_mount_point.

Warning
Volumes are unpartitioned by default, but if you manually partitioned your volume when you created it, you need to expand the final partition before expanding the filesystem.

For unpartitioned volumes using the ext4 filesystem, pass the /dev/disk/by-id volume identifier to resize2fs:

sudo resize2fs /dev/disk/by-id/scsi-0DO_example

The output looks like this:

resize2fs 1.42.13 (17-May-2015)
Filesystem at /dev/disk/by-id/scsi-0DO_example is mounted on /mnt/volume-example; on-line resizing required
old_desc_blocks = 25, new_desc_blocks = 32
The filesystem on /dev/disk/by-id/scsi-0DO_example is now 131072000 (4k) blocks long.

For unpartitioned volumes using the XFS filesystem, pass the mount point to the xfs_growfs tool:

sudo xfs_growfs /mnt/your_mount_point

The output looks like this:

meta-data=/dev/sda               isize=512    agcount=4, agsize=32768000 blks
        =                       sectsz=512   attr=2, projid32bit=1
        =                       crc=1        finobt=1 spinodes=0
data     =                       bsize=4096   blocks=131072000, imaxpct=25
        =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=64000, version=2
        =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 131072000 to 157286400

If you receive the error open: No such file or directory while opening /dev/disk/by-id/scsi-0DO_example, make sure that the volume is mounted and then retry the command.

Verify that the larger filesystem is available with df:

df -h -x tmpfs -x devtmpfs

The output of df looks like this:

    
        
            
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        20G  1.1G   18G   6% /
/dev/sda        197G   60M  187G   1% /mnt/volume-nyc1-01

        
    

Some operating systems require a reboot to see the volume’s new size. If you do not see the volume’s new size, reboot your Droplet.

If the size or available space doesn’t match what you expected, read our support article on why filesystem tools may report your volume as smaller than expected.