GCP VM with 99,8% full disk has not resized its file system after increasing the disk capacity in google console.
I have a small VM on GCP based on public image ubuntu-2004-focal-v20220419
.
There was a 10GB disk with root partition and file system.
Some logs occupied 99,8% of the disk capacity.
I increased the disk size to 15GB (without removing any data) and restarted the VM.
Documentation says:
For VMs with public images, Compute Engine automatically resizes the root partition and file system after you increase the size of the boot disk and restart the VM.
however, I can see that file system was not resized
~$ sudo lsblk
sda 8:0 0 15G 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
I am wondering why is it so? I expected that additional 5GBs will be merged with sda1
automatically based on above documentation. Could it be, that the disk is so full, so some GCP background processes are not able to resize the file system?
2
Answers
I have posted my solution on Server Fault community. I hope this will be helpful for someone. https://serverfault.com/a/1119504/450511
I gave this response in order to assist other communities with this problem, and @John Hanley responded with a suitable response in the comment area.
Important notes:
Step 1 – Create a default instance in the Google Console for testing.
The default disk size is 10 GB.
Step 2 – Connect to the instance.
Go to the Google Console -> Compute Engine. A list of VM instances is displayed. On the line with your instance, click “SSH”. You can also use the CLI: “gcloud compute ssh <instance_name>”.
Execute the “df” command and record the output.
Step 3 – Shutdown the instance.
Step 4 – Resize the disk to 16 GB.
Go to the Google Console -> Compute Engine -> Disks. Select the disk for the instance. Click the edit button and resize the disk to 16 GB.
Step 5 – Start the instance and connect with SSH.
Step 6 – Execute the “df” command again.
Comparing the line for /dev/sda1 confirms that Debian 9 Stretch on Google Compute does automatically resize the root file system. Now I wanted to know how.
Step 7 – Get the serial port console output.
Documentation for gcloud compute instances get-serial-port-output.
Step 8 – Analyze the Console Output.
This produced about 1,000 lines. To reduce this output I used grep to search for output that is probably related to resizing the file system. Notice how I spelled “resiz”. I want the search to include “resize” and “resizing”.
This produced the following:
Step 9 – Figure out what command is used to resize the root file system.
From the console output I can see the command “expand-root.sh”. Using the command “which expand-root.sh”, I found this command located at “/usr/bin/expand-root.sh”.
Debian 9 Stretch running on Google Cloud Compute Engine does resize the root volume automatically if you resize the root disk. Very nice.
Google Cloud offers the feature to resize the disk while the VM instance is running. Can you resize the root disk and the root filesystem while the system is running? If so, how?
Step 1 – Go to the Google Console -> Compute Engine -> Disks. Select the disk for the instance.
Step 2 – Click the “CREATE SNAPSHOT” button to create a recovery snapshot.
Step 3 – Click the edit button and resize the disk to 25 GB.
Step 4 – Connect to the instance.
Step 5 – Execute this command to see the disk size and partition layout:
This command produces the following output:
Notice that the disk size is reported as “25 Gib” but the partition size is still “15G”. This means that the disk drive was resized to 25 GB but the root partition (filesystem) stayed the same size. Let’s try to resize the root filesystem while the system is running.
Automating the Resize
Now let’s take this even further and completely automate resizing a VM disk and resizing the root filesystem from the command line or a script.
STEP 1 – SNAPSHOT DISK.
First, we will snapshot the disk just in case.
Documentation for gcloud compute disks snapshot.
STEP 2 – RESIZE DISK.
This command will resize the VM instance disk. Modify for the size you require, disk name and zone. Notice the –quiet flag. This prevents the prompt to confirm the resize.
Documentation for gcloud compute disks resize.
STEP 3 – RESIZE ROOT FILESYSTEM.
This command will use SSH to connect to the instance and execute the expand-root.sh program remotely.
Documentation for gcloud compute ssh.
STEP 4 – VERIFY RESIZE.
A final “df” command on the on VM instance shows that the new root filesystem is 30 GB (30,896,016 blocks).
This is the complete blog-link to @John Hanley’s documentation.