Bird
Raised Fist0
GCPcloud~5 mins

Boot disk images in GCP - Commands & Configuration

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Boot disk images are pre-made snapshots of operating systems that help start virtual machines quickly. They solve the problem of setting up a new server by providing a ready-to-use system image.
When you want to create a new virtual machine with a specific operating system quickly.
When you need to ensure all your virtual machines start with the same software setup.
When you want to test software on different operating systems without installing them manually.
When you want to restore a virtual machine to a known good state using a saved image.
When you want to customize a base image and reuse it for multiple virtual machines.
Commands
This command lists all available boot disk images in the Debian Cloud project. It helps you find the exact image name to use when creating a VM.
Terminal
gcloud compute images list --project=debian-cloud
Expected OutputExpected
NAME FAMILY DEPRECATED STATUS debian-11-bullseye-v20240612 debian-11 READY debian-10-buster-v20240612 debian-10 READY ...
--project - Specifies the project that holds the images to list.
This command creates a new virtual machine named example-vm in the us-central1-a zone using the Debian 11 boot disk image. It shows how to launch a VM with a specific boot image.
Terminal
gcloud compute instances create example-vm --zone=us-central1-a --image=debian-11-bullseye-v20240612 --image-project=debian-cloud
Expected OutputExpected
Created [https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-a/instances/example-vm]. NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS example-vm us-central1-a e2-medium 10.128.0.2 34.68.123.45 RUNNING
--zone - Specifies the zone where the VM will be created.
--image - Specifies the boot disk image to use for the VM.
--image-project - Specifies the project that contains the boot disk image.
This command shows detailed information about the example-vm instance, including the boot disk image used. It helps verify the VM's configuration.
Terminal
gcloud compute instances describe example-vm --zone=us-central1-a
Expected OutputExpected
name: example-vm zone: projects/my-project/zones/us-central1-a disks: - boot: true initializeParams: sourceImage: projects/debian-cloud/global/images/debian-11-bullseye-v20240612 deviceName: example-vm type: PERSISTENT status: RUNNING
--zone - Specifies the zone of the VM to describe.
Key Concept

If you remember nothing else from this pattern, remember: boot disk images are ready-made operating system snapshots that let you start virtual machines quickly and consistently.

Common Mistakes
Using an incorrect or misspelled image name when creating a VM.
The VM creation fails because the specified image does not exist.
Always list available images with 'gcloud compute images list' and copy the exact image name.
Not specifying the correct image project with --image-project flag.
The command cannot find the image because it looks in the wrong project.
Use the --image-project flag to specify the project that owns the image, like 'debian-cloud'.
Summary
List available boot disk images to find the right operating system snapshot.
Create a virtual machine using a specific boot disk image and zone.
Verify the VM's boot disk image by describing the instance details.

Practice

(1/5)
1. What is the main purpose of a boot disk image in Google Cloud Platform (GCP)?
easy
A. It stores user data separately from the VM.
B. It provides the operating system for a virtual machine (VM).
C. It manages network traffic for the VM.
D. It controls billing and usage reports.

Solution

  1. Step 1: Understand the role of boot disk images

    Boot disk images contain the operating system that a VM uses to start and run.
  2. Step 2: Identify the correct function in GCP context

    In GCP, the boot disk image is the source of the OS for the VM instance.
  3. Final Answer:

    It provides the operating system for a virtual machine (VM). -> Option B
  4. Quick Check:

    Boot disk image = OS provider [OK]
Hint: Boot disk image = OS for VM startup [OK]
Common Mistakes:
  • Confusing boot disk image with data disk
  • Thinking it manages network or billing
  • Assuming it stores user files
2. Which of the following is the correct command to list all available public boot disk images in GCP using gcloud CLI?
easy
A. gcloud compute images list --project=debian-cloud
B. gcloud compute instances list --images
C. gcloud compute disks list --public
D. gcloud compute images list --public

Solution

  1. Step 1: Recall the correct gcloud command for listing images

    The command to list images uses 'gcloud compute images list' with a project filter for public images.
  2. Step 2: Identify the public image project

    Public images like Debian are under projects such as 'debian-cloud'. So filtering by --project=debian-cloud lists those images.
  3. Final Answer:

    gcloud compute images list --project=debian-cloud -> Option A
  4. Quick Check:

    List images by project = gcloud compute images list --project=debian-cloud [OK]
Hint: Use --project with public image project name [OK]
Common Mistakes:
  • Using --public flag which does not exist
  • Listing disks instead of images
  • Listing instances instead of images
3. Consider this snippet to create a VM with a boot disk image:
gcloud compute instances create my-vm \
--image-family=ubuntu-2204-lts \
--image-project=ubuntu-os-cloud

What OS will the VM run?
medium
A. Debian 10
B. CentOS 7
C. Ubuntu 22.04 LTS
D. Windows Server 2019

Solution

  1. Step 1: Analyze the image family and project

    The image family 'ubuntu-2204-lts' in project 'ubuntu-os-cloud' refers to Ubuntu 22.04 Long Term Support.
  2. Step 2: Match image family to OS version

    Ubuntu 22.04 LTS is the latest stable Ubuntu release matching the image family name.
  3. Final Answer:

    Ubuntu 22.04 LTS -> Option C
  4. Quick Check:

    Image family ubuntu-2204-lts = Ubuntu 22.04 LTS [OK]
Hint: Image family name shows OS version clearly [OK]
Common Mistakes:
  • Confusing Ubuntu with Debian or CentOS
  • Ignoring image-project parameter
  • Assuming Windows from Linux image family
4. You tried to create a VM with this command:
gcloud compute instances create test-vm \
--image-family=centos-7 \
--image-project=centos-cloud \
--boot-disk-size=5GB

The command fails with an error about disk size. What is the likely cause?
medium
A. The VM name 'test-vm' is invalid.
B. The image family name is incorrect.
C. The project name 'centos-cloud' does not exist.
D. The boot disk size is too small for the CentOS 7 image.

Solution

  1. Step 1: Understand boot disk size requirements

    CentOS 7 images require a minimum boot disk size larger than 5GB, usually 10GB or more.
  2. Step 2: Check command parameters

    The image family and project are correct, and VM name is valid, so the error is due to insufficient disk size.
  3. Final Answer:

    The boot disk size is too small for the CentOS 7 image. -> Option D
  4. Quick Check:

    Disk size too small causes boot failure [OK]
Hint: Check minimum disk size for image before creating VM [OK]
Common Mistakes:
  • Assuming image family or project is wrong
  • Ignoring disk size minimum requirements
  • Thinking VM name causes disk size error
5. You want to create a custom boot disk image from an existing VM's disk to use for multiple new VMs. Which steps should you follow?
hard
A. Create a snapshot of the VM's boot disk, then create an image from the snapshot.
B. Directly copy the VM instance to create new VMs without images.
C. Export the VM's disk to a local file, then upload it as an image.
D. Create a new VM and select the existing VM's disk as boot disk.

Solution

  1. Step 1: Create a snapshot of the existing VM's boot disk

    This captures the current state of the disk safely and efficiently.
  2. Step 2: Create a custom image from the snapshot

    Using the snapshot, you create a reusable boot disk image for new VMs.
  3. Final Answer:

    Create a snapshot of the VM's boot disk, then create an image from the snapshot. -> Option A
  4. Quick Check:

    Snapshot then image = reusable boot disk [OK]
Hint: Snapshot first, then create image for reuse [OK]
Common Mistakes:
  • Trying to copy VM directly without image
  • Exporting disk unnecessarily
  • Using existing disk directly for new VMs