To grow a Google Cloud VM disk without rebooting, run three commands: gcloud compute disks resize to enlarge the disk, sudo growpart to expand the partition, and sudo resize2fs (ext4) or sudo xfs_growfs (XFS) to stretch the filesystem. Persistent disks resize online, so no detach, reboot, or maintenance window is needed. If you need more space on a separate volume instead, the last section adds a second persistent disk and mounts it with a UUID-based /etc/fstab entry, and SSH into a GCP VM without gcloud covers getting a shell on the VM with plain OpenSSH.
The disk hardware is resized at the GCP control-plane layer in seconds, then the partition table and filesystem are stretched live from inside the VM. Below is the exact procedure, the verification commands to run before and after, the caveats that bite people once (shrinking, MBR ceiling, Extreme PD throttling), and a Console vs gcloud vs Terraform comparison so you can pick the right interface for your workflow.
How do I increase a Google Cloud VM disk size without rebooting?
Run gcloud compute disks resize DISK_NAME --size NEW_SIZE --zone ZONE to enlarge the persistent disk at the GCP layer. The hypervisor exposes the new size to the running VM within a few seconds. SSH into the instance and confirm the kernel sees it with lsblk. Expand the partition with sudo growpart /dev/DEVICE PART_NUM (typically /dev/sda 1 for boot disks on most public images). Finally, stretch the filesystem: sudo resize2fs /dev/sda1 for ext4 or sudo xfs_growfs / for XFS. Verify with df -h. The entire flow runs against a live VM with active connections, services, and disk I/O. No detach, no reboot, no downtime. For Extreme PD the only constraint is one resize per six hours, and shrinking is never supported on any disk type.
Jump to:
- Before you start: prerequisites and backups
- Step 1: Resize the disk in GCP
- Step 2: Expand the partition
- Step 3: Resize the filesystem
- Verify the new size
- Detect the filesystem before you resize it
- Console vs gcloud vs Terraform
- Caveats and gotchas
- Add a persistent disk to a GCP VM
- SSH into a GCP VM without gcloud
- What to do next
- FAQ
Type your GCP values once. Every command below updates as you type.
Before you start: prerequisites and backups
You need the Compute Instance Admin (v1) IAM role (roles/compute.instanceAdmin.v1) or an equivalent custom role with compute.disks.update. The VM can be running. The disk does not need to be detached.
Take a snapshot first. Snapshots are incremental, cheap, and the only single-command rollback you have if the partition table goes sideways:
gcloud compute snapshots create pre-resize-$(date +%Y%m%d-%H%M) \
--source-disk :disk_name \
--source-disk-zone :zoneA 100 GB disk snapshot completes in seconds and costs cents. Mistakes on a live disk are not cheap.
Capture the current state so you have a before-and-after to compare:
df -h
lsblkdf -h shows mounted filesystems and their used/free space. lsblk shows the block-device tree (disk → partitions → filesystems) and is where you'll confirm the new size lands.
Step 1: Resize the disk in GCP
The gcloud one-liner:
gcloud compute disks resize :disk_name \
--size :new_size \
--zone :zone--size is in GiB. The disk name is the persistent disk's name, not the VM's (though for boot disks they usually match). The flag is --zone for zonal disks; use --region instead for regional (replicated) disks.
For boot disks the disk name usually equals the VM name. List disks to confirm:
gcloud compute disks list --filter="zone::zone"The resize takes a few seconds and returns immediately. The new size is visible from inside the VM the moment the gcloud command returns, but the kernel may need a nudge to re-read the block-device geometry. Run lsblk from inside the VM to confirm. If the disk still shows the old size, force a rescan:
echo 1 | sudo tee /sys/class/block/:device/device/rescanThis is rare on modern public images (Debian, Ubuntu, RHEL, Rocky all auto-detect) but worth knowing.
Console method: Compute Engine > Disks > click the disk > Edit > change Size > Save. Same effect, just slower if you're resizing more than one disk.
Step 2: Expand the partition
The kernel now sees the larger disk, but the partition table still says "this partition ends at the old boundary." Fix that with growpart from the cloud-utils-growpart package (pre-installed on every GCP public image):
sudo growpart /dev/:device :partitionTwo arguments, space-separated: the device (/dev/sda) and the partition number (1). Note the space, not a colon and not concatenated. A common typo is growpart /dev/sda1 (no space) which fails because growpart needs the disk and the partition index separately.
Output looks like:
CHANGED: partition=1 start=2048 old: size=209713119 end=209715167 new: size=419430399 end=419432447
If growpart isn't installed (rare, but happens on minimal or custom images):
# Debian / Ubuntu
sudo apt-get update && sudo apt-get install -y cloud-guest-utils
# RHEL / Rocky / CentOS
sudo dnf install -y cloud-utils-growpartFor data disks with a single partition the call is identical with a different device, for example sudo growpart /dev/sdb 1. For data disks formatted as a whole-disk filesystem (no partition table) skip this step and go straight to filesystem resize against the raw device.
Step 3: Resize the filesystem
The partition is now the full size of the disk, but the filesystem inside the partition still believes it's the old size. The command depends on the filesystem type.
ext4 (Debian, Ubuntu, most custom Linux images):
sudo resize2fs /dev/:device:partitionresize2fs reads the partition geometry and grows the ext4 superblock to match. Online resize on a mounted filesystem is supported and is what runs here. Expected output:
resize2fs 1.46.5 (30-Dec-2021)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/sda1 is now 52428795 (4k) blocks long.
XFS (RHEL 8+, Rocky, AlmaLinux, some Ubuntu cloud images):
sudo xfs_growfs :mountXFS resizes by mount point, not by device. / is the root mount; for a data disk mounted at /data it would be sudo xfs_growfs /data. XFS can only grow, never shrink, which matches the GCP disk constraint anyway.
Btrfs (uncommon on GCP, but supported):
sudo btrfs filesystem resize max :mountIf you don't know the filesystem type, the next section has the detection commands.
Verify the new size
df -h
lsblkdf -h should now show the new free space on the mount point. lsblk should show the partition matching the disk size.
A complete before-and-after on a boot disk grown from 100 GB to 200 GB:
# Before
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 98G 42G 52G 45% /
# After
$ df -h /
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 196G 42G 149G 22% /
Same Used, larger Size. That's the green light. Total wall-clock for the three commands on a typical boot disk: under 30 seconds, no reboot, active SSH session never drops.
Detect the filesystem before you resize it
Run any of these to identify the filesystem type and partition layout. Useful when you've inherited a VM and don't know what shape its disk is in.
# Filesystem type per partition
lsblk -f
# Filesystem type of the root mount
findmnt -T / -o SOURCE,TARGET,FSTYPE
# Disk and partition geometry
sudo parted -l
# Quick filesystem type lookup by device
sudo blkid /dev/sda1lsblk -f is the fastest single command and shows everything at once: device tree, filesystem type, label, UUID, and mountpoint.
Cheat sheet for picking the resize command:
| Filesystem | Resize command |
|---|---|
| ext2 / ext3 / ext4 | sudo resize2fs /dev/DEVICE |
| XFS | sudo xfs_growfs MOUNT_POINT |
| Btrfs | sudo btrfs filesystem resize max MOUNT_POINT |
| ZFS | sudo zpool online -e POOL DEVICE |
| FAT32 / NTFS | not online-resizable on Linux |
The first three cover ~99% of GCP Linux VMs.
Console vs gcloud vs Terraform
The resize itself is identical at the API layer. The interface choice is about your workflow.
| Approach | Best for | Command / action |
|---|---|---|
| Cloud Console | One-off resizes, exploring | Compute Engine > Disks > Edit > Size |
gcloud CLI | Scripted, one-shot, ad-hoc batches | gcloud compute disks resize DISK --size N --zone Z |
| Terraform | Infra-as-code, audit trail, multi-environment | google_compute_disk.size = 200 then terraform apply |
| REST API | Programmatic, custom tooling | PATCH /compute/v1/projects/PROJECT/zones/ZONE/disks/DISK |
For Terraform specifically, the only attribute that changes is size:
resource "google_compute_disk" "data" {
name = "data-disk"
zone = "us-central1-a"
size = 200 # was 100
type = "pd-balanced"
}
Terraform performs the resize in place. It does NOT trigger a replacement, which is exactly what you want. The growpart and resize2fs steps still have to happen inside the VM, typically via a remote-exec provisioner or a separate Ansible/SSM run.
To batch-resize many disks via gcloud, a Bash for loop over a disk-name list is the simplest pattern:
for disk in web-01 web-02 web-03; do
gcloud compute disks resize "$disk" --size 200 --zone us-central1-a --quiet
donePair with a Bash while loop and a gcloud compute disks describe poll if you need to wait for the resize to be observed by each VM before proceeding to the partition step.
Caveats and gotchas
You cannot shrink a persistent disk. Ever. The only path to a smaller disk is: create a new smaller disk, copy data over, switch the VM to use it, delete the old one. Plan capacity with this in mind; over-provisioning is reversible only the hard way.
MBR partition tables cap at 2 TB. GPT supports the full range up to 64 TiB. GCP public images ship GPT by default, but custom images imported from older infrastructure may still be MBR. Check with sudo parted /dev/sda print | grep "Partition Table". If it says msdos, you're on MBR and capped at 2 TB.
Maximum disk size is 64 TiB for Balanced, Performance (SSD), Standard, and Extreme persistent disks. Hyperdisk goes higher but uses a different resize path.
Extreme PD throttles resizes to once per 6 hours. Plan accordingly. The other disk types have no such limit.
Custom images may not auto-detect the new size on boot. Public Google-managed images (Debian, Ubuntu, RHEL, Rocky, Windows) auto-grow the boot disk's partition and filesystem on first boot after a resize. Custom or imported images do not. If you're on a custom image, the three-step procedure above is mandatory.
Boot disks vs data disks. The device is /dev/sda for the boot disk on most public images and /dev/sdb, /dev/sdc, etc. for additional data disks. NVMe-backed instances (C3, N4, third-gen and later) use /dev/nvme0n1, /dev/nvme0n2 instead. lsblk is the source of truth.
Snapshots before, not regrets after. A snapshot is faster than typing this sentence and saves the disk in its current state. Cost is incremental-only, measured in cents. There is no excuse to skip it on production disks.
Performance scales with capacity on some disk types. Standard PD throughput scales at roughly 0.12 MiB/s per GiB of provisioned size. Going from 100 GB to 200 GB doubles your throughput ceiling. Balanced PD and Performance PD have different scaling rules. Check the GCP disk performance docs if you care about the exact numbers for your disk type.
Don't run fdisk just because an old guide tells you to. Some older blog posts (including the one currently ranking on dev.to) advise running sudo fdisk /dev/sda and pressing w to "fix the GPT partition table" before growpart. This is unnecessary on modern GCP public images and risks corruption if you press the wrong key in fdisk's interactive mode. growpart handles the partition table update on its own.
Add a persistent disk to a GCP VM
Sometimes the right answer is not a bigger boot disk but a second disk: a database or upload directory on its own block device, with its own snapshot cadence. Persistent disks attach to running VMs without downtime. Create the disk with gcloud compute disks create, attach it with gcloud compute instances attach-disk, then format and mount it from inside the VM. The two things people get wrong: skipping the snapshot before mounting a disk that already has data, and using the device path (/dev/sdb) in /etc/fstab instead of the UUID. The same IAM role applies (roles/compute.instanceAdmin.v1), and if the disk already contains data (snapshot restore, migration, import), snapshot it first exactly as in the resize prerequisites.
Create and attach the disk
A 500 GB balanced disk in the same zone as the VM:
gcloud compute disks create data-disk-01 \
--size 500 \
--type pd-balanced \
--zone us-central1-a--size is in GiB. --type accepts pd-standard, pd-balanced, pd-ssd, or pd-extreme (compared below). --zone must match the VM; for replicated disks use --region plus --replica-zones. To restore from a snapshot, swap --size for --source-snapshot SNAPSHOT_NAME; the size is inherited from the snapshot, and you can enlarge on creation by passing --size (it must be larger than the source).
gcloud compute instances attach-disk web-01 \
--disk data-disk-01 \
--device-name data-disk-01 \
--zone us-central1-a--device-name is optional but worth setting: it creates a stable symlink at /dev/disk/by-id/google-DEVICE_NAME inside the VM, which beats referencing /dev/sdb in scripts. Attach completes in seconds. From inside the VM, lsblk shows the new, empty disk:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 100G 0 disk
└─sda1 8:1 0 100G 0 part /
sdb 8:16 0 500G 0 disk
sdb (or nvme0n2 on NVMe-attached instances such as C3) is the new disk, with no partitions and no filesystem. In the Console: Compute Engine, VM instances, click the VM, Edit, Additional disks, Attach existing disk.
Format and mount the new disk
Confirm the device through the stable symlink (ls -l /dev/disk/by-id/google-* should show google-data-disk-01 -> ../../sdb), then format with ext4 using Google's recommended flags for persistent-disk performance:
sudo mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb-m 0skips the default 5% root reservation (wasted on a data disk).lazy_itable_init=0,lazy_journal_init=0initializes the inode table and journal up front: slightly slower mkfs, faster steady state.discardissues a TRIM at format time so the storage backend knows which blocks are free.
This is destructive, so double-check the device path on a system with multiple disks. Then mount it:
sudo mkdir -p /mnt/disks/data
sudo mount -o discard,defaults /dev/sdb /mnt/disks/data
sudo chmod a+w /mnt/disks/dataThe discard mount option enables continuous TRIM, a small free win on persistent disks. Confirm with df -h /mnt/disks/data. Because this formats the whole device with no partition table, a later resize of this disk skips growpart and goes straight to sudo resize2fs /dev/sdb (see Step 2).
Mount it at boot with a UUID fstab entry
The mount is live but ephemeral; reboot now and the disk is gone. The fix is /etc/fstab, and only one way of writing the entry is right. The wrong version:
/dev/sdb /mnt/disks/data ext4 discard,defaults 0 2
It works until you attach another disk, detach and re-attach the boot disk, or move to an instance type with different controllers. The kernel can re-letter the devices, and /dev/sdb ends up being a different disk or nothing at all: the VM either mounts the wrong filesystem or fails to boot. The right version uses the filesystem UUID, which is baked in at format time:
sudo blkid /dev/sdb/dev/sdb: UUID="d2a4f1d0-9e5a-4b1c-83d9-7f0c2a8b6a3e" TYPE="ext4"
echo "UUID=d2a4f1d0-9e5a-4b1c-83d9-7f0c2a8b6a3e /mnt/disks/data ext4 discard,nofail 0 2" \
| sudo tee -a /etc/fstabnofail matters: without it, a missing disk (detached, migrated, snapshot-restored elsewhere) stops the VM from booting at all; with it, boot continues and you can SSH in to diagnose. Test without rebooting:
sudo umount /mnt/disks/data
sudo mount -a
df -h /mnt/disks/dataClean output from mount -a plus the disk in df -h means the line is correct. The only test that fully proves it is sudo reboot, then df -h /mnt/disks/data and mount | grep /mnt/disks/data once the VM is back. If the mount is missing, check dmesg | tail and journalctl -xb | grep -i fstab; the usual suspects are a UUID copy-paste typo, a filesystem type mismatch (ext4 declared but the disk is XFS), or a missing nofail blocking boot. Before you ever run gcloud compute instances detach-disk, remove or comment out the fstab line, or the next reboot fails.
Persistent disk types compared
| Type | Reference | Media | Min size | Max size | Best for |
|---|---|---|---|---|---|
| Standard | pd-standard | HDD-backed | 10 GiB | 64 TiB | Cold storage, archives, backup targets |
| Balanced | pd-balanced | SSD-backed | 10 GiB | 64 TiB | General workloads, boot disks, web servers |
| Performance SSD | pd-ssd | SSD-backed | 10 GiB | 64 TiB | Databases, high-IOPS workloads |
| Extreme | pd-extreme | SSD with provisioned IOPS | 500 GiB | 64 TiB | Very high IOPS, in-memory caches |
Rough cost ratio in us-central1: pd-standard ~$0.04/GB-month, pd-balanced ~$0.10, pd-ssd ~$0.17, pd-extreme priced per-IOPS on top of capacity. I default to pd-balanced, use pd-standard only for cold-tier data, reach for pd-ssd when a latency-sensitive database sits on top, and use pd-extreme only after measuring pd-ssd and needing more IOPS than its capacity-linked ceiling allows. Because performance scales with capacity, growing the disk with the resize procedure above is often the fastest fix for a slow one.
Attach a disk with Terraform or a loop
In Terraform it is two resources, not one:
resource "google_compute_disk" "data" {
name = "data-disk-01"
type = "pd-balanced"
zone = "us-central1-a"
size = 500
labels = {
environment = "production"
role = "data"
}
}
resource "google_compute_attached_disk" "data" {
disk = google_compute_disk.data.self_link
instance = google_compute_instance.web.self_link
device_name = "data-disk-01"
}
google_compute_attached_disk attaches without forcing a VM replacement. The attached_disk block on google_compute_instance would tie the disk's lifecycle to the VM, which is rarely what you want for data disks. The format, mount, and fstab steps still happen inside the VM (a remote-exec provisioner, an Ansible playbook, or a startup script). Across a fleet, a for loop does it:
for vm in web-01 web-02 web-03; do
gcloud compute disks create "${vm}-data" \
--size 500 --type pd-balanced --zone us-central1-a
gcloud compute instances attach-disk "$vm" \
--disk "${vm}-data" --device-name data \
--zone us-central1-a
doneAuto-delete and multi-writer mode
A disk attached with gcloud compute instances attach-disk is not deleted when the VM is deleted; it persists as an unattached resource, the safe default for data disks. Change the setting on an attached disk with set-disk-auto-delete: --auto-delete turns deletion-with-the-VM on, and --no-auto-delete (shown here) turns it off so the disk is preserved:
gcloud compute instances set-disk-auto-delete web-01 \
--disk data-disk-01 \
--no-auto-delete \
--zone us-central1-aFor boot disks the Console default is auto-delete ON, which is a disaster for stateful boot disks. Check with gcloud compute instances describe VM_NAME and look at autoDelete on each disk.
Multi-writer mode (--multi-writer on disk creation) attaches one disk to two VMs read-write, with significant caveats. For Persistent Disk it is pd-ssd only, two VMs maximum, both VMs must be N2 machine types, and attachment works only in a short list of locations (australia-southeast1, europe-west1, plus specific zones in us-central1, us-east1 and us-west1); no snapshots while active, and ext4 and XFS corrupt themselves in this mode, so you need a cluster-aware filesystem (OCFS2, GFS2). For read-only fanout, attach with --mode ro instead. That works on pd-standard (Google recommends at most 10 VMs), pd-balanced (10 VMs maximum), and pd-ssd (Google recommends at most 100), but not on pd-extreme. For most shared-storage needs, NFS, GCS Fuse, or Filestore is a better fit.
A few more limits worth knowing: zonal disks cannot attach across zones (moving zones means snapshot, restore in the new zone, attach); a VM takes at most 127 secondary disks and 257 TB total attached capacity; run fsck -n before mounting a snapshot-restored disk whose source VM may have crashed mid-write; and encryption at rest is on by default with Google-managed keys (use --kms-key at creation for your own key).
SSH into a GCP VM without gcloud
Every step on this page after the resize itself runs inside the VM, and gcloud compute ssh is not the only way in. A Compute Engine VM is a Linux box listening on TCP/22: as long as a firewall rule permits SSH from your source IP and the VM has a public key it trusts, plain OpenSSH connects like it would to any other server. That matters on a CI runner, a monitoring or backup box that is not Google-managed, or a fresh laptop where you have not run gcloud auth login yet.
GCP gives you three ways to authorize a key:
| Path | Where keys live | Username | When to use |
|---|---|---|---|
| Metadata SSH keys | Project or instance metadata | The key's comment field | Single account, CI runners |
| OS Login | Google IAM, synced by the guest agent | Derived from your Google account email | Multi-user teams, IAM audit |
| IAP TCP forwarding | Metadata or OS Login, plus roles/iap.tunnelResourceAccessor | Same as the key path | VMs with no public IP |
Metadata keys with plain OpenSSH
Generate a key pair, setting the comment explicitly (if you need the full background, how to create an SSH key covers the choices):
ssh-keygen -t ed25519 -C ishan -f ~/.ssh/gcp_ed25519The -C ishan comment matters: GCP uses it as the Linux username on the VM. The default comment is USER@HOSTNAME, which would make the username literally USER@HOSTNAME.
Add the public key in the Console: Compute Engine, VM instances, click the VM, Edit, SSH Keys, Add item, paste the contents of ~/.ssh/gcp_ed25519.pub, Save. The guest agent picks up the metadata change within a few seconds and writes the key to /home/ishan/.ssh/authorized_keys. Project-wide keys (Compute Engine, Metadata, SSH Keys tab) are trusted by every VM in the project; per-VM keys are the safer default. A reserved static IP keeps the address stable across restarts, but it is not free: Google bills external IPv4 addresses in use on a standard VM (static or ephemeral) at $0.005 per hour, and a reserved static IP still counts as in use while its VM is stopped. Take the external IP from the VM instances list, then connect:
ssh -i ~/.ssh/gcp_ed25519 ishan@34.122.15.42The default default-allow-ssh rule on a fresh project permits TCP/22 from 0.0.0.0/0. On a hardened project or a custom VPC, add a firewall rule allowing tcp 22 from your source IP.
OS Login and IAP
OS Login keeps public keys in Google IAM instead of metadata, so revoking access is a role change rather than a per-VM edit. Enable it with the metadata key enable-oslogin = TRUE (project-wide or per VM), grant each user roles/compute.osLogin (or roles/compute.osAdminLogin for sudo), and add your key to your profile once per laptop. That one step does need gcloud:
gcloud compute os-login ssh-keys add --key-file=~/.ssh/gcp_ed25519.pub
gcloud compute os-login describe-profile --format="value(posixAccounts[0].username)"The username is derived from your Google account email (cloudysanfrancisco@gmail.com becomes cloudysanfrancisco_gmail_com), and after that plain ssh -i ~/.ssh/gcp_ed25519 cloudysanfrancisco_gmail_com@34.122.15.42 works from anywhere. I use metadata keys for solo work and CI service accounts, and OS Login for teams above about five engineers.
IAP TCP forwarding tunnels SSH through Google's edge so the VM needs no public IP. The firewall must allow tcp:22 from Google's IAP range 35.235.240.0/20, and the practical client is gcloud compute ssh VM_NAME --tunnel-through-iap --zone ZONE. Doing IAP without gcloud means talking to the IAP API with a Google-issued OAuth token, which is rare enough that I either accept gcloud on those machines or use a public IP with a tight single-source firewall rule.
A ~/.ssh/config block for GCP VMs
Host gcp-web-01
HostName 34.122.15.42
User ishan
IdentityFile ~/.ssh/gcp_ed25519
IdentitiesOnly yes
ServerAliveInterval 60
ServerAliveCountMax 3
Host gcp-*
User ishan
IdentityFile ~/.ssh/gcp_ed25519
IdentitiesOnly yes
StrictHostKeyChecking accept-new
IdentitiesOnly yes stops OpenSSH from offering every key in ssh-agent first (too many wrong-key attempts can temporarily lock the account), ServerAliveInterval 60 keeps the session alive across NATs that drop idle TCP, and StrictHostKeyChecking accept-new accepts a host key on first connect but refuses if it later changes. After that, ssh gcp-web-01 is the whole command.
On Windows 10 1809+ and Windows 11 the OpenSSH client is built in and the config lives at %USERPROFILE%\.ssh\config. With PuTTY, generate an Ed25519 key in PuTTYgen, paste the "Public key for pasting into OpenSSH authorized_keys file" text into GCP metadata, save the private key as .ppk, and set it under Connection, SSH, Auth, Credentials, with the username under Connection, Data, Auto-login username. To move saved sessions between machines, see how to export and import PuTTY settings.
Connection refused or Permission denied
Connection refused is a network problem, not authentication: the VM is stopped, no firewall rule allows TCP/22 from your IP (check VPC network, Firewall for a tcp:22 rule that targets the VM), or sshd has died (recover through the serial console, or attach the disk to a recovery VM).
Permission denied (publickey) means the network works but the key was not accepted:
- Wrong username: the key comment for metadata keys, the IAM-derived name for OS Login.
- Wrong key offered: check with
ssh -v, then pin it with-iorIdentityFile. - Key not propagated yet: wait about 10 seconds.
- OS Login is on: with
enable-oslogin = TRUE, OS Login wins and metadata keys are ignored. - Bad permissions on the VM: use the Console's SSH-in-browser button and run
chmod 600 ~/.ssh/authorized_keys && chmod 700 ~/.ssh.
ssh -vvv prints the Offering public key: and Server accepts key: lines that usually pinpoint the problem. Google's Connect to a Linux VM guide is the upstream reference for all of these methods.
What to do next
- The canonical reference: Google Cloud's official Resize a persistent disk guide covers the gcloud and Console flows plus Windows-specific steps.
- How to Export All MySQL Databases: the "snapshot before resize" hygiene applies double when a database lives on the disk. Run a logical dump first.
- How to ZIP Multiple Directories into Individual Files: useful for archiving the freed-up space you'll have after a resize.
- Upstream references for the new-disk flow: Google Cloud's Add a persistent disk guide and Format and mount a disk on a Linux VM.
- How to Export and Import PuTTY Settings: if you're SSH-ing from Windows into a GCP VM, save your session config before swapping machines.
- On the other cloud: extend an AWS EBS volume without a restart. The control-plane resize,
growpart, and filesystem grow map almost one-to-one onto AWS, with the EBS-specific caveats called out. - Bash For Loops and Bash While Loops: the patterns I use to batch-resize a fleet of disks and poll for completion.
- The
growpartsource lives in the cloud-utils repo on GitHub if you want the implementation details.
FAQ
Yes. Persistent disk resize is an online operation. The disk is enlarged at the GCP control-plane layer, the kernel inside the running VM sees the new size within seconds, and growpart plus resize2fs (or xfs_growfs) stretch the partition and filesystem live. Active SSH sessions, running services, and disk I/O all continue uninterrupted.
The only thing that requires a reboot is a custom-image boot disk where the OS does not detect the new size automatically. In that case running the three-step procedure manually still avoids any reboot.
gcloud compute disks resize DISK_NAME --size NEW_SIZE --zone ZONE. The size is in GiB. For regional (replicated) disks substitute --region REGION for --zone.
The resize completes in a few seconds and returns. The disk is now larger at the hypervisor level; the partition and filesystem inside still need to be expanded with growpart and resize2fs or xfs_growfs.
No. Google Cloud supports resizing persistent disks while they are attached to a running VM. The disk stays mounted, the VM stays up, and the resize happens transparently. Detaching is not a prerequisite and would only add downtime.
This is one of the things GCP gets genuinely right: the resize, the partition expansion, and the filesystem grow are all online operations on every supported Linux filesystem.
First expand the partition: sudo growpart /dev/sda 1 (note the space between the device and the partition number). Then resize the filesystem.
For ext4: sudo resize2fs /dev/sda1. For XFS: sudo xfs_growfs / (XFS works on the mount point, not the device). For Btrfs: sudo btrfs filesystem resize max /. Run df -h to confirm the new size.
growpart resizes the partition table entry. It tells the kernel that the partition now extends to the new end of the disk. After growpart, lsblk shows the partition at its new size, but the filesystem inside still believes it's the old size.
resize2fs resizes the ext4 (or ext2/ext3) filesystem to fill the partition. It updates the filesystem superblock and adds capacity that user data can actually consume. Both steps are required, in this order: disk → partition (growpart) → filesystem (resize2fs).
No. Persistent disks cannot be shrunk under any circumstances on any disk type (Standard, Balanced, Performance SSD, Extreme). The gcloud compute disks resize command rejects a smaller size with an error.
The workaround is to create a new smaller disk, copy data over (rsync, dd of a smaller filesystem, or a snapshot-restore to a smaller target), attach the new disk to the VM, and delete the old one. Plan capacity with this constraint in mind: over-provision is reversible only via migration.
No, for the standard case. The control-plane resize, the growpart partition expansion, and the resize2fs or xfs_growfs filesystem grow are all online operations. The VM stays up, services keep running, open files and active connections are unaffected.
The one exception is a custom-image boot disk that does not auto-detect the new geometry on running kernels. Even then the three-step manual procedure avoids a reboot. Snapshots before the resize give you a one-command rollback if anything goes wrong.
Device paths like /dev/sdb are not stable. The kernel assigns them in the order it sees disks at boot. Attach another disk, detach and re-attach the boot disk, or move to an instance type with different controllers, and the same physical disk can show up as /dev/sdc or /dev/nvme0n2.
Filesystem UUIDs are baked into the filesystem at format time and never change. UUID=... references the filesystem directly, not whichever device letter won the boot-time race. Always add nofail so a missing disk does not block boot.
pd-standard is HDD-backed: cheap, slow, fine for cold storage and backup targets. pd-balanced is SSD-backed at a lower cost than pd-ssd: the right default for most workloads. pd-ssd is higher-performance SSD for latency-sensitive databases. pd-extreme is SSD with provisioned IOPS: only when you have measured pd-ssd and need more.
Not by default for disks attached via gcloud compute instances attach-disk. The disk survives VM deletion as an unattached resource you can re-attach or delete manually.
The exception is boot disks, where the Console default is auto-delete ON. Check with gcloud compute instances describe VM_NAME and look at the autoDelete field on each disk. Change it with gcloud compute instances set-disk-auto-delete: --auto-delete turns it on, --no-auto-delete turns it off so the disk survives the VM.
For read-only access, yes: attach with --mode ro. It works on pd-standard (up to about 10 VMs recommended), pd-balanced (10 VMs maximum), and pd-ssd (up to about 100 recommended), but not pd-extreme. It is the right answer for shared static assets and reference datasets.
For read-write from two VMs simultaneously, you need multi-writer mode (--multi-writer on creation). For Persistent Disk it is limited to pd-ssd, two N2 VMs maximum, a short list of supported locations, no snapshots while active, and requires a cluster-aware filesystem like OCFS2 or GFS2. For most use cases NFS, GCS Fuse, or Filestore is a better fit.
127 secondary (non-boot) persistent disks per VM, plus the boot disk. Total attached capacity caps at 257 TB per instance. The limit you hit first is usually IOPS or throughput, not the disk count, and since performance scales with disk size, larger disks of the right type often outperform many small disks.
Yes. Add your public key to the VM's metadata in the Console (the key's comment becomes the Linux username), make sure a firewall rule allows TCP/22 from your IP, and connect with ssh -i ~/.ssh/key user@EXTERNAL_IP. OS Login needs gcloud once per laptop to register the key; IAP tunneling effectively needs it every time.
With metadata keys, the username is the comment field of the public key, so a key made with ssh-keygen -C ishan connects as ishan. With OS Login, it is derived from your Google account email: dots and the at-sign become underscores, so cloudy.sanfrancisco@gmail.com becomes cloudy_sanfrancisco_gmail_com. gcloud compute os-login describe-profile prints it.
For Standard, Balanced, Performance (SSD), and Extreme persistent disks, the maximum is 64 TiB per disk. Hyperdisk goes higher but uses a different resize path and a different IOPS/throughput model.
A single VM can attach multiple persistent disks, so total VM storage scales well beyond a single-disk ceiling. Note also that MBR partition tables cap at 2 TB regardless of the disk-level maximum, so use GPT (the GCP default on public images) to go beyond that.
Sources
Authoritative references this article was fact-checked against.
- GCP, persistent disk performance (docs)docs.cloud.google.com
- GCP, persistent disks overview (docs)docs.cloud.google.com
- Canonical cloud-utils (growpart): GitHubgithub.com
- GCP, extreme persistent disk (docs)docs.cloud.google.com
- GCP, share a disk between VMs (docs)docs.cloud.google.com
- gcloud compute instances set-disk-auto-delete (reference)docs.cloud.google.com
- GCP, connect to Linux VMs (docs)docs.cloud.google.com
- Google Cloud VPC network pricing: external IP addressescloud.google.com





