113

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.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
Rishin S Babu
  • 1,553
  • 3
  • 13
  • 16
  • See also [this answer](http://stackoverflow.com/a/24102667/3618671) on a similar question. – Misha Brukman Dec 19 '14 at 17:19
  • 1
    possible duplicate of [How to get a bigger boot disk on Google Compute Engine](http://stackoverflow.com/questions/24021214/how-to-get-a-bigger-boot-disk-on-google-compute-engine) – maljub01 Jan 25 '15 at 13:40
  • 1
    Do sudo growpart /dev/sda 1 && sudo xfs_growfs /dev/sda1 after @MishaBrukman steps below. No reboot required for this. – Martin Karari Jul 20 '20 at 09:10

10 Answers10

271

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.
  2. Select Disks under the "Storage" section.
  3. Click on the name of the disk that you want to resize to get to the disk details page.
  4. At the top of the disk details page, click "Edit".
  5. In the "Size" field, enter the new size for your disk.
  6. At the bottom of the disk details page, click "Save" to apply your changes to the disk.
  7. 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.

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
  • Can you please explain point 6 with an example. I tried resize2fs but its not working for me sudo resize2fs /dev/sda1 resize2fs 1.42.13 (17-May-2015) The filesystem is already 2621179 (4k) blocks long. Nothing to do! – Aftab Naveed Jul 26 '17 at 13:36
  • @AftabNaveed – some OSes do this for you automatically, so there's nothing to do, as it says. Is the total size of the partition matching the full size of the disk? Ubuntu is one of those systems that can auto-resize on the fly with a reboot (without `fdisk` or `resize2fs`), so this could happen in that case. – Misha Brukman Jul 26 '17 at 14:01
  • 3
    @AftabNaveed – see [this page](https://cloud.google.com/compute/docs/disks/create-root-persistent-disks#repartitionrootpd) for operating systems that support auto-resizing partitions during a reboot. You can resize a non-root partition with `resize2fs` on the fly without a reboot, but if it's the boot partition, you need to reboot, and no additional commands are necessary. – Misha Brukman Jul 26 '17 at 14:06
  • 3
    Thanks for the reply, I just had to reboot it. – Aftab Naveed Jul 26 '17 at 14:10
  • I cannot find `At the top of the disk details page, click Edit.` – user1700890 Jan 04 '18 at 15:54
  • 1
    @user1700890 — did you open the [list of disks](https://console.cloud.google.com/compute/disks) in your project, and then click on a specific disk first? Then, you should see an Edit button at the top of the page for that specific disk. – Misha Brukman Jan 05 '18 at 03:45
  • 20
    Without rebooting: ```sudo growpart /dev/sda 1 && sudo resize2fs /dev/sda1``` – gdaras Oct 03 '19 at 14:27
  • 4
    without rebooting with centos/xfs : `dnf install cloud-utils-growpart -y && growpart /dev/sda 1 && xfs_growfs -d / ` – tisc0 May 14 '20 at 13:34
  • 1
    It worked for me on Debian Stretch without any resizing. A reboot helped. Thanks – Karthik Sunil Oct 08 '20 at 15:23
  • Note that if you're truly out of space, you'll need to do something like `sudo bash -c "TMPDIR=/run growpart /dev/sda 1"` (because there is some vestigial `mktemp` in the `growpart` script). – jhfrontz Aug 19 '21 at 15:55
  • I don't see the edit button either, did a find in the page not there. Made sure I was on the disk detail page. Was able to get it to work from the CLI, thank you. – dllahr Jan 02 '22 at 22:54
  • Great answer. For me, with both a login and controller, `sudo growpart /dev/sda 2` was necessary – Mathews24 Apr 11 '23 at 00:06
  • On Debian 11 (Bullseye) `sfdisk` is available from the `fdisk` package and it's required by the `growpart` command – Andre Miras May 15 '23 at 18:22
26
  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)
user1130176
  • 1,772
  • 1
  • 23
  • 33
  • 2
    Cool. worked. But be aware of reboot that is needed. – aholbreich Nov 25 '14 at 21:11
  • 4th step is also mentioned in the cloud docs. ` Resize your filesystem to the full size of the partition: user@mytestinstance:~$ sudo resize2fs /dev/sda1 resize2fs 1.42.5 (29-Jul-2012) Filesystem at /dev/sda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 4 The filesystem on /dev/sda1 is now 13106944 blocks long.` – Kevin Siji Dec 05 '14 at 04:39
  • Yep, the 4th step is now there, it wasn't at the time of my writing. – user1130176 Dec 05 '14 at 14:53
  • The link you point to in 3rd step is no longer useful -- it's just an overview about disks. Can you explain how to embiggen the partition? Thanks. – e18r Feb 17 '15 at 15:29
  • looks like they moved the route, try this: https://cloud.google.com/compute/docs/disks/persistent-disks#repartitionrootpd – user1130176 Feb 24 '15 at 05:07
  • 8
    A truly cromulent answer. – orrymr Dec 17 '15 at 09:30
  • 4
    Be aware that an easier and quicker option is available in the answer by Misha Brukman below. – Aldekein Jan 05 '17 at 14:20
5

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.

Brian Dorsey
  • 4,588
  • 24
  • 27
5

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.

  • -bash: xfs_growfs: command not found, where is this command located? – omerio Feb 28 '16 at 15:12
  • You might be using a different/older version of CentOS, if you are using CentOS at all. Basically, if you're using CentOS 6 you'd have `resize2fs` and using CentOS you'd have `xfs_growfs`. – mohsenrezaeithe Feb 29 '16 at 23:53
  • You can check this automated script : https://gist.github.com/OmarTrigui/7d6ec92c8f2ef83ba15b80e30fb6a5be – Omar_0x80 Feb 09 '17 at 01:57
3

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).

Benoît Sauvère
  • 701
  • 7
  • 23
  • It _is_ usable as a startup script, but you have to be careful to distinguish the current state that you're in and do different things (or nothing) depending on the state of the disk. For more details, see [my answer](http://stackoverflow.com/a/24102667/3618671) which links to a `fdisk.sh` script I wrote which does exactly this. – Misha Brukman Jul 12 '16 at 00:38
3

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.

Inbar Rose
  • 41,843
  • 24
  • 85
  • 131
2

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)

Misha Brukman
  • 12,938
  • 4
  • 61
  • 78
Igor Belianski
  • 181
  • 1
  • 3
1

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

robetus
  • 491
  • 1
  • 5
  • 16
0

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
d-_-b
  • 21,536
  • 40
  • 150
  • 256
0

now its has changed the command , always better to follow Google Documentation. as of Sep 2nd 2022.

https://cloud.google.com/compute/docs/disks/resize-persistent-disk

Before resize disk:-

mgadage8@vm:~$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 9.9G 0 part / ├─sda14 8:14 0 3M 0 part └─sda15 8:15 0 124M 0 part /boot/efi mgadage8@vm:~$ df -h Filesystem Size Used Avail Use% Mounted on udev 1.8G 0 1.8G 0% /dev tmpfs 368M 368K 368M 1% /run /dev/sda1 9.7G 1.7G 7.5G 19% / tmpfs 1.8G 0 1.8G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock /dev/sda15 124M 5.9M 118M 5% /boot/efi tmpfs 368M 0 368M 0% /run/user/1000

Shiv
  • 144
  • 10