Convert Fixed Size VHD for Apple Silicon Mac and Upload to Azure Blob Storage
In this article, we will discuss the process of converting a fixed size VHD specifically for Apple Silicon Mac and then uploading it to the Azure Blob Storage. This task has been challenging due to the limitation of Azure Blob Storage which does not accept dynamic sized VHDs. The common tools used like qemu-img and VBoxManage have not been successful, and thus, we will explore an alternative approach.
What is a VHD?
A Virtual Hard Disk (VHD) is a disk image file format used for virtual machines. It can store the whole operating system, applications, and user data, just like a physical hard disk.
Why convert to a fixed size VHD?
Azure Blob Storage requires a fixed-size VHD for upload. Dynamic-sized VHDs have a varying disk size, whereas fixed-size VHDs have a pre-allocated disk size, making them suitable for upload to Azure Blob Storage.
Requirements
- A VHD file for Apple Silicon Mac
- Azure Blob Storage account
Creating a Fixed Size VHD
Before uploading the VHD to the Azure Blob Storage, we need to create a fixed-size VHD using the hdiutil command in macOS.
Step 1: Convert VHD to raw format
hdiutil convert -format UDRW -o newVHD.raw /path/to/originalVHD.vhd
This command converts the VHD file to raw format, making it easier to create a fixed-size VHD.
Step 2: Create a fixed-size raw disk image
hdiutil create -size -fs -volname -srcfolder /path/to/folder newFixedSize.raw
Replace "size" with the desired fixed size, "filesystem" with the appropriate filesystem for your VHD, "volume name" with a name for the volume, and "folder" with the folder containing files you want to add to the fixed-size VHD. In this step, you will create a new fixed-size raw disk image.
Step 3: Copy the contents of the raw image to the new fixed-size raw disk image
dd if=newVHD.raw of=newFixedSize.raw bs=4m
This command copies the contents of the raw image to the new fixed-size raw disk image. Now, you have a fixed-size VHD.
Uploading the Fixed Size VHD to Azure Blob Storage
Once you have the fixed-size VHD, you can upload it to Azure Blob Storage using the Azure CLI.
Step 1: Install Azure CLI
Install the Azure CLI on your system following the instructions in the official documentation.
Step 2: Log in to your Azure account
az login
Step 3: Use the appropriate subscription
az account set --subscription ""
Step 4: Upload the fixed-size VHD
az storage blob upload --type block --account-name "" --account-key "" --container-name "" --type page --file "" --name ".vhd"
- Converted a VHD for Apple Silicon Mac to
rawformat using thehdiutilcommand. - Created a fixed-size
rawdisk image. - Copied the contents of the original
rawimage to the fixed-sizerawdisk image. - Uploaded the fixed-size VHD to Azure Blob Storage using the Azure CLI.