Default images have 10GB, but I need more (30GB approx). If I create a disk of 30GB using one of that default images, the usable space it's 10GB, not 30GB. I know I can install the distro using tools like debootstrap, but that seems unnecessarily complicated. is there any other way to do it?
相关问题
- How to prevent windows from accessing and detectin
- compute engine use gsutil to download tgz file has
- Flask app cannot open server to Google Cloud Compu
- VM Instance is not accessible The project you requ
- Adding a billing method with google cloud results
相关文章
- How do I create a persistent volume claim with Rea
- Can you get a static external IP address for Googl
- Google Compute Engine VM instance: VFS: Unable to
- Setting environment variable for a Compute Engine
- Windows Server 2012 VM created from Snapshot fails
- connect Google App Engine and Google Compute Engin
- Deploying a nodejs app to the google cloud platfor
- Why Google Cloud Compute Engine instance gives ssh
Here are the steps I followed to resize a Google Cloud compute instance. It's not enough to just create a new instance with a bigger disk, you also need to modify the partition and extend the filesystem as follows:
Last two steps are described in detail here:
https://cloud.google.com/compute/docs/disks/persistent-disks#manualrepartition
You'll then need to cut over to your new instance as required or you could restart your original instance with the newly created disk image.
You can create a boot disk larger than 10GB but then you'll need to repartition it, because by default, the provided VM images expand to 10GB so you'll need to use these instructions and run
fdisk
, reboot, and then runresize2fs
to expand the usable space to the full size of the disk. You can automate it so that it runs as part of instance creation by using startup scripts.Edit 1: I have open-sourced my scripts which do this for you automatically at boot using the
startup-script
metadata. You can find sample code in my GitHub repo created specifically for this question, which has been verified to work with CentOS and Debian. Seefdisk.sh
for the repartitioning andgcloud.sh
for the deployment commands.Edit 2: Alternatively, you can also create an additional disk and attach it to your instance but you'll also need to format and mount it before you can use it.
When you create an instance and specify a larger root disk size than the default, your instance will still end up with a partition table and filesystem size of 10GB.
In order to use the extra space you'll need to expand the /dev/sda1 partition and then resize the filesystem on it.
To resize the /dev/sda1 partition (THIS IS DANGEROUS AND SHOULD ONLY BE DONE INSIDE A BRAND NEW CLEAN INSTANCE):
To resize the root filesystem:
You should be good to go after this.
I've added the following to an instance's 'startup-script' metadata so it resizes on the first two boots:
Adapt this to your needs, and test it first! I've only tested on CentOS 6. Also, this does not necessarily work if you want to keep an instance disk at 10 GB (IOPS is best at 200 GB or larger, so, unless IO is of no concern to you, I suggest always creating larger disks).
The general idea can be applied on your startup-script: check the disk partition size to see if it's larger than the default for the image Google supplied. If it's the same as Google's default, run
fdisk
for the maximum size permitted on the virtual hard disk and reboot. Upon the next boot, check the file system size and resize to the maximum size of the partition. Once those two actions are performed, it'll be skipped on subsequent reboots.A safer method than editing the partition directly and which doesn't require maintaining your own images, is dracut's growroot module & cloud-init.
I've used this with CentOS 6 & 7 on Google Compute, AWS & Azure.
The partition will be resized automatically during the next boot.
Notes:
This may be a new feature as of this writing, but go to
So, one approach to answering your question is to create an instance with the default disk and simply resize it via the Compute Engine GUI.