Qwiklabs – GCP Essentials – Creating a Persistent Disk – Extending the lab

I really enjoyed the Qwiklabs – GCP Essentials – Creating a Persistent Disk lab, but I think Qwiklabs could extend the lab a bit further by showing how the disk is persistent by blowing  away a VM, starting a new one and reattaching the disk. So I decided to try it. You can follow the steps below  to do just that.

Start here after you’ve finished the “Creating a Persistent Disk” lab.

Let’s create a new folder on our  persistent disk. Run  mkdir /mnt/mydisk  (while still SSH-ing to the VM)

Now add a file there with some text vi /mnt/mydisk/tmp/hello.txt

Press i  to switch to edit mode and type in some text (It was “Hi There!” in my case) then follow this sequence to save Esc : wq

It’s time to say goodbye to your VM and delete it.

In the Cloud Shell execute  gcloud compute instances delete gcelab --zone=us-central1-c  and you will see something similar to the below

You can also go to the Cloud Console and verify that your “old” VM is gone.

Create a new VM (using Cloud Console or Shell) with the  name of  gcelab2

When it is ready use the following command (in the Cloud Shell) to attach the disk:

gcloud compute instances attach-disk gcelab2 --disk mydisk --zone us-central1-c

SSH to the VM

Execute the below commands (similar to the ones you did as part of attaching the persistent disk to gcelab VM) necessary to create  a new mount point and mount the disk. DON’T run the  format (mkfs) command

You can run df -kh  to see the disk mounted and available

Don’t forget to check your message from the old VM

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.