Change the order of disks for a migrating VM

Problem

There is no way to change the order of disks for a migrating VM.

Environment

  • Compute Engine

Solution

The disks can be cloned and connected in the correct order to a new VM on Google Compute Engine.

  1. Stop the VM.
  2. Clone the original boot disk:
    gcloud compute disks create -project=$PROJECT --zone=$ZONE --source-disk=$DISK new-disk-name
  3. Run the following to reassign the license to the boot disk and to add relevant tags (Example with windows2008-r2):
    gcloud compute disks create --project=$PROJECT --zone=$ZONE --source-disk=<disk created on step #2> --licenses=projects/windows-cloud/global/licenses/windows-server-2008-r2-dc --guest-os-features=VIRTIO_SCSI_MULTIQUEUE,MULTI_IP_SUBNET,WINDOWS new-disk-name
  4. Detach the current boot disk and attach it to the Additional disks.
  5. Remove the original boot disk from the Additional disks.
  6. Attach the created disk from step above on the Boot Disk.
  7. Save the changes.
  8. After confirming the VM boot as well, you can delete the original boot disk.

Cause

If the boot partition is not on the first disk (the lowest index on the Bus) at the source, system boot for a test clone or cutover VM may fail. This could be identified by checking if the operating system is installed on the disk marked as the boot disk on the Google Compute Engine image.