How to resize your DigitalOcean droplet
I didn’t think I had to ask this question, right before clicking the “Resize” button, neither did I find a simple-to-understand explanation of what to do. So let me share what I learned.
TL;DR
- Turn off droplet
- Resize it in the DO interface & turn back on
- Launch console
- Use
parted
&print
to know the number of partition to resize - Add more space using
resizepart
- Resize using
resize2fs
- Reboot
How I did it
Seems easy enough, right. Turn off the droplet first. No prob. After a 2–3 minutes, the resizing is finished and I turn it back on.
Result: 500 server error. You kidding me?
Right, my server is down which I can’t really afford it to be. Quickly, let’s open the console via DO by clicking on Access > Launch console.
The first thing I see is the message saying that the disk is full. But how, I just resized it 2x?
I’m quite comfortable on the command line and can manage my server pretty well, generally. But I never had to manage disk partitions before. So after doing some reading, I understand that /dev/vda1
is a partition and has a size of around 25GB (I’ve resized my droplet to 50GB).
Ah, the DigitalOcean blog states that sudo resize2fs /dev/vda1
will help me out. To be hones, I had no idea what it was about, just that it would fix this. Also, I was in a hurry as my server was down so I didn’t do man resize2fs
¯\_(ツ)_/¯
Error: The filesystem is already (n) blocks long. Nothing to do!
So I continue my search and learn sow new commands:
lsblk
lists your partitions and also the total size of your hard disk (which confirmed that the resize had worked)- with
parted
you can manage disk partitions: https://www.tecmint.com/parted-command-to-create-resize-rescue-linux-disk-partitions/ (read this article)
I start by listing my partitions: print
. First thing that comes to mind is to create a second partition (mkpart
), but I was on the wrong track so I deleted it again.
Solution: first add space to the partition then resize
- Assigning more space to
/dev/vda1
usingparted
andresizepart
(partedq)
print 1 /dev/vda1resizepart Partition number? 1
End? [24.8GB]? 50000 // this is important to resize
So if you had 25GB available before, then end would be somewhere around 25GB. Thus, end means actually the size you want to assign to your partition. I didn’t get that at first. As I needed to resize to 50GB, I had to put 50000
(units are MB) as the end parameter.
2. Resize it
sudo resize2fs /dev/vda1
(This should work now)
3. Reboot
sudo reboot
I also had to restart mysql for some reason (didn’t check the logs):
sudo systemctl restart mysql
And voila, back online. What a relief, I thought I lost it all. Hope this can help someone. Don’t hesitate to ask any questions, I’ll do my best to help where I can.
-Thomas