After going through number of articles, forums and user guides, finally I am able to spin the Windows VM Instance successfully from Snapshot.
The issue was with bootloader and Boot Configuration Data (BCD). Ideally you use Images for OS Disk. In my case OS and data were in same disk and we just had a Snapshot. GCE allows creating new VM instance from Snapshot but in my case the instance was not booting up.
Follow the step by step guide to recover your OS/Data from snapshot.
Summary:
Create Disk from Snapshot and fix the disk BCD using new temporary VM Instance.
Detailed StepsStep 1: Create Recovery VM Instance and Start it
This instance is temporary instance and you may delete it after you recover your OS / data.
From Google Cloud Console
Select Compute Engine > VM Instances and select CREATE INSTANCE
Make sure you select the same OS as the Snapshot. Once started, make sure you can do remote desktop and login to new VM instance.
Note down instance name and zone in which the instance is running.
Step 2: Create New Disk from Snapshot
From Google Cloud Console
Select Compute Engine > Disks and select CREATE DISK
Make Sure you select the same Disk size / Disk Type as on/before taking snapshot else Windows may throw boot error. Also make sure the disk is in same zone as your recovery instance. If your disk is not in same zone as in your instance then you won't be able to attach it.
Step 3: Attach the Disk to Recovery Instance
In this step you attach the disk you (created in Step-2) to VM instance (created in Step-1)
Open Google Cloud Shell and type the following command
gcloud compute instances attach-disk [INSTANCE-NAME] --disk [DISK-NAME] --zone [ZONE]
Replace the variables with your Instance name, Disk name and Zone in which you are running the instance.
Step 4: Mount Disk and assign Drive letter in Windows
Go to Start > Search and type diskmgmt.msc to open the Disk Management tool. If the disk you just attached, shows up as Offline, right-click on it and select Online.
After making sure the disk is Online, verify that each volume on the disk has a drive letter assigned. The specific drive letters assigned is not important. If any of the volumes do not have a drive letter assignment, right-click the volume and select Change Drive Letter and Paths, then Add. Select Assign the following drive letter, let it choose the next available drive letter, then click OK. Again, the actual drive letters used doesn’t matter.
Note down the Drive letter. For me its D: drive.
Step 6: Remove write-protection from disk
Try creating a new folder in your attached drive. If your disk is write-protected and you are not able to create any file or folder in the drive then you need to turn-off the write-protection, otherwise you can skip this step.
Open Elevated Command Prompt (run as Administrator) and type
diskpart
and you will get DISKPART> prompt
Type:
list volume
System will display all volumes with number. Next you need to select the volume by typing:
select volume #
where # is the volume number. For me it's 1.
Then type following commands remove write-protection
attr disk clear readonly
attr volume clear readonly
attr volume clear hidden
attr volume clear shadowcopy
Exit diskpart by typing exit or closing command prompt window. Open the drive in Windows Explorer. You should be able to see all your data and Windows system files. Create a new folder in the drive to make sure disk is not write-protected.
Step 7: Fix Boot Configuration Data (BCD)
If you are familiar with Windows bcedit command, then by all means use bcedit, but I used EasyBCD for fixing the boot configuration data.
Download and install EasyBCD on your Recovery VM Instance from https://neosmart.net/EasyBCD
Once installed open EasyBCD and click on
File > Select BCD Store
and file selection dialog under filename enter D:\Boot\BCD or whatever drive letter you assigned in Step 5. The system will show you Boot Configuration Data for your drive.
Click on Edit Boot Menu button and select Skip the boot menu and click on Save settings.
Click on Advanced Settings button and under the Basic tab click on Drive: menu and select the Drive letter of the disk.
Please note: The drive letter should be the same as Step-5
Click on BCD Backup/Repair button and under the BCD management options select Re-create/repair boot files and click on Perform Action button.
Make the disk offline by Opening Disk Management again and right-click the disk and select Offline.
Now minimize your RDP window and in Google Cloud Shell type following command to detach the disk from Recovery instance
gcloud compute instances detach-disk [INSTANCE-NAME] --disk [DISK-NAME] --zone [ZONE]
Now you have fixed the Boot Configuration Data of the Disk created from Snapshot.
We are now ready to spin the VM Instance and boot it using this disk. Let's create instance from disk
Step 8: Create new VM Instance
From Google Cloud Console select Compute Engine > VM Instances and select CREATE INSTANCE
In order to avoid any problem at first run, make sure you select the same Machine Type as on/before the snapshot creation.
At this point you should be able to have working VM instance and you should be able to do RDP login.
In case you are still facing any issues, then have a look at your serial port log by clicking the VM instance in Google Cloud Console and then scroll down to bottom of the page or you can type the following command in Google Cloud Shell.
gcloud compute instances get-serial-port-output [INSTANCE-NAME] --zone [ZONE]
Lesson Learned
- For OS disks with / without data, use images instead of snapshots.
- Do not keep your data in same disk as OS even if it's a test machine and you are doing some temporary work.