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
- Go toCompute Engine then select Disks.
- Click CREATE DISK.
- Name the disk
disk-1
- Assign the disk to the
us-east1
region, and zoneus-east1-b
. - Change the Size (GB) to
100
. - Click on the command line button beneath the Create button.
- Save the
gcloud
command line for later reference. - Close out of the gcloud reference, then click Create.
- Resize Disk Using the Web Console
- From the Disks screen, click on
disk-1
. - Click the EDIT button.
- Change the size from
100
to150
. - Click Save.
- From the Disks screen, click on
- Create Linux Instance and Attach the Disk
- Click VM instances in the left-hand menu.
- Click Create, and set the following values:
- Name: linux-instance
- Region: us-east1
- Zone: us-east1-b
- Under the Firewall section, click to expand Management, security, disks, networking, sole tenancy.
- Click the Disks tab.
- Click Attach existing disk.
- In the Disk dropdown, choose disk-1.
- Click Done.
- Click Create.
- Format and Mount a Disk in the Linux Instance
- Click on SSH to log in to our
linux-instance
instance. - Enter
lsblk
to view all disks. - Format disk
sdb
:sudo mkfs.ext4 -m 0 -F -E lazy_itable_init=0,lazy_journal_init=0,discard /dev/sdb
- Create the disk mount directory:
sudo mkdir -p /mnt/disks/disk2
- Mount the disk:
sudo mount -o discard,defaults /dev/sdb /mnt/disks/disk2
- Set the
read/write
permissions:sudo chmod a+w /mnt/disks/
- Verify that the disk is mounted using either the
lsblk
ordf -h
commands.
- Click on SSH to log in to our
- Create a Disk with `gcloud`
- Open the Cloud Shell
- Type the following command to create a disk named
disk-2
in the zoneus-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`
- Resize the
disk-2
disk to150GB
. Confirm that you want to complete this when prompted:gcloud compute disks resize disk-2 --size=150 --zone=us-east1-b
- Next, enter the
gcloud
command to create a Windows instance namedwindows-instance
in zoneus-east1-b
. We will not attach ourdisk-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`
- Now that we have created our Windows instance let’s attach our
disk-2
disk to the instancegcloud compute instances attach-disk windows-instance --disk=disk-2 --zone=us-east1-b
- Resize the
- Create Windows Instance with `gcloud`
- From the web console, go back to your VM Instances page.
- Under
windows-instance
, select the dropdown menu next to RDP, and select Set Windows password. - Keep username as
admin
, and click SET. - 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`
- Connect to your Windows instance via RDP.
- 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
Close out of the Server Manager – Dashboard screen
Click the magnifying glass icon in the bottom left.
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:
If you are not automatically prompted, from Disk Management, scroll down to
Disk 1
, which is listed as Not Initialized.Right-click on
Disk 1
on the left side, and click on Initialize Disk.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.
Next, right-click on the disk
bar
next toDisk 1
, and select New Simple Volume.Click Next through all prompts, accepting all defaults, to quickly format and allocate space.