Question

Difficulty: MediumDeploying and Managing Compute Engine Virtual Machines

A Cloud Engineer needs to restore a corrupted boot disk on a Compute Engine virtual machine instance named `app-server-1` using an existing disk snapshot named `app-boot-snapshot-v2`. In what sequence should the engineer execute the `gcloud` operations to replace the boot disk and restore the server?

  1. 1Stop the instance using `gcloud compute instances stop app-server-1`.
  2. 2Create a new persistent disk from the snapshot using `gcloud compute disks create restored-disk --source-snapshot=app-boot-snapshot-v2`.
  3. 3Detach the corrupted boot disk using `gcloud compute instances detach-disk app-server-1 --disk=corrupted-disk`.
  4. 4Attach the restored disk as the new boot disk using `gcloud compute instances attach-disk app-server-1 --disk=restored-disk --boot`.
  5. 5Start the instance using `gcloud compute instances start app-server-1`.

Answer

The correct operational sequence to restore the VM boot disk from a snapshot is: 1) Stop the `app-server-1` VM instance; 2) Create a new persistent disk from the snapshot; 3) Detach the corrupted boot disk; 4) Attach the new persistent disk with the `--boot` flag; 5) Start the VM instance.
To replace a boot disk on a Compute Engine instance using a snapshot, the engineer must follow a strict order: first, stop the instance because root disks cannot be detached while active; second, restore the snapshot to a new persistent disk; third, detach the broken boot disk; fourth, attach the newly restored disk using the `--boot` flag to declare it as the OS boot drive; and finally, start the VM instance.

Step-by-Step Solution

1
Stop the target VM instance
The instance transitions from `RUNNING` to `TERMINATED` state.
Compute Engine requires a virtual machine to be stopped before its boot disk can be detached or modified.
2
Provision a new persistent disk from the target snapshot
A standalone bootable persistent disk resource is generated containing data from the snapshot.
Snapshots represent point-in-time backups and must be instantiated into persistent disk objects before attachment.
3
Detach the failed boot disk volume from the VM
The VM instance metadata releases the existing boot disk reference.
Detaching the damaged volume clears the primary attachment interface for the replacement disk.
4
Attach the new persistent disk with boot priority
The restored disk is linked to the VM instance as index 0 (boot disk).
Including the `--boot` flag explicitly marks the volume as the bootable root disk rather than an additional data volume.
5
Start the repaired VM instance
The VM boots up using the restored operating system image.
Starting the instance executes the bootloader from the newly designated boot disk.

Key Concept

Compute Engine VM Boot Disk Replacement & Snapshot Recovery
Rate this question