Creating Customized Root Disks

This page shows you how to create a root disk for your instance from a public image, a custom image, or a snapshot from a root disk.

Google Compute Engine automatically creates a root persistent disk when you create an instance. If you require additional data storage space for your instances, add one or more secondary instance storage options.

However, in some situations you might need to create a standalone root persistent disk and attach it to an instance later, or resize a root persistent disk to improve performance and add more room for additional application or operating system files.

Before you begin

Creating a standalone root persistent disk from an image

You can create a standalone root persistent disk outside of instance creation and attach it to an instance afterwards.

Console

  1. Go to the Create a new disk page.

    Go to the Create a new disk page

  2. Under Source type, select Image. Choose an image from the list.
  3. Create your disk.

gcloud

To create a standalone root persistent disk, use the gcloud compute disks create command:

gcloud compute disks create example-disk --image example-image

API

To create a new root persistent disk using the API, use the following URI:

https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/disks?sourceImage=IMAGE

Where IMAGE is the URL-encoded, fully-qualified URI of the source image to apply to this persistent disk.

The request body must contain a name for this new persistent disk:

{
  "name": "example-disk"
}

If you created a root persistent disk that is larger than the image, you might need to repartition the root persistent disk.

Create a root persistent disk from a snapshot

After you create a snapshot of a root persistent disk, you can apply data from that snapshot to new persistent disks. It is only possible to apply data from a snapshot when you first create a persistent disk. You cannot apply a snapshot to an existing persistent disk, or apply a snapshot to persistent disks that belong to a different project than that snapshot.

Console

  1. Go to the Create a new disk page.

    Go to the Create a new disk page

  2. Under Source type, select Snapshot.
  3. Choose a snapshot from the list.
  4. Finish setting the properties for your disk and create it.

gcloud

To apply data from persistent disk snapshot, run the following command:

gcloud compute disks create example-disk --source-snapshot example-snapshot

API

To create a new root persistent disk with a snapshot, make a POST request to the following URI:

POST https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-f/disks

The request body must contain a name for this new persistent disk and the URL to the snapshot to use:

{
  "name": "example-disk",
  "sourceSnapshot": "zones/us-central1-f/snapshots/example-snapshot"
}

Resizing a root persistent disk

If your instances require additional storage space, you can attach a persistent disk or connect another instance storage option. However, in some situations your root persistent disk might require additional space for the operating system data.

You can resize root persistent disks even if they are attached to running instances. For example, if you have a default 10GB root persistent disk and you require 40GB of additional space or better performance for that disk, you can resize the disk to 50GB.

Console

Resize the persistent disk in the Google Cloud Platform Console:

  1. Go to the VM instances page.

    Go to the VM instances page

  2. Click the name of the root disk that you want to resize.
  3. At the top of the disk details page, click Edit.
  4. In the Size field, enter the new size for your disk.
  5. At the bottom of the disk details page, click Save to apply your changes to the disk.
  6. After you resize the disk, you must repartition the root persistent disk so that the operating system can access the additional space. Some operating systems support automatic root disk resizing, so you can simply restart the instance.

gcloud

In the gcloud beta tool, use the disks resize command and specify the --size flag with the desired disk size in GB.

gcloud beta compute disks resize example-instance --size 50

After you resize the disk, you must repartition the root persistent disk so that the operating system can access the additional space. Some operating systems support automatic root disk resizing, so you can simply restart the instance.

API

In the API, construct a POST request to the compute.disks.resize method. In the request body, specify the sizeGb parameter and set it to the desired disk size in GB.

POST https://www.googleapis.com/compute/beta/projects/myproject/zones/us-east1-d/disks/example-instance/resize

{
 "sizeGb": "50"
}

After you resize the disk, you must repartition the root persistent disk so that the operating system can access the additional space. Some operating systems support automatic root disk resizing, so you can simply restart the instance.

Repartition a root persistent disk

If you create or resize a root persistent disk or create a disk from an image or a snapshot, your virtual machine instance can automatically resize the partition to recognize the additional space after you restart the instance.

In some cases, depending on the operating system, this behavior might not be supported yet. If this is the case for your operating system, you can manually repartition your disk.

Check to see if your instance's operating system supports automatic resizing.

Checking if your operating system supports automatic resizing

Use the following table to check if your operating system performs automatic disk resizing during boot time. If it does, you do not need to repartition your disk to use additional space. If not, you can manually repartition your disk.

Operating systems supported by Compute Engine team Automatic Resizing
Ubuntu Yes.

All Compute Engine Ubuntu images will automatically resize the root partition to use the entire disk, up to a 2 TB limit. Even if the disk is larger than 2 TB, the operating system only recognizes up to 2 TB.

Windows Yes.

All Windows images will automatically resize the root partition up to 2 TB limit. Even if the disk is larger than 2 TB, the operating system only recognizes up to 2 TB.

Debian 8
v20160606 or newer
Yes.

These images will automatically resize root partitions up to 2 TB. Even if the disk is larger than 2 TB, the operating system recognizes only up to 2 TB.

CentOS 6 & CentOS 7
v20160418 or newer
Yes.

These images will automatically resize root partitions up to 2 TB. Even if the disk is larger than 2 TB, the operating system only recognizes up to 2 TB.

RHEL 6 & RHEL 7
v20160418 or newer
Yes.

These images will automatically resize root partitions up to 2 TB. Even if the disk is larger than 2 TB, the operating system only recognizes up to 2 TB.

CoreOS Yes.

These images will automatically resize root partitions up to 2 TB. Even if the disk is larger than 2 TB, the operating system only recognizes up to 2 TB.

All other operating systems supported by Compute Engine No.

All other operating systems supported by the Compute Engine team will only partition enough space for the root filesystem, and do not currently recognize the additional space until you repartition the disk manually.

For operating systems that are supported by external vendors and communities, you must follow resizing instructions provided by the respective operating system vendor.

For a full list of all available operating systems, see Operating Systems.

Repartitioning a root persistent disk

If you are using an operating system that does not support automatic resizing of the root partition, you can manually repartition the root disk using the steps below.

  1. Create a snapshot of your root persistent disk to back up your data.

  2. If you haven't already, create your root persistent disk:

    gcloud compute disks create example-disk --image IMAGE --size 60GB
    
  3. Start a virtual machine instance using your root persistent disk.

    gcloud compute instances create example-instance --disk name=example-disk,boot=yes
    
  4. SSH into your instance using the gcloud compute ssh command:

    gcloud compute ssh example-instance
    
  5. Check the current size of your root persistent disk:

    $ df -h
    Filesystem                                              Size  Used Avail Use% Mounted on
    rootfs                                                  9.9G  523M  8.9G   6% /
    ...
    /dev/disk/by-uuid/d2eff345-780f-44f7-9c95-f8dde40c6505  9.9G  523M  8.9G   6% /
    ...
    

    Notice that, although the disk you created earlier was 60 GB, only the standard 10 GB of root disk space is being recognized.

  6. Run fdisk.

    $ sudo fdisk /dev/sda
    

    Note: If you are running a CentOS 6 or RHEL 6 image, you must disable DOS compatibility and change the unit to sectors to complete this step. CentOS 6 and RHEL 6 start fdisk in a deprecated mode that is DOS-compatible, but will cause an alignment error in your persistent disks.

    Enter the following commands in your prompt to turn off DOS compatibility mode:

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

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

  7. When prompted, enter p to print the current state of /dev/sda. This displays the actual size of your root persistent disk (here, roughly 50 GB):

    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: 0x000d975a
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048    20971519    10484736   83  Linux
    
  8. Make note of the device ID number and the Start sector value for future steps. In this example, the device ID is 83 and the start sector value is 2048.

  9. Next, enter d at the prompt to delete the logical partition at /dev/sda1 so you can resize the partition. This won't delete any files on the system.

    Command (m for help): d
    Selected partition 1
    
  10. Enter p at the prompt to verify that the original partition has been deleted. The device table should now be empty, as seen here:

    Command (m for help): p
    
    Disk /dev/sda: 53.7 GB, 53687091200 bytes
    ...
    
       Device Boot      Start         End      Blocks   Id  System
    
  11. Enter n at the prompt to create a new partition. Select the default values for partition type and number when prompted. When asked for the first cylinder, provide the Start sector value that you noted from the steps above. In this example, the first sector is 2048.

    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 1
    First cylinder (2048-104857599, default 2048): 2048
    Last cylinder, +sectors or +size{K,M,G} (2048-104857599, default 104857599):
    Using default value 104857599
    
  12. Verify that your partition was created:

    Command (m for help): p
    
    Disk /dev/sda: 53.7 GB, 53687091200 bytes
    ...
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1            2048   104857599    52427776   83  Linux
    
  13. Verify that the device ID matches the one you noted earlier. Here, the device ID matches the original ID of 83.

  14. Commit your changes by entering w at the prompt:

    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.
    
  15. Reboot your instance.

    $ sudo reboot
    

    Rebooting closes your current SSH connection. Wait a couple minutes before performing another SSH connection.

  16. SSH into your instance again.

    gcloud compute ssh example-instance
    
  17. Check the file system type on the root disk. RHEL 7 or CentOS 7 operating systems use file systems other than ext4 on their root persistent disks, which require different partition managment commands.

    $ sudo parted /dev/sda 'print'
    Number  Start   End     Size    Type     File system  Flags
    1      2097kB  10.7GB  10.7GB  primary  ext4         boot
    

  18. Resize your filesystem to the full size of the partition. If your root disk is formatted in ext4, use the resize2fs command. If your root disk uses xfs, use the xfs_growfs command.

    resize2fs:

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

    xfs_growfs:

    $ sudo xfs_growfs /
    meta-data=/dev/sda1              isize=256    agcount=4, agsize=655232 blks
    data blocks changed from 2620928 to 5242624
    

  19. Verify that your filesystem is now the correct size.

    $ df -h
    Filesystem                          Size  Used Avail Use% Mounted on
    rootfs                               60G  533M   56G   1% /
    ...
    

Send feedback about...

Compute Engine Documentation