Increase disk space on debian VM filesystem with command line

If, like me, you’re a bit of a linux n00b and you’ve made the mistake of setting up a development VM-based linux server (in my case Debian) that ended up being a production server but you failed to provision enough disk space (it was only a dev server am I right?!) then you’ll probably have tried increasing the disk space in vSphere or similar and wondered how to make the OS see that extra disk space…

What you need to do is rebuild the partitions and then get the filesystem to fill the space, particularly the rootfs, which is probably where you are see 90%+ when you run:

$ df -h

First thing you need to do is have a read of this excellent guide: Live resizing of an ext4 filesytem on linux

Pay particular attention to the disclaimer about data loss. You MUST create a backup in case you mess this up.

This is actually magic. After adding additional disk via your VM management tool, you’re going to log in to your linux system and using fdisk you’ll delete active partitions, all of them. While you are logged on! Then you’re going to create new partitions and then get use resize2fs to get the OS to recognise the new space.

A colleague and I practiced this on a clone, and this morning I came in early and we did it on the production server.

The only slightly complicated bits were picking the right number of sectors to give to sda1 (we went with 60000000) leaving enough room for sda2 (Extended) and sda5 (Linux swap / Solaris).

The other bit we stumbled on while trying to follow the codesilence recipe was that the code section for resize2fs at the bottom of the post didn’t show the command to edit fstab, and we tried to do that last… that didn’t work 🙂 We reread it and realised the correct order is stated in this bit:

run mkswap, adjust /etc/fstab to the new UUID and turn the swap on

After you run mkswap, it will give you a UUID that you need to copy (or screenshot) which you then enter into /etc/fstab using your preferred editor (that’s nano for me, but you may prefer vim or vi… you sick puppy) THEN you do the swapon bit…

Enjoy your new space!


I might not be the world’s best multi-tasker but I reckon I’m a contender for the world’s best multi-slacker!

Did I mention I do social media stuff for my day job? The way I keep sane (and employed!) is by forgetting all about my day job when I finish for the day, which means I try to avoid social media. I do keep in touch with family via Facebook in the evenings, but I’m rubbish at Twitter. I’m rubbish at updating this blog. I do enjoy going out into the wild and taking pics of nature (especially fungi and bees) and I can cope with Instagram which has become my phenology diary 🙂

So basically, if you’re interested in what I get up to – insta is it