How to get a bigger boot disk on Google Compute Engine [closed]
Asked Answered
M

9

4

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?

Muncy answered 3/6, 2014 at 17:17 Comment(0)
L
7

This may be a new feature as of this writing, but go to

  1. https://console.cloud.google.com/compute/
  2. Click on Disks in the left menu
  3. In the main pane that loads, click on your instance
  4. In the upper horizontal menu that loads, click on Edit
  5. The former disk size will become editable. Change the disk size to your desired size.
  6. Restart your instance (sudo restart -r now). On reboot, df -h lists your new disk size.

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.

Lyford answered 20/1, 2016 at 17:38 Comment(1)
It was only solution that worked for me (using containerOS), do you have a workaround without having to restart the VM ?Nehru
C
6

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 run resize2fs 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. See fdisk.sh for the repartitioning and gcloud.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.

Cup answered 8/6, 2014 at 3:17 Comment(6)
Are only some images able to support this? I'm trying to repartition the container-vm image and reboot hangs at Booting from Hard Disk... Booting from 0000:7c00Assignment
@financeCoding I've verified that it works with CentOS6 and Debian7, so the container-vm image should have worked since it's based on Debian7 as well, but I've verified that it hangs as you described. I'm still looking into it and am not yet sure what is going on here. I'll post an update when I figure it out.Cup
@financeCoding I've updated my repo with an additional script growroot.sh which uses cloud-init and cloud-initramfs-growroot which works well to repartition the container-vm image. I've incorporated it into my gcutil.sh script so it should be easy to use. Please try it out and let me know if it works for you.Cup
@financeCoding see my answer elsewhere with an auto-resizing image based on container-vm using Packer.Cup
Your link is broken. To repartition disk follow this instructions : cloud.google.com/compute/docs/disks/…Fosterfosterage
@Fosterfosterage — thanks for the note! I've updated my answer. FYI, the link was valid at the time I wrote the answer, which was in June 2014, but has changed since then. BTW, you can also edit others' answers directly to fix issues such as broken links.Cup
G
1

You can easily do this without having to manually resize/partition/format a disk or any of the complications introduced in all the other answers on StackOverflow. All you really need to do is:

  1. Separately create a new disk with the desired capacity based on the image you want to use.
  2. Choose that disk as the boot disk for the instance you're creating.

Here's a detailed explanation of how to do this using the Google Developers Console:

First, you'll have to create a new blank disk to be used as the root partition for your new instance. To do this, go to Compute / Compute Engine / Disks and click "New disk". Remember to make sure the disk is in the same zone as the instance you want to launch otherwise you wont be able to use it. Next, change the "Source Type" for the disk to "Image". Then select the appropriate image and specify the disk size you want and hit Create.

Now that you have your boot disk ready, go to create your new instance (Compute / Compute Engine / VM Instances and click "New instance"). In the new instance form, change the Boot Source to Existing Disk and select the disk you just created.

It should be relatively simple to do the same thing using a couple of gcloud commands.

Geraldgeralda answered 25/1, 2015 at 13:29 Comment(6)
This might also work for snapshot-based instances too but I'm not sure as I haven't tried that yet.Geraldgeralda
I try to reproduce it with the centos-6, but it doesn't resize automatically. :(Predikant
Were you using an image or a snapshot? Can you give more details?Geraldgeralda
I have tried an image and a snapshot at the asia-east1-b zone. The df command show me 10G, fdisk show 100G. i.imgur.com/nsHiBDq.pngPredikant
I am so sorry, The docs said, centos is not supported the auto-resize: cloud.google.com/compute/docs/disks/…Predikant
Interesting. I have to admit, I tried it on Ubuntu and just assumed it worked everywhere :/Geraldgeralda
C
1

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.

## you'll need to be root or use sudo
yum -y install epel-release
yum -y install cloud-init cloud-initramfs-tools dracut-modules-growroot cloud-utils-growpart
rpm -qa kernel | sed -e 's/^kernel-//' | xargs -I {} dracut -f /boot/initramfs-{}.img {}
# reboot for the resize to take affect

The partition will be resized automatically during the next boot.

Notes:

  • This is built into Ubuntu, which is why you don't see the problem there.
  • The partition size problem is seen with RedHat & CentOS with most pre-built images, not only Google Cloud. This method should work anywhere.
Christoffer answered 31/8, 2015 at 17:37 Comment(0)
C
0

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

echo "16," | sudo sfdisk /dev/sda
sudo reboot

To resize the root filesystem:

sudo resize2fs /dev/sda1

You should be good to go after this.

Conti answered 6/6, 2014 at 18:10 Comment(0)
L
0

Consider to add aditional persitance disc toyour instance which will hold user application data. It migth be very usefull later. Because you your application data may evolve and scale in diffrent ways and of course independent of choosed OS. E.G you can do snapshots of that addtional disc independently. With that you gane full flexibility of your data in the cloud and you don't need to take OS with you data ;) P.S. Of coure new Desics of snapshots can be greater. See instructions abowe

Laceration answered 19/8, 2014 at 11:51 Comment(0)
R
0

I've added the following to an instance's 'startup-script' metadata so it resizes on the first two boots:

# Resize /dev/sda1 primary disk partition to use full space if not already done
if [[ "$(fdisk -l /dev/sda1 | grep '^Disk.*10\.[0-9] GB' | sed 's/.*, \([0-9]*\) bytes$/\1/')" -eq 10735321600 ]]; then
  echo -e "c\nu\nd\nn\np\n1\n\n\nw\n" | fdisk /dev/sda
  reboot
elif [[ "$(df -P /dev/sda1 | tail -n +2 | awk '{print $2}')" -le 10319160 ]]; then
  resize2fs /dev/sda1
fi

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.

Reproduction answered 15/1, 2015 at 16:12 Comment(0)
K
0

First create a disk from UI with existing image. Now use this image when creating an instance.

Kesha answered 9/3, 2015 at 7:21 Comment(1)
that will only make another partition, you will have the original partition plus a new one with the space you requested when creating the new image.Jural
F
0

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:

  • Create a new disk snapshot on original instance
  • Create new compute instance with boot disk based on that snapshot with the new desired size
  • ssh to your new compute instance
  • as root use fdisk to resize the partition
  • as root use resize2fs to extend the root partition

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.

Fayre answered 2/9, 2015 at 5:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.