Working with Disks on Google Compute Engine

1 hour
  • 9 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we will explore the variety of methods to create, modify, and attach disks in Compute Engine.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Disk Using the Web Console
  1. Go toCompute Engine then select Disks.
  2. Click CREATE DISK.
  3. Name the disk disk-1
  4. Assign the disk to the us-east1 region, and zone us-east1-b.
  5. Change the Size (GB) to 100.
  6. Click on the command line button beneath the Create button.
  7. Save the gcloud command line for later reference.
  8. Close out of the gcloud reference, then click Create.
Resize Disk Using the Web Console
  1. From the Disks screen, click on disk-1.
  2. Click the EDIT button.
  3. Change the size from 100 to 150.
  4. Click Save.
Create Linux Instance and Attach the Disk
  1. Click VM instances in the left-hand menu.
  2. Click Create, and set the following values:
    • Name: linux-instance
    • Region: us-east1
    • Zone: us-east1-b
  3. Under the Firewall section, click to expand Management, security, disks, networking, sole tenancy.
  4. Click the Disks tab.
  5. Click Attach existing disk.
  6. In the Disk dropdown, choose disk-1.
  7. Click Done.
  8. Click Create.
Format and Mount a Disk in the Linux Instance
  1. Click on SSH to log in to our linux-instance instance.
  2. Enter lsblk to view all disks.
  3. Format disk sdb:
    sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
  4. Create the disk mount directory:
    sudo mkdir -p /mnt/disks/disk2
  5. Mount the disk:
    sudo mount -o discard,defaults /dev/sdb /mnt/disks/disk2
  6. Set the read/write permissions:
    sudo chmod a+w /mnt/disks/
  7. Verify that the disk is mounted using either the lsblk or df -h commands.
Create a Disk with `gcloud`
  1. Open the Cloud Shell
  2. Type the following command to create a disk named disk-2 in the zone us-east1-b, and set the size to “`
gcloud compute disks create disk-2 --size=100GB --zone=us-east1-b
If you wish, go back to the Disks menu in the web console to verify every step completes successfully.
Resize Disk with `gcloud`
  1. Resize the disk-2 disk to 150GB. Confirm that you want to complete this when prompted:
    gcloud compute disks resize disk-2 --size=150 --zone=us-east1-b
  2. Next, enter the gcloud command to create a Windows instance named windows-instance in zone us-east1-b. We will not attach our disk-2 disk until after we create the instance:
    gcloud compute instances create windows-instance --zone=us-east1-b --image=windows-server-2019-dc-v20190225 --image-project=windows-cloud --boot-disk-size=50GB`
  3. Now that we have created our Windows instance let’s attach our disk-2 disk to the instance
    
    gcloud compute instances attach-disk windows-instance --disk=disk-2 --zone=us-east1-b
Create Windows Instance with `gcloud`
  1. From the web console, go back to your VM Instances page.
  2. Under windows-instance, select the dropdown menu next to RDP, and select Set Windows password.
  3. Keep username as admin, and click SET.
  4. When it generates a password, copy and paste it into a text editor for reference, then click CLOSE.
Attach Disk to Windows Instance with `gcloud`
  1. Connect to your Windows instance via RDP.
  2. For whichever RDP method you choose, once connected, enter the admin username and the generated password you created above to connect to the instance.
Initialize Disk in Windows Instance
  1. Close out of the Server Manager – Dashboard screen

  2. Click the magnifying glass icon in the bottom left.

  3. Type "create and format hard disk partitions" and select the above match by the same name. You may automatically get a prompt to initialize our disk, if so you can ignore the below step:

  4. If you are not automatically prompted, from Disk Management, scroll down to Disk 1, which is listed as Not Initialized.

  5. Right-click on Disk 1 on the left side, and click on Initialize Disk.

  6. Make sure that Disk 1 is selected, and choose GPT (GUID Partition Table) for the partition style, then click OK.

    Note: There are compatibility reasons to choose MBR over GPT, but we are not concerned about those for this demo.

  7. Next, right-click on the disk bar next to Disk 1, and select New Simple Volume.

  8. Click Next through all prompts, accepting all defaults, to quickly format and allocate space.

Additional Resources

Be sure to launch the lab in incognito mode to avoid cached login issues.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?