How can size of the root disk in Google Compute Engine be increased?

CloudGoogle Compute-EngineGoogle Cloud-Platform

Cloud Problem Overview


The root disk size in GCE is 10 gigs. How do I increase this? I cant find the option in the console or the gcutil flags. This can be easily done in AWS.

Cloud Solutions


Solution 1 - Cloud

As of 31 Mar 2016, you can resize a persistent disk online without stopping or rebooting the VM, without taking snapshots, and without having to restore it to a larger disk.

The blog post announcing the feature has the details, and you can see the docs for how to do this via the console:

> Resize the persistent disk in the Google Cloud Platform Console: > > 1. Click on Compute Engine product tab. > 1. Select Disks under the "Storage" section. > 1. Click on the name of the disk that you want to resize to get to the disk details page. > 1. At the top of the disk details page, click "Edit". > 1. In the "Size" field, enter the new size for your disk. > 1. At the bottom of the disk details page, click "Save" to apply your changes to the disk. > 1. After you resize the disk, you must resize the disk partitions so that the operating system can access the additional space.

Or via CLI:

gcloud compute disks resize example-disk --size 250

Then, on Debian/Ubuntu/etc. run:

$ sudo apt install -y cloud-utils         # Debian jessie
$ sudo apt install -y cloud-guest-utils   # Debian stretch, Ubuntu
$ sudo growpart /dev/sda 1
$ sudo resize2fs /dev/sda1

or, for RedHat/Fedora/CentOS/etc.:

$ sudo dnf install -y cloud-utils-growpart
$ sudo growpart /dev/sda 1
$ sudo xfs_growfs -d /                    # CentOS 6 needs `resize2fs`

Note that some operating systems will automatically resize your partition on reboot without requiring you to do any manual steps with tools such as fdisk, resize2fs or xfs_growfs, so it should be sufficient to just resize the disk and reboot the VM for changes to take effect.

Solution 2 - Cloud

  1. create a new disk from snapshot, but increase the size when doing so
  2. create a new instance, using new, embiggened disk
  3. embiggen the partition to recognize the new space (https://cloud.google.com/compute/docs/disks/persistent-disks#repartitionrootpd) (NOTE: pay special attention to the starting sector, don't just blindly hit return, you can, however blindly hit return on the ending sector)
  4. sudo resize2fs /dev/sda1 (note, this step is not mentioned in the google cloud docs)

Solution 3 - Cloud

In most cases, it will be simpler and more flexible to create a second data disk of the size you want, and attach it to the instance.

To resize a Persistent Disk (including a root disk), snapshot the disk, then create a new larger disk from the snapshot.

Solution 4 - Cloud

This is more like a follow-up to @user1130176's answer, but if you are running CentOS 7+, you'll need to do the following for step #4 (expanding the filesystem): xfs_growfs /dev/sda1

The new disks on CentOS 7 are of type xfs. Hope this helps, it was not very clear from all the links around.

Solution 5 - Cloud

Since the new GCoud command line tool you can choose your boot disk size and type at the instance creation:

gcloud compute instances create foo-instance --boot-disk-size 100 --image "xxxxxx"

Then resize the root partition using these instructions: https://cloud.google.com/compute/docs/disks#repartitionrootpd

Documentation : https://cloud.google.com/sdk/gcloud/reference/compute/instances/create

Edit: After resizing the root partition, you have to reboot your instance to force the system to re-read the partition table. That makes this trick unusable in a startup script (executed on each startup/reboot).

Solution 6 - Cloud

I know this is an old topic, but I just did this using a simpler method than the ones explained above. All from the cloud console user interface with no need to worry or do any special commands in just a few minutes and clicks.

However, it requires creating a new instance, not resizing a disk on an already running instance

  1. Create a snapshot of the disk you want to enlarge

    > Click on the instance, then click on the disk, then you have "create snapshot", give it a name and then wait for the snapshot to be created. (You don't need to turn off the instance for this)

  2. Create a new instance from the snapshot and specify the new size

    > Click on the snapshot, then you have "create instance", you can then see the boot disk options, click change and then size it to a new size. (You probably want to change all the default instance settings to the ones you want also)

This is a fool-proof way to enlarge a disk without causing any partition errors, doesn't require any commands or special actions.

The only downside is that you need to create a new instance. You can't just do it on an instance that you already have.

Solution 7 - Cloud

Now you can resize a Persistent Disk in place:

gcloud compute disks resize DISK_NAME [DISK_NAME …] --size SIZE [--zone ZONE]

This would only re-size physical device. file system (and possibly partitions still need to be adjusted after that)

Solution 8 - Cloud

Create a disk first with whatever size and image you want, and then create your instance using Existing Disk as your boot source.

Solution 9 - Cloud

For anyone else unable to find a working answer, I found this script someone kindly posted:

https://gist.github.com/xelwarto/6f5c6556613c9215b1e1

# Requires cloud-utils-growpart to be installed

# Resize ROOT FS
part=`df --output=source / |grep "/dev/"`
if [ ! -z "$part" ] ; then
  len=${#part}
  p=`echo $part|cut -c$len`
  d=`echo $part|cut -c1-$(($len-1))`

  growpart "$d" "$p"
  xfs_growfs "$part"
fi

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRishin S BabuView Question on Stackoverflow
Solution 1 - CloudMisha BrukmanView Answer on Stackoverflow
Solution 2 - Clouduser1130176View Answer on Stackoverflow
Solution 3 - CloudBrian DorseyView Answer on Stackoverflow
Solution 4 - CloudmohsenrezaeitheView Answer on Stackoverflow
Solution 5 - CloudBenoît SauvèreView Answer on Stackoverflow
Solution 6 - CloudInbar RoseView Answer on Stackoverflow
Solution 7 - CloudIgor BelianskiView Answer on Stackoverflow
Solution 8 - CloudconlustroView Answer on Stackoverflow
Solution 9 - Cloudd-_-bView Answer on Stackoverflow