Adding Volume Storage to Digital Ocean Droplet
Published June 11, 2020
I use Digital Ocean for all of my server side projects. Lately I have been having some random issues start to pop up, and the culprit has always been disk space filling up.
Digital Ocean offers Volume storage you can attach to your droplets, so you can add more space without upgrading RAM and CPU. Its like adding a USB to a computer. Here are my steps to troubleshoot and add volume storage. Note that I'm not a server guy, I could be wildly wrong, but it works for me.
First step, ssh into your server and run this command. It checks filesystem usage and percentages. As you can see below in my screenshot, I'm using 100% of
/dev/vda1, not good. Another command I use is with the
—max-depth 1 flag. It shows the specific sizes of that directory. Very helpful to track down large log files or culprits.
sudo du -h --max-depth 1
So I'm out of disk space and I need to add more. This is where Digital Ocean Volumes comes in. Go into your digital ocean dashboard, click on
Create, and then choose Volume. Choose however large of size you need, choose which droplet to attach to, and then click on
After it creates the new volume, it will bring up a list of commands and instructions on what to do next. Most of these we will follow with a few modifications.
Since I want to continue to use my home directory for my sites, the basic process will go like this.
- Format our new volume so we can actually store files on it
- Rename my current home directory.
- Create a new mount point (directory) for that volume. In my case, I want it to be my home directory.
- Mount the new volume to the new user home directory
- Clone permissions from old home directory and remove all content from old directory
- Move all content from the previous home directory into the new
Step 1. Format new volume
Digital Ocean will give you this command after creating volume. If you accidentally closed it, just find your new volume and click on the down arrow and click on
sudo mkfs.ext4 /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01
Step 2. Rename your desired directory
I want to continue to use my
/home/forge directory. I will rename
/home/forge-backup so I can mount my new volume to
mv /home/forge /home/forge-backup
Step 3. Create a mount point for the new volume
This is where the new volume will be mounted. I want to continue to use /home/forge, so thats what I will name my new mount point.
mkdir -p /home/forge
Step 4. Mount the new volume & update fstab
Now that we have our new directory created, lets mount our new volume to this directory. Make sure to replace
/home/forge with your new directory.
mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /home/forge
Now change fstab so the volume will be mounted after reboot. Again, make sure to replace
/dev/disk/by-id/scsi-0D0_Volume_volume-nyc1-01 with your own values
echo '/dev/disk/by-id/scsi-0DO_Volume_volume-nyc1-01 /home/forge ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
After the fstab is updated, mount the drive (or reboot according to digital ocean)
sudo mount -a
df -h again, and we should see our new volume attached and where its mounted on. As you can see, our new volume,
/dev/sda, is mounted on
/home/forge and has 47G available
Step 5. Update Permissions
Now lets update permissions from our old forge directory to our new
sudo chown -R --reference=/home/forge-backup /home/forge
sudo chmod -R --reference=/home/forge-backup /home/forge
Step 6. Move content into new folder
Now that we are ready to go with our new volume attached, we can move all of our website data into our new folder. Add
-v flag to the command to see the output as it moves files and folders.
mv /home/forge-backup/* /home/forge/
Once its done moving, browse around in your new /home/forge directory and make sure everything looks right. If everything was moved over successfully, you can remove the old
rm -rf forge-backup/
df -h again to see new disk space and availability.
We have successfully added volume storage to our digital ocean droplet and we don't have strange error messages anymore. Go us!