DEV Community

Dian Fay
Dian Fay

Posted on • Originally published at di.nmfay.com

Populating GCE Persistent Disks

This is one of those things I didn't expect to be quite this involved and couldn't find a step-by-step guide for. I just want to allocate a disk out there in The Cloud and put something on it, right? The idea being that then I spin up a cluster and my fancy application server container startup script pulls that static data off the disk and performs whatever initialization is required. It doesn't sound especially complicated.

But as yet, there's no "upload some stuff" button in the Google Cloud Engine console, and gcloud compute scp only works for VM instances. There's nothing sitting in front of a Persistent Disk that will just pull your data into it. So, you have to create one:

  1. Spin up a new VM instance in the Compute Engine screens. You'll need to be an iam.serviceAccountUser for the project.
  2. Once it's running, log in:

    gcloud compute --project "my-project" ssh --zone "us-central1-b" "my-new-instance"

  3. lsblk shows devices as usual. Find yours. Now format it:

  4. sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdwhatever

  5. Create a mountpoint and sudo mount -o discard,defaults /dev/sdwhatever /mnt/my-mount-point.

  6. Add your files, then clean up after yourself and umount the mountpoint.

Delete the instance from the VM Instances page. A GCE Persistent Disk can't be attached in read/write mode to more than one instance or container, also something to be mindful of if you're adding it to a deployment with multiple replicas.

Top comments (0)