DEV Community

Cover image for Expanding Disk Size in Google Cloud
Athreya aka Maneshwar
Athreya aka Maneshwar

Posted on

Expanding Disk Size in Google Cloud

Hi there! I'm Maneshwar. Right now, I’m building LiveAPI, a first-of-its-kind tool that helps you automatically index API endpoints across all your repositories. LiveAPI makes it easier to discover, understand, and interact with APIs in large infrastructures.


When your VM’s root disk is running out of space — say you're on 20GB and need to go to 40GB — here’s the exact procedure to scale the disk without breaking anything. This example uses an Ubuntu VM named phpbb-new.

Step 1: Resize the Disk from Google Cloud Console

  1. Go to Google Cloud Console.
  2. Navigate to Compute Engine → VM instances.
  3. Click your instance (e.g. phpbb-new).
  4. Scroll to the "Boot disk and local disks" section.
  5. Click the boot disk name.
  6. Click EDIT at the top.
  7. Change Size (GB) → from 20 → to 40.
  8. Hit SAVE.

Note: Disk size updates immediately in GCP, but the OS inside the VM still sees the old size. You’ll need to fix that next.

Step 2: SSH into the VM

From the instance details page, hit SSH.

Confirm you’re in with:

root@phpbb-new:~#
Enter fullscreen mode Exit fullscreen mode

Step 3: Check the Current Disk Usage

Run:

df -h
Enter fullscreen mode Exit fullscreen mode

You’ll likely see:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        19G   16G  3.1G  84% /
Enter fullscreen mode Exit fullscreen mode

Then run:

sudo fdisk -l
Enter fullscreen mode Exit fullscreen mode

Check that it detects the new disk size:

Disk /dev/sda: 40 GiB
...
GPT PMBR size mismatch (old size vs new size)
Enter fullscreen mode Exit fullscreen mode

Step 4: Fix the GPT Partition Table

Let’s correct the partition table to reflect the new size.

sudo fdisk /dev/sda
Enter fullscreen mode Exit fullscreen mode

At the Command (m for help): prompt, just type:

w
Enter fullscreen mode Exit fullscreen mode

This writes the updated partition layout and exits. Ignore any "device busy" warnings — it's fine in GCP.

Step 5: Expand the Partition

Run:

sudo growpart /dev/sda 1
Enter fullscreen mode Exit fullscreen mode

This resizes partition 1 (/dev/sda1), which maps to /.

Expected output:

CHANGED: partition=1 ... new: size=83883903
Enter fullscreen mode Exit fullscreen mode

Step 6: Resize the Filesystem

Tell ext4 to use the new space:

sudo resize2fs /dev/sda1
Enter fullscreen mode Exit fullscreen mode

This might take a few seconds. When it’s done, your root filesystem now uses the full disk.

Step 7: Verify It Worked

Final check:

df -h
Enter fullscreen mode Exit fullscreen mode

You should now see:

Filesystem      Size  Used Avail Use% Mounted on
/dev/root        39G   16G   22G  43% /
Enter fullscreen mode Exit fullscreen mode

Mission accomplished.

Recap: Quick Command List

# SSH into VM
df -h
sudo fdisk -l

# Fix GPT table
sudo fdisk /dev/sda
# then just type: w

# Resize partition
sudo growpart /dev/sda 1

# Resize filesystem
sudo resize2fs /dev/sda1

# Verify
df -h
Enter fullscreen mode Exit fullscreen mode

Pro Tips

  • Works only for disks using GPT (which is default in GCP).
  • If your root disk is XFS instead of ext4, use xfs_growfs / instead of resize2fs.
  • For automated workflows, you can script this and run via cloud-init or startup scripts.

Done. Disk doubled. No reboot. No downtime.


LiveAPI helps you get all your backend APIs documented in a few minutes.

With LiveAPI, you can generate interactive API docs that allow users to search and execute endpoints directly from the browser.

LiveAPI Demo

If you're tired of updating Swagger manually or syncing Postman collections, give it a shot.

Top comments (1)

Collapse
 
shiva_shanker_k profile image
shiva shanker • Edited

Honestly, there's gotta be a simpler way than all these manual steps! What about just using Google Cloud's auto-resize feature or setting up disk monitoring with alerts?
Sometimes the "simple" solution is just avoiding the problem entirely.what's your opinion in this!!