Disk Image - Restoring To Azure
Creating a Virtual Machine in the Azure cloud from a Magnus Box Disk Image Backup
- All example commands executed in Windows Powershell
- Azure accepts only VHD file format, so images must first be converted to this format. Example instructions included below.
- Install and configure MS Azure command-line interface (CLI): https://aka.ms/installazurecliwindows
- If using an existing VM, Microsoft recommends that it be prepared first: https://docs.microsoft.com/en-us/azure/virtual-machines/windows/prepare-for-upload-vhd-image?toc=/azure/virtual-machines/windows/toc.json
A future version of Magnus Box will automate many of the following steps.
Perform restore in Magnus Box to create VMDK files
- Note: The restored files will be the same size as the original disk size, so ensure you have enough space in your restore location.
Produces files as shown below
Convert VMDK to VHD format
- We used QEMU utility with the 1 KB VMDK file from the previous step (with fixed-size-type required by Azure). You can download the utility at this link.
- Example command to convert VMDK file to VHD format:
.\qemu-img.exe convert C:\path\to\disk.vmdk -O vpc -o subformat=fixed C:\path\to\disk.vhd
- Note: The disk.vhd image just produced can now be imported, without further changes, into any locally-installed MS Hyper-V program.
Resize the VHD file upwards to the nearest megabyte multiple if needed
- The size of the disk.vhd file from the previous step must be a multiple of megabytes (ie: the VHD file-size needs to be a number exactly divisible by 1024).
- Example command to find file size:
ls C:\path\to\diskname.vhd = X
- Our example produced a file of size X = 41943040 KB
- X/1024/1024 must be a whole number. You may need to resize your own file upwards to a megabyte-multiple.
- An exact next-biggest megabyte-multiple for our example 40 GB disk = 42951770112 bytes.
- We resize our example file to illustrate:
- Example command to resize the disk.vhd file upwards to a megabyte multiple:
resize-vhd C:\path\to\diskname.vhd -SizeBytes 42951770112
- Note: This creates a resized VHD file of size 42951770624 bytes. Azure 'resize' command adds 512 bytes for their footer 42951770112 + 512
Create empty managed disk on Azure
- Example command to create an empty managed disk on Azure using the size parameter from the previous step:
az disk create --name azure-disk-name --resource-group azure-resource-name --sku standardssd_lrs --hyper-v-generation V1 --location australiaeast --for-upload true --upload-size-bytes 42951770624
- Use your own preference parameters for disk-name, resource-group, hard-disk type, location. Other VM parameters, such as CPU and RAM allocation, can be added later. Location parameter can be selected via:
az account list-locations -o table
Grant write access to obtain ‘sasURI’
- Example command to grant write access to Azure:
az disk grant-access -n azure-disk-name -g azure-resource-name --access-level Write --duration-in-seconds 86400
- Produces an sas-URI: similar to: "https://xx-xxxxx-xxxxxxxxxx.blob.core.windows.net/xxxxxxxxxx/abcd?sv=2017-04-17&sr=b&si=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&sig=xxxx%3D"
- Note: Azure charges while disk is writeable
Upload the VHD file to Azure
- We used the convenient AzCopy https://adamtheautomator.com/azcopy-setup/
- Command format:
AzCopy.exe copy "C:\path\to\diskname.vhd" "sas-URI" --blob-type PageBlob
- Example command to upload the VHD file to Azure, using the sas-URI from the previous step:
AzCopy.exe copy "C:\path\to\diskname.vhd" "https://xx-xxxxx-xxxxxxxxxx.blob.core.windows.net/xxxxxxxxxx/abcd?sv=2017-04-17&sr=b&si=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx&sig=xxxx%3D" --blob-type PageBlob
- Note: To reduce costs, revoke write-access when finished uploading.
- Example command to revoke write access:
az disk revoke-access -n azure-disk-name -g azure-resource-name
Create the new VM in Azure
- Example command to create the new VM in Azure using the azure-disk-name file uploaded from the previous step:
az vm create --resource-group azure-resource-name --location australiaeast --name new-vm-name --os-type windows --attach-os-disk azure-disk-name
- Use your parameters for resource group, location, vm name.
- Example result from command to create new VM in Azure:
Connect via RDP
- Use your preferred Remote Desktop program to connect to the ‘publicIpAddress’ from previous step: “XXX.XXX.XXX.XXX”