How to increase Google Cloud virtual machine disk size

Increase Google Cloud virtual machine instance disk size without service interruption.

Google Cloud

Use gcloud command-line utility to increase available disk space.

$ gcloud compute disks resize personal-instance-1 --size 200G --zone europe-west1-b --project personal-project


This command increases disk size. This change is not reversible.
For more information, see:
https://cloud.google.com/sdk/gcloud/reference/compute/disks/resize

Do you want to continue (Y/n)?

Updated [https://www.googleapis.com/compute/v1/projects/personal-project/zones/europe-west1-b/disks/personal-instance-1].
---
creationTimestamp: '2019-05-31T01:37:32.808-07:00'
id: '1336862165669075235'
kind: compute#disk
labelFingerprint: 42WmSpB8rSM=
lastAttachTimestamp: '2019-05-31T01:37:32.809-07:00'
licenseCodes:
- '1000207'
licenses:
- https://www.googleapis.com/compute/v1/projects/centos-cloud/global/licenses/centos-7
name: personal-instance-1
physicalBlockSizeBytes: '4096'
selfLink: https://www.googleapis.com/compute/v1/projects/personal-project/zones/europe-west1-b/disks/personal-instance-1
sizeGb: '200'
sourceImage: https://www.googleapis.com/compute/v1/projects/personal-project/global/images/lpp-elastic-base-image-20190531073519
sourceImageId: '4276414890599343955'
status: READY
type: https://www.googleapis.com/compute/v1/projects/personal-project/zones/europe-west1-b/diskTypes/pd-standard
users:
- https://www.googleapis.com/compute/v1/projects/personal-project/zones/europe-west1-b/instances/personal-instance-1
zone: https://www.googleapis.com/compute/v1/projects/personal-project/zones/europe-west1-b


To take a quick anonymous survey, run:
  $ gcloud alpha survey

You are halfway through, now you need to update instance configuration.

Debian

Inspect available and allocated disk space.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
└─sda1   8:1    0  100G  0 part /
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.8G     0  1.8G   0% /dev
tmpfs           371M   11M  360M   3% /run
/dev/sda1        99G  1.1G   94G   2% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup

I will use growpart utility. It is provided by the cloud-guest-utils package.

$ dpkg-query -S growpart
cloud-guest-utils: /usr/share/man/man1/growpart.1.gz
cloud-guest-utils: /usr/bin/growpart

Expand disk partition.

$ sudo growpart /dev/sda 1
CHANGED: partition=1 start=4096 old: size=209711071 end=209715167 new: size=419426271,end=419430367

Inspect allocated disk space.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
└─sda1   8:1    0  200G  0 part /

Inspect filesystem type.

$ sudo blkid /dev/sda1
/dev/sda1: UUID="1e33928a-82a6-4e67-62f3-1b7b9b2603d7" TYPE="ext4" PARTUUID="5b8988ba-01"

Resize filesystem.

$ sudo resize2fs /dev/sda1
resize2fs 1.43.4 (31-Jan-2017)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old_desc_blocks = 13, new_desc_blocks = 25
The filesystem on /dev/sda1 is now 52428283 (4k) blocks long.

Inspect available disk space.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.8G     0  1.8G   0% /dev
tmpfs           371M   11M  360M   3% /run
/dev/sda1       197G  1.1G  188G   1% /
tmpfs           1.9G     0  1.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           1.9G     0  1.9G   0% /sys/fs/cgroup

Done.

CentOS

Inspect available and allocated disk space.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
└─sda1   8:1    0  100G  0 part /
$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       100G   61G   40G  61% /
devtmpfs        6,3G     0  6,3G   0% /dev
tmpfs           6,3G     0  6,3G   0% /dev/shm
tmpfs           6,3G  121M  6,2G   2% /run
tmpfs           6,3G     0  6,3G   0% /sys/fs/cgroup
tmpfs           1,3G     0  1,3G   0% /run/user/1052

I will use growpart utility.

Notice, growpart utility is provided by the gce-disk-expand package.
$ rpm -qf /bin/growpart
gce-disk-expand-1.0.5-1505406172.el7.x86_64

Expand disk partition.

$ sudo growpart /dev/sda 1
CHANGED: partition=1 start=2048 old: size=209710462 end=209712510 new: size=419422972,end=419425020

Inspect allocated disk space.

$ lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  200G  0 disk
└─sda1   8:1    0  200G  0 part /

Inspect filesystem type.

$ sudo blkid /dev/sda1
/dev/sda1: LABEL="/" UUID="43e9328e-3216-47e6-82fe-1b709b26b3d7" TYPE="xfs"

Resize filesystem.

$ sudo xfs_growfs /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=41, agsize=655296 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=26213807, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Inspect available disk space.

$ df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       200G   61G  140G  31% /
devtmpfs        6.3G     0  6.3G   0% /dev
tmpfs           6.3G     0  6.3G   0% /dev/shm
tmpfs           6.3G  121M  6.2G   2% /run
tmpfs           6.3G     0  6.3G   0% /sys/fs/cgroup
tmpfs           1.3G     0  1.3G   0% /run/user/1052

Additional information

Inspect Google Cloud image packages and Google Cloud images.