How to Resize Disk of a VM Instance in Google Cloud. In this guide you are going to learn how to resize the disk space of your Compute Engine instance on the fly without any downtime.
You can also attach and mount new additional disk to your instance instead of resizing your disk.
- 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.
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
/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.
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
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
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.
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.
Now you have learned how to resize your VM Instance without restarting and without downtime.
I don’t see the size option on the Disk Management page. Any ideas on what else I can do?
You need to click the edit button on your disk details page to see the size option
Easy to follow and worked like a charm…. great article many thanks
For windows cloud instance I have updated disk size from 100 GB to 500 GB, but it is not reflecting. What could be the reason?
F0r Windows instance you need to follow this
1. Login with RDP
2. Open a command prompt, and then run the diskmgmt.msc command to launch Disk Management. For Action, choose Refresh.
3. Open the context (right-click) menu for the Volume, and then choose Extend Volume.
4. Choose Next, Next, Finish.
Thx guys, you are definetly life savers. Helped many times to me while dealing my own web server.
Thanks for the good post! Helped a lot
Like a Charm
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.
Worked as explained. Thanks for the instructions.
You are the Boss!