Resize Disk of VM Instance on Google Cloud Platform without Stopping VM Tricks by Rajesh Kumar Sahanee - May 30, 20200 Post Views: 5,322 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) Shell 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 1234567891011121314 rajesh@instance-1:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/root 9.6G 1.4G 8.2G 14% /devtmpfs 1.8G 0 1.8G 0% /devtmpfs 1.8G 0 1.8G 0% /dev/shmtmpfs 369M 912K 368M 1% /runtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 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/133tmpfs 369M 0 369M 0% /run/user/1001 Step 3: Check partition using lsblk command Shell 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 12345678910 rajesh@instance-1:~$ sudo lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTloop0 7:0 0 27.1M 1 loop /snap/snapd/7264loop1 7:1 0 55M 1 loop /snap/core18/1754loop2 7:2 0 69.3M 1 loop /snap/lxd/15161loop3 7:3 0 115M 1 loop /snap/google-cloud-sdk/133sda 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 Shell gcloud compute disks resize INSTANCE_NAME --zone ZONE --size 30GB --quiet 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 grow partition Shell rajesh@instance-1:~$ sudo growpart /dev/sda 1 CHANGED: partition=1 start=227328 old: size=20744159 end=20971487 new: size=62687199 end=62914527 12 rajesh@instance-1:~$ sudo growpart /dev/sda 1CHANGED: partition=1 start=227328 old: size=20744159 end=20971487 new: size=62687199 end=62914527 for centos grow partition Shell [rajesh@instance-3 ~]$ sudo growpart /dev/sda 2 CHANGED: partition=2 start=411648 old: size=41529344 end=41940992 new: size=62502879,end=62914527 12 [rajesh@instance-3 ~]$ sudo growpart /dev/sda 2CHANGED: 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 install growpart Shell sudo apt-get install cloud-utils 1 sudo apt-get install cloud-utils for centos install growpart Shell sudo yum install cloud-utils-growpart 1 sudo yum install cloud-utils-growpart Step 6: Resize filesytem for debian and ubuntu resize filesystem Shell 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. 12345 rajesh@instance-1:~$ sudo resize2fs /dev/sda1resize2fs 1.45.5 (07-Jan-2020)Filesystem at /dev/sda1 is mounted on /; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 4The filesystem on /dev/sda1 is now 7835899 (4k) blocks long. for centos resize partition Shell [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 12345678910111213 [rajesh@instance-3 ~]$ sudo mount /dev/sda2 /mnt[rajesh@instance-3 ~]$ sudo xfs_growfs -d /mntmeta-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=1data = bsize=4096 blocks=5191168, imaxpct=25 = sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0, ftype=1log =internal log bsize=4096 blocks=2560, version=2 = sectsz=4096 sunit=1 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data size 51200 too small, old size is 5191168 Step 7: Verify using df command verify Shell 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 1234567891011121314 rajesh@instance-1:~$ df -hFilesystem Size Used Avail Use% Mounted on/dev/root 29G 1.4G 28G 5% /devtmpfs 1.8G 0 1.8G 0% /devtmpfs 1.8G 0 1.8G 0% /dev/shmtmpfs 369M 912K 368M 1% /runtmpfs 5.0M 0 5.0M 0% /run/locktmpfs 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/133tmpfs 369M 0 369M 0% /run/user/1001 That’s it If you find this helpful then please do shareAny suggestions and queries are welcome in comment section