
Hello friends, today we’ll see how to resize disk of VM instance on Google Cloud Platform without stopping VM. Actually one of my colleague was working on a project which was hosted on GCP Compute Engine VM and while working on the project suddenly he ran out of disk storage then he asked me for help. Then I said ok and after figuring out I found there was only 10 GB of disk space, so I asked him to stop the vm and increase disk space but he hadn’t want to stop the vm. Then I googled and came up with another solution which I am sharing now. This solution applies on most common case which is – “the disk should have single partition”.
Step 1: SSH into your VM
![]() |
![]() |
Step 2: Check Available Disk Size using df below command (Optional)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
rajesh@instance-1:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/root 9.6G 1.4G 8.2G 14% / devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 369M 912K 368M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup /dev/sda15 105M 3.9M 101M 4% /boot/efi /dev/loop0 28M 28M 0 100% /snap/snapd/7264 /dev/loop1 55M 55M 0 100% /snap/core18/1754 /dev/loop2 70M 70M 0 100% /snap/lxd/15161 /dev/loop3 115M 115M 0 100% /snap/google-cloud-sdk/133 tmpfs 369M 0 369M 0% /run/user/1001 |
Step 3: Check partition using lsblk command
1 2 3 4 5 6 7 8 9 10 |
rajesh@instance-1:~$ sudo lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT loop0 7:0 0 27.1M 1 loop /snap/snapd/7264 loop1 7:1 0 55M 1 loop /snap/core18/1754 loop2 7:2 0 69.3M 1 loop /snap/lxd/15161 loop3 7:3 0 115M 1 loop /snap/google-cloud-sdk/133 sda 8:0 0 10G 0 disk ├─sda1 8:1 0 9.9G 0 part / ├─sda14 8:14 0 4M 0 part └─sda15 8:15 0 106M 0 part /boot/efi |
Step 4: Increase disk size from GCP console or by running below command in cloud shell
1 |
gcloud compute disks resize INSTANCE_NAME --zone ZONE --size 30GB --quiet |
replace INSTANCE_NAME with your instance name and ZONE with your zone name
OR
![]() |
![]() |
Go to Disk Section of Compute Engine and click on the name of the disk of which you want to increase space and then click edit then change disk size according to your need and click save |
Step 5: Grow Partition using growpart command
for debian and ubuntu
1 2 |
rajesh@instance-1:~$ sudo growpart /dev/sda 1 CHANGED: partition=1 start=227328 old: size=20744159 end=20971487 new: size=62687199 end=62914527 |
for centos
1 2 |
[rajesh@instance-3 ~]$ sudo growpart /dev/sda 2 CHANGED: partition=2 start=411648 old: size=41529344 end=41940992 new: size=62502879,end=62914527 |
Note: if you get command not found error then you can use below command to install it
for debian and ubuntu
1 |
sudo apt-get install cloud-utils |
for centos
1 |
sudo yum install cloud-utils-growpart |
Step 6: Resize filesytem
for debian and ubuntu
1 2 3 4 5 |
rajesh@instance-1:~$ sudo resize2fs /dev/sda1 resize2fs 1.45.5 (07-Jan-2020) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 4 The filesystem on /dev/sda1 is now 7835899 (4k) blocks long. |
for centos
1 2 3 4 5 6 7 8 9 10 11 12 13 |
[rajesh@instance-3 ~]$ sudo mount /dev/sda2 /mnt [rajesh@instance-3 ~]$ sudo xfs_growfs -d /mnt meta-data=/dev/sda1 isize=512 agcount=4, agsize=1297792 blks = sectsz=4096 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=5191168, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data size 51200 too small, old size is 5191168 |
Step 7: Verify using df command
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
rajesh@instance-1:~$ df -h Filesystem Size Used Avail Use% Mounted on /dev/root 29G 1.4G 28G 5% / devtmpfs 1.8G 0 1.8G 0% /dev tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 369M 912K 368M 1% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 1.8G 0 1.8G 0% /sys/fs/cgroup /dev/sda15 105M 3.9M 101M 4% /boot/efi /dev/loop0 28M 28M 0 100% /snap/snapd/7264 /dev/loop1 55M 55M 0 100% /snap/core18/1754 /dev/loop2 70M 70M 0 100% /snap/lxd/15161 /dev/loop3 115M 115M 0 100% /snap/google-cloud-sdk/133 tmpfs 369M 0 369M 0% /run/user/1001 |
That’s it
If you find this helpful then please do share
Any suggestions and queries are welcome in comment section
Comments