6

How do I increase the default 10GB boot drive when I create an instance on the Google Cloud Platform? I've read through different answers regarding this with nothing super clear. I'm sort of a beginner to the platform and I'd really appreciate it if someone could tell me how to do this in simple terms.

GalloCedrone
  • 4,869
  • 3
  • 25
  • 41
robetus
  • 491
  • 1
  • 5
  • 16
  • This might be a duplicate of [this question](http://stackoverflow.com/q/24021214/3618671), please also see answers posted there and close this question if they suffice. – Misha Brukman Jul 11 '14 at 02:15

5 Answers5

12

Use the following steps to increase the boot size with CentOS on the Google Cloud Platform.

ssh into vm instance

[user@user-srv ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.9G  898M  8.5G  10% /
tmpfs                 296M     0  296M   0% /dev/shm
[user@user-srv ~]$ sudo fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
        switch off the mode (command 'c') and change display units to
        sectors (command 'u').

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes
4 heads, 32 sectors/track, 819200 cylinders
Units = cylinders of 128 * 512 = 65536 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0004a990

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1              17      163825    10483712+  83  Linux

Command (m for help): c
DOS Compatibility flag is not set

Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes
4 heads, 32 sectors/track, 819200 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0004a990

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    20969472    10483712+  83  Linux

Command (m for help): p

Disk /dev/sda: 53.7 GB, 53687091200 bytes
4 heads, 32 sectors/track, 819200 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x0004a990

  Device Boot      Start         End      Blocks   Id  System
/dev/sda1            2048    20969472    10483712+  83  Linux

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
Partition 1 is already defined.  Delete it before re-adding it.

Command (m for help): d
Selected partition 1

Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
Using default value 104857599

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[user@user-srv ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.9G  898M  8.5G  10% /
tmpfs                 296M     0  296M   0% /dev/shm
[user@user-srv ~]$ sudo reboot

Broadcast message from user@user-srv
(/dev/pts/0) at 3:48 ...

The system is going down for reboot NOW!
[user@user-srv ~]$ Connection to 23.251.144.204 closed by remote host.
Connection to 23.251.144.204 closed.

Robetus-Mac:~ tomassiro$ gcutil listinstances --project="project-name"
+-------+---------------+---------+----------------+----------------+
| name  | zone          | status  | network-ip     | external-ip    |
+-------+---------------+---------+----------------+----------------+
| srv-1 | us-central1-a | RUNNING | 10.230.224.112 | 107.168.216.20 |
+-------+---------------+---------+----------------+----------------+

ssh into vm instance

[user@user-srv ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1             9.9G  898M  8.5G  10% /
tmpfs                 296M     0  296M   0% /dev/shm

[user@user-srv ~]$ sudo resize2fs /dev/sda1
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/sda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/sda1 to 13106944 (4k) blocks.
The filesystem on /dev/sda1 is now 13106944 blocks long.

[user@user-srv ~]$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              50G  908M   46G   2% /
tmpfs                 296M     0  296M   0% /dev/shm
[user@user-srv ~]$ exit
logout
Connection to 23.251.144.204 closed.
robetus
  • 491
  • 1
  • 5
  • 16
1

The steps are easy:

  1. Create a new disk from an existing source image with bigger size
  2. Create a new instance using the disk you just created (select existing disk)
  3. After the system boot up, using the command "df -h", you can see the storage is still 9.9GB.
  4. Follow the steps (from steps 4-12) in the "Repartitioning a root persistent disk" section in https://developers.google.com/compute/docs/disks
  5. Finished!!
1

Without reboot or restarts increase boot size in GCP cloud VM or Google cloud engine

Check first disk usage is more than 80% df -h of /dev/sda1 if more than 80% it's dangerous.

Update disk size on the fly for VM without restart

  1. Increase disk size from console first
  2. SSH inside VM : sudo growpart /dev/sda 1
  3. Resize your file system : sudo resize2fs /dev/sda1
  4. Verify : df -h
Harsh Manvar
  • 27,020
  • 6
  • 48
  • 102
0

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.
sean
  • 47
  • 6
0

Note that you cannot umount the /dev/sda1 because it's running your OS. But you can create another partition by following:

  1. See available space.

sudo cfdisk

enter image description here

Move with arrows and select Free space , then:

  • Click enter and a new partition will be created
  • Write changes on disk
  • Quit

  1. Format partition (replace sdb1 with yours):

sudo mkfs -t ext4 /dev/sdb1

Check changes: lsblk -f

enter image description here


  1. Mount new partition

sudo mount /dev/sda3 /mnt

testing_22
  • 2,340
  • 1
  • 12
  • 28