GCP: Resize/Repair Compute engine root partition is full (100%) issues on the fly.
Sometimes as part of infrastructure management, we faced issues like root partition is full(100%). Which leads to inaccessibility of the VM via SSH or cloud shell. Or We need to resize the VM root partition due to some need. Thanks to Google cloud, we no need to stop the VM and can able t resize or expand our disk size. We can repair or resize a disk without stopping the VM using below steps.
Recommendation(To avoid disk overutilized):
1) Proper alert configuration setup using Stackdriver monitoring or any other tool
2) Housekeeping of log file and other unnecessary files
Solutions for below-listed issues:
1) If root partition is full(100%)
2) Need to resize disk without stopping the VM
Step 0.1: Check disks available and space details
$ df -h
Line starting with /dev/sda1 (marked yellow) is the one we are looking for. As we can see /dev/sda1 is used 100%.
If you see the use rate is over 80%, that’s probably a dangerous sign.
Step 0.2: Check partition
Check for the partition details
Step 0.3: Resize the disk on the Compute engine page
Now we need to resize the disk under
Compute engine > Disk
Go to the disk attached to this VM and click on the edit
Resize the disk to the needed size and click on save.
Step 0.3: If root partition is completely full 100% follow below step or skip to Step 0.4
Mount a temp folder
sudo mount -o size=10M,rw,nodev,nosuid -t tmpfs tmpfs /tmp
Step 0.4: Grow the partition
sudo growpart /dev/sda1
Step 0.4: Resize file system
lsblk
to verify partition has expandedsudo resize2fs /dev/sda1
Final Step:
Run df -h
to verify your resized disk
If followed Step 0.3 use below command to delete the temp mountsudo umount /tmp
Enjoy all done !!