GCP: How to increase the disk space of Linux Machine

In this tutorial, we will learn how to expand or increase the Linux root volume without stopping/shutdown the instance or stopping any services on the Virtual Machine without restart.

In this, we have 2 steps to be followed.

  1. We have to change the volume size of the disk on Google console from disks Menu in GCP Cloud Compute.
  2. We have to increase the partition size on the Linux machine

Google Console Changes

  • Log in to the Google Console.
  • Click on Google Compute Menu and then goto disks
  • Find the disk on which we want to increase the disk space.gcp_disk1
  • Once the Edit, increase the size of the Volume to our need and Click on Size.

gcp_disk2

  • It will take around 5 – 8 min to increase the volume size on the Google console after some time we can see the increased size on the Google console.

Linux Instance Side.

  • Log in to the Instance using the Credentials and corresponding key pair.
  • Check the Existing disk space using the command df –h
$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             100G  90.1M  9.9  90% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
  • Change the login to root user by using sudo –i.
  • Run lsbk to show the block devices attached to the instance.
# lsbk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda    202:0    0   100 G  0 disk
└─sda1 202:1    0   100 G  0 part /

Here if we see that the block device sda has 100 GB attached and having 1 partition with 100  GB for the root

  • Run the growpart command to increase the root partition (/)
# growpart /dev/sda 1

The filesystem on /dev/sda1 is now 18350080 blocks long.

  • Finally, increase the root partition with resize command
# resize2fs /dev/sda1
resize2fs 1.42.3
   Filesystem at /dev/sda1 is mounted on /; on-line resizing required
    old_desc_blocks = 1, new_desc_blocks = 5
    Performing an on-line resize of /dev/sda1 to 18350080 (4k) blocks.
    The filesystem on /dev/sda1 is now 18350080 blocks long.
  • Now if we check the disk space using df, we can observe the disk space has been increased to a size we have extended on the Google Console.
# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1            150G  90.1M  60 G  69% /
tmpfs                 1.9G     0  1.9G   0% /dev/shm
1 comment
  • turkce

    I like the helpful information you provide in your articles. I will bookmark your weblog and check again here regularly. I am quite certain I will learn a lot of new stuff right here! Good luck for the next! Myrah Brodie Harod

Leave a Reply to turkce Cancel Reply

Your email address will not be published.

Have a Question?