Checkpoints
Create a new instance in the specified zone.
/ 40
Create a new persistent disk in the specified zone.
/ 30
Attaching and Mounting the persistent disk.
/ 30
Creating a Persistent Disk
GSP004
Overview
Compute Engine lets you create and run virtual machines on Google infrastructure. You can create virtual machines running different operating systems, including multiple flavors of Linux (Debian, Ubuntu, Suse, Red Hat, CoreOS) and Windows Server!
Compute Engine provides persistent disks for use as the primary storage for your virtual machine instances. Like physical hard drives, persistent disks exist independently of the rest of your machine – if a virtual machine instance is deleted, the attached persistent disk continues to retain its data and can be attached to another instance.
- Standard persistent disk
- SSD Persistent disk
In this hands-on lab, you'll learn how to create a persistent disk and attach it to a virtual machine.
What you'll learn
- Create a new VM instance and attach a persistent disk
- Format and mount a persistent disk
Prerequisites
- Familiarity with standard Linux text editors such as
vim
,emacs
ornano
will be helpful
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Activate Cloud Shell
Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.
- Click Activate Cloud Shell at the top of the Google Cloud console.
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
- (Optional) You can list the active account name with this command:
- Click Authorize.
Output:
- (Optional) You can list the project ID with this command:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Set the region and zone
- Set the project region and zone for this lab:
- Create a variable for region:
- Create a variable for zone:
Learn more from the Regions & Zones documentation.
gcloud
on your own machine, the config settings are persisted across sessions. But in Cloud Shell, you need to set this for every new session or reconnection.
Task 1. Create a new instance
First, create a Compute Engine virtual machine instance that has only a boot disk.
- In Cloud Shell command line, use the
gcloud
command to create a new virtual machine instance namedgcelab
:
Example Output:
The newly created virtual machine instance will have a default 10 GB persistent disk as the boot disk.
Click Check my progress to verify the objective.
Task 2. Create a new persistent disk
- Still in the Cloud Shell command line, use the following command to create a new disk named
mydisk
:
Output:
Click Check my progress to verify the objective.
Task 3. Attaching a disk
Attaching the persistent disk
You can attach a disk to a running virtual machine. Attach the new disk (mydisk
) to the virtual machine instance you just created (gcelab
).
- Use the following command to attach the disk:
Output:
That's it!
Finding the persistent disk in the virtual machine
The persistent disk is now available as a block device in the virtual machine instance. Let's take a look.
- SSH into the virtual machine:
Output:
- At the prompt, enter Y to continue.
- When prompted for an RSA key pair passphrase, press ENTER for no passphrase, and then press ENTER again to confirm no passphrase.
Output:
- Now find the disk device by listing the disk devices in
/dev/disk/by-id/.
:
Output:
You found the file, the default name is:
scsi-0Google_PersistentDisk_persistent-disk-1.
device-name
parameter. For example, to specify a device name, when you attach the disk you would use the command:
gcloud compute instances attach-disk gcelab --disk mydisk --device-name <YOUR_DEVICE_NAME> --zone $ZONE
Formatting and mounting the persistent disk
Once you find the block device, you can partition the disk, format it, and then mount it using the following Linux utilities:
-
mkfs:
creates a filesystem -
mount
: attaches to a filesystem
- Make a mount point:
- Next, format the disk with a single
ext4
filesystem using the mkfs tool. This command deletes all data from the specified disk:
Last lines of the output:
- Now use the mount tool to mount the disk to the instance with the
discard
option enabled:
That's it!
Automatically mount the disk on restart
By default the disk will not be remounted if your virtual machine restarts. To make sure the disk is remounted on restart, you need to add an entry into /etc/fstab
.
- Open
/etc/fstab
in nano to edit:
- Add the following below the line that starts with "UUID=...":
/etc/fstab
content should look like this:
- Save and exit nano by pressing CTRL+O, ENTER, CTRL+X, in that order.
Click Check my progress to verify the objective.
Task 4. Test your knowledge
Test your knowledge about Google cloud Platform by taking this quiz.
For migrating data from a persistent disk to another region, reorder the following steps in which they should be performed:
- Attach disk
- Create disk
- Create snapshot
- Create instance
- Unmount file system(s)
Task 5. Local SSDs
Compute Engine can also attach local SSDs. Local SSDs are physically attached to the server hosting the virtual machine instance to which they are mounted. This tight coupling offers superior performance, with very high input/output operations per second (IOPS) and very low latency compared to persistent disks.
Local SSD performance offers:
- Less than 1 ms of latency
- Up to 680,000 read IOPs and 360,000 write IOPs
These performance gains require certain trade-offs in availability, durability, and flexibility. Because of these trade-offs, local SSD storage is not automatically replicated and all data can be lost in the event of a host error or a user configuration error that makes the disk unreachable. Users must take extra precautions to backup their data.
This lab does not cover local SSDs.
- To maximize the local SSD performance, you'll need to use a special Linux image that supports NVMe. You can learn more about local SSDs in the Local SSD documentation.
Congratulations!
You've learned how to create, find, and attach persistent disks to a virtual machine instance and the key difference between persistent disks and local SSDs. You can use persistent disks to setup and configure your database servers.
Next steps / Learn more
- Persistent Disk Documentation
-
gcloud
Documentation and tutorial video.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated: January 15, 2024
Lab Last Tested: January 15, 2024
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.