So we have a lot of instances running up and about and every now and then we find out we’re running out of diskspace due to excessive logging and/or poor optimization of added media files. And while it is always best practice to fix those issues and keep the environment as clean as possible, this isn’t always viable. And in this instance I wasn’t able to securely clean an instance, but I did needed more space. So I resized the disk of the running instance.
GCP makes this fairly easy (fairly, because it never really is).
I used the
gcloud compute disks resize [DISK_NAME] --size [DISK_SIZE] command to increase the disk from 10G to 25G, and smartboys as they are over at Google, they said if you resized the root disk, it would automagically scale the OS after rebooting the instance. So I did, and it didn’t. Of course.
Output of lsbklk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 25G 0 disk
`-sda1 8:1 0 10G 0 part /
Output of df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.8G 4.0K 1.8G 1% /dev
tmpfs 370M 280K 370M 1% /run
/dev/sda1 9.9G 4.8G 4.6G 52% /
none 4.0K 0 4.0K 0% /sys/fs/cgroup
none 5.0M 0 5.0M 0% /run/lock
none 1.9G 0 1.9G 0% /run/shm
none 100M 0 100M 0% /run/user
Output of resize2fs /dev/sda1
resize2fs 1.42.9 (4-Feb-2014)
The filesystem is already 2621184 blocks long. Nothing to do!
Fumbling around with a few different methods to achieve this, I came back to this simple command and figured though it’s a GCP instance, it is still just an Ubuntu 14.04 installation.
Turns out I was missing some steps, namely resizing the partition first to the end of the resized disk
parted /dev/sda – to enter the prompt “(parted)”
resizepart 1 to resize the partition 1
-0 resizes it to the end of the disk (-0 is the last possible sector)
quit to exit parted
After this, I ran the
resize2fs command, and all was well with the world.