Table of Contents
You can also attach and mount new additional disk to your instance instead of resizing your disk.
Prerequisites
- SSH access to your VM Instance.
- Backup your disk by creating a snapshot of your disk. You can also setup automatic snapshot schedules.
- Basic SSH terminal skills to execute commands.
Important: You can only enlarge the size of the existing disk, you cannot shrink your disk to lower size.
Step 1: Check Disk Size
Before resizing your disk size you can check your available disk space so you will get an idea about the available space in your disk. It is recommended to increase the size if your used space is more than 80%.
Execute the following command to check the disk space.
df -h
You will get an output similar to the one below.
Output
Filesystem Size Used Avail Use% Mounted on
udev 286M 0 286M 0% /dev
tmpfs 60M 2.4M 57M 4% /run
/dev/sda1 9.8G 1.1G 8.2G 12% /
tmpfs 297M 0 297M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 297M 0 297M 0% /sys/fs/cgroup
Here /dev/sda1
is the one which shows the available and used space of your disk. I tested this on a new fresh disk with 10GB space.
Step 2: Check Partition
Now you need to check the partitions available on the your disk.
lsblk
This command shows the available partitions. You will get an output similar to this.
Output
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 10G 0 disk
└─sda1 8:1 0 10G 0 part /
In this case we having only one partition.
As you can see, sda
is the DEVICE_ID
and 1
is the partition number.
Step 3: Increase Disk Size
Go to your Google Cloud Console and navigate to Compute >> VM Instances.
Click the name of the instance where you want to add a disk.
Scroll down to Boot disk and click on the disk name.
Now you will be taken to the Disk Management page.
Click Edit on the top.
Here you can specify the size of you need.
Click Save in the bottom to apply the changes.

Step 4: Grow Partition
Now you need to resize the partition using the growpart
command with your device id and partition number.
sudo growpart /dev/sda 1
You will get something similar.
Output
CHANGED: partition=1 start=4096 old: size=20967424 end=20971520 new: size=1048571871,end=1048575967
Step 5: Resize File System
The last step is to resize the filesystem with the resize2fs
command.
sudo resize2fs /dev/sda1
The output will be like this.
Output
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 63
The filesystem on /dev/sda1 is now 131071483 (4k) blocks long.
Step 6: Verify the Setup
Now you can verify the disk space using the df
command. Your disk space must have rezised to the additional space you added.
df -h
Output
Filesystem Size Used Avail Use% Mounted on
udev 286M 0 286M 0% /dev
tmpfs 60M 2.4M 57M 4% /run
/dev/sda1 493G 1.2G 471G 1% /
tmpfs 297M 0 297M 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 297M 0 297M 0% /sys/fs/cgroup
Get your Professional Google Cloud Architect certificate with this easy to learn course now.
Conclusion
Now you have learned how to resize your VM Instance without restarting and without downtime.
You are the Boss!
Worked as explained. Thanks for the instructions.
If I do all these steps to increase the size, does it mean it will remove all the existing data from the boot disk??
No, it wont remove the existing data. Your data will be there as it is.
Like a Charm