# How to Increase the Size of DigitalOcean Volumes Block Storage 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. If you need more storage space than your current volume provides, you can either [attach additional volumes to the same Droplet](https://docs.digitalocean.com/products/volumes/how-to/create/index.html.md) or [increase the size of an existing volume](#resize) and [expand the filesystem](#expand), so the operating system can use the additional space. Before resizing a volume, review the following limitations and recommendations: - **Volume sizes cannot be decreased.** Volume resizes are irreversible because filesystem data is not always stored sequentially. Shrinking a volume can result in data loss or corruption. To reduce storage size, [create a smaller volume](https://docs.digitalocean.com/products/volumes/how-to/create/index.html.md), then transfer the data using a tool such as [SnapShooter](https://docs.digitalocean.com/products/snapshooter/index.html.md) or `rsync`. - **Take a snapshot before resizing.** Filesystem changes can result in data loss if interrupted. We recommend [taking a snapshot](https://docs.digitalocean.com/products/snapshots/how-to/snapshot-volumes/index.html.md) before resizing. After confirming the resize is successful, you can delete the snapshot. Before resizing the volume, unmount the volume using the `umount` command to prevent data corruption: ```shell sudo umount /mnt/use_your_mount_point ``` ## Resize the Volume Using Automation You can resize a volume using the DigitalOcean CLI (`doctl`) or the API. ### Resize the Volume via the CLI When resizing a volume via the CLI, you must specify the volume ID and the new size in gigabytes. The new size must be larger than the current size. ## How to Resize a 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-action resize`. Basic usage looks like this, but you can [read the usage docs](https://docs.digitalocean.com/reference/doctl/reference/compute/volume-action/resize/index.html.md) for more details: ```shell doctl compute volume-action resize [flags] ``` The following example resizes a volume with the UUID `f81d4fae-7dec-11d0-a765-00a0c91e6bf6` to 120 GiB in the `nyc1` region: ```shell doctl compute volume-action resize f81d4fae-7dec-11d0-a765-00a0c91e6bf6 --size 120 --region nyc1 ``` ### Resize the Volume via the API To resize a volume via the API, send a POST request to the volume actions endpoint and set: - `type` to `resize`. - `size_gigabytes` to the desired size in GiB. ## How to Resize 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/{volume_id}/actions`](https://docs.digitalocean.com/reference/api/digitalocean//index.html.md#operation/volumeActions_post_byId). ### cURL Using cURL: ```shell # 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](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() // 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](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) # 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 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 = { "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 To resize the volume using the DigitalOcean Control Panel, go to the [Volumes section of the Control Panel](https://cloud.digitalocean.com/volumes). Find the volume you want to resize, click the **More** dropdown menu on the right, and then select **Increase size**. In the **Increase volume size** window, select or enter a new size that’s at least 1 GB larger than the current size (for example, greater than 100 GB if the volume is currently 100 GB). Volume size increases are irreversible. Then, click **Resize volume**. After the resize completes, [expand the filesystem](#expand). ## Expand the Filesystem After resizing the volume, you need to expand the filesystem. Resizing increases the disk size, but the filesystem doesn’t automatically grow. You must expand the filesystem manually to use the additional space. First, identify the filesystem type using the `df -T` command: ```shell df -T /mnt/your_mount_point ``` **Warning**: Volumes are unpartitioned by default. If you manually partitioned your volume when creating it, [expand the last partition before expanding the filesystem](https://docs.digitalocean.com/products/volumes/how-to/expand-partitions/index.html.md). ## Expand Ext4 filesystems For unpartitioned volumes using Ext4, pass the `/dev/disk/by-id` volume identifier to `resize2fs`: ```shell sudo resize2fs /dev/disk/by-id/scsi-0DO_example ``` `resize2fs` reports the new filesystem size in blocks. The final line confirms the filesystem has successfully expanded. ```text 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 ... The filesystem on /dev/disk/by-id/scsi-0DO_example is now 131072000 (4k) blocks long. ``` ## Expand XFS filesystems For unpartitioned volumes using XFS, pass the mount point to `xfs_growfs`: ```shell sudo xfs_growfs /mnt/your_mount_point ``` The final line from the output confirms that the filesystem has grown to use the additional space. ```text meta-data=/dev/sda isize=512 agcount=4, agsize=32768000 blks ... 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`, ensure the volume is attached and mounted, then retry the command. ## Verify the New Size First, confirm the updated size with the `df -h` command: ```shell df -h -x tmpfs -x devtmpfs ``` The `Size` column reflects the expanded volume capacity: ```text 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 recognize the new size. If the updated size does not appear, reboot your Droplet. If the reported size doesn’t match your expectations, see [why filesystem tools may report your volume as smaller than expected](https://docs.digitalocean.com/support/why-is-my-resized-volume-smaller-than-i-expected/index.html.md).