1

I want to use the gcloud CLI to create new instances based on a machine image. I can create the instance just fine, but I can't figure out how to add additional storage to the instance. beyond the fixed size of the machine image's boot disk (in this case 30GB). If I don't use the "--source-machine-image" option, I can create a boot disk or additional disk of any size and I see it when I type "lsblk", but so far nothing I've tried actually gives me an extra disk that shows up on the instance.

2

To create a VM instance you can use the following command:

gcloud compute instances create VM_NAME \
    [--image IMAGE | --image-family IMAGE_FAMILY] \
    --image-project IMAGE_PROJECT

And --source-machine-image is the option that you can use to create your instance from a machine image.

Here you have two options to add additional storage to the instance, and you could check this documentation for further details.

  1. Resizing a zonal persistent disk

You can resize zonal persistent disks when your instances require more storage, and attach multiple secondary disks only when you need to separate your data into unique partitions.

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

gcloud compute disks resize DISK_NAME --size DISK_SIZE
  1. Adding a blank zonal persistent disk to your instance
gcloud compute disks create DISK_NAME \
  --size DISK_SIZE \
  --type DISK_TYPE

After you create the disk, attach it to any running or stopped instance. Use the gcloud compute instances attach-disk command:

gcloud compute instances attach-disk INSTANCE_NAME \
  --disk DISK_NAME

Keep in mind that a new blank zonal persistent disk starts with no data or file system and you must format this disk yourself after you attach it to your instance, you can follow this documentation for this task : Formatting and mounting a zonal persistent dis

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.