In this lab, you will learn how to create persistent disks and add them to virtual machines. You will then create snapshots of disks and additional disks from snapshots.

Disks are used for persistent block storage and can be added to your virtual machines just like you would add additional hard drives to physical servers in your own location.

Snapshots are copies of disks at some moment in time. Snapshots can be used as backups. Additional disks can be created from those snapshots.

What you need

To complete this lab, you need:

What you learn

In this lab, you:

Step 1

Log onto the Google Cloud Platform web console at http://console.cloud.google.com.

Go to your ROICourse project if you are not already there. If you don't have a project, create one now.

Step 2

From the Products and Services menu, choose Compute Engine. At this point, you should have no instances. If you have any, you can delete them now.

Click the Create button to create a new instance.

Step 3

Name your new instance linux-1.

Change the zone to us-central1-b.

From the Boot disk section, click the Change button. Do not change the default OS image, but change the Boot disk size from 10 GB to 15 GB. Then, click the Select button.

Leave all the other settings at their defaults and click the Create button.

Step 4

Wait for the machine to be ready and then SSH into it. Type the following command to see how much disk space you have. It should be around 15 GB.

df -h

Step 5

In the GCP web console, click Disks from the navigation pane on the left.

You should see a disk with the same name as your virtual machine, it should be 15GB big and it should be in the zone us-central1-b (or whatever zone you created the virtual machine in).

Step 6

Click the Create Disk button. Name the disk disk-2. Make sure the disk is in the same zone as your instance (it should be us-central1-b).

Set the Source type to None (blank disk). Make this disk 10 GB big.

Click Create.

Step 7

From the navigation pane on the left, select VM Instances. Click the name of your instance to show its details. On the instance details page, click the Edit button.

Step 8

Scroll down to the Additional disks section and click the Add item button. From the resulting dropdown, select the disk you just created, disk-2.

Scroll to the bottom and click Save.

Step 9

SSH into your virtual machine. Type the following command to see your available disks.

lsblk

You should have two disks now, the first is 15GB and the second is 10GB.

The output should be similar as shown below. In the screenshot below, the second disk's device name is sdb. If your device name is different, make note of it.

Step 10

Enter the following command to format your second disk. (Important: If your second disk's name was something other than sdb, alter the command below accordingly.)

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

You should have two disks now, the first is 15GB and the second is 10GB.

Step 11

Enter the following command to create a mount directory for your new disk.

sudo mkdir -p /mnt/disks/disk2

Step 12

Enter the following command to mount your disk into the mount directory you just created. (Important: If your second disk's name was something other than sdb, alter the command below accordingly.)

sudo mount -o discard,defaults /dev/sdb /mnt/disks/disk2

Step 13

Enter the following command to give read/write access to the drive.

sudo chmod a+w /mnt/disks/disk2

Step 14

Test your new drive.

First, cd into it:

cd /mnt/disks/disk2

Second, add a file to it.

touch afile.txt

Last, see if the new file is there.

ls

Step 15

For additional information on adding and resizing disks, see the documentation located at the URL below.

https://cloud.google.com/compute/docs/disks/add-persistent-disk

Step 1

A snapshot is a copy of a disk at some moment in time. It is dangerous to create a snapshot while a disk is attached to a running machine. In class, we could likely get away with it, but let's stop the machine before creating the snapshot.

Go to the VM instances page, select the machine you created in this exercise, and click the Stop button.

Step 2

Click the Snapshots link on the left side of the GCP console, and click the Create Snapshot button. Create a snapshot of disk-2. Give it any name you like.

Step 3

Go to the Disks page. Create a new disk based on the snapshot you just created. Maked the new disk a little larger. You could now add that disk to an instance if you like.

Step 1

Go to the VM instances page and delete all your instances.

Step 2

Go to the Disks page and delete all your disks.

Step 3

Go to the Snapshots page and delete all your snapshots.

Step 1

Create a Windows server, then create a second disk and attach it to your Windows server.

RDP into your Windows server and use the disk manager to format this drive and assign a letter to it.

For more detailed instructions, see the documentation below.

https://cloud.google.com/compute/docs/disks/add-persistent-disk

Step 2

Don't forget to delete everything when you are done.