1. Upload a vhd file to Azure blob Storage
The source code of the vhdupload program is compiled into vhdupload.exe in the labs \ exploringwindowsazurestoragevs2010 \ source \ assets \ vhdupload.exe directory of the Windows azure Training Kit directory. Then upload
Uploads a virtual hard disk (vhd) file to Windows azure page blob service.
Usage: vhdupload vhdfilepath bloburi accountname accountkey
Vhdfilepath-path to virtual hard disk (vhd) File
Bloburi-destination Page blob relative uri (I. e. Container/blobname)
Accountname-storage account name (use devstorage for storage emulator)
Accountkey-storage account primary key (omit for storage smulator)
The vhdupload upload process is as follows:
2. Self-write command line program Mount drive
The main code is as follows (modify it to the corresponding storage account and storage key and compile it into exe ):
class Program { const string sMainStorageName = "StorageAccountName"; const string sMainStorageKey = "StorageKey"; static void Main(string[] args) { string sVHDPathName = string.Empty; string sOperation = string.Empty; bool IfUnmount = false; if (args.Count() == 0) { Console.WriteLine("Syntax: MountAzureDrive ContainerName/Disk.VHD"); return; } try { sVHDPathName = args[0]; if (args.Length > 1) { sOperation = args[1]; if (args[1] == "/u") IfUnmount = true; } var cloudDriveBlobPath = string.Format("http://{0}.blob.core.windows.net/{1}", sMainStorageName, sVHDPathName); StorageCredentialsAccountAndKey credentials = new StorageCredentialsAccountAndKey(sMainStorageName, sMainStorageKey); // LocalResource localCache = RoleEnvironment.GetLocalResource(sMainLocalStorageName); // Char[] backSlash = { '\\' }; //String localCachePath = localCache.RootPath.TrimEnd(backSlash); //CloudDrive.InitializeCache(localCachePath, localCache.MaximumSizeInMegabytes); //string cachePath = @"C:\Resources\LocalStorage"; //for VM role //Console.WriteLine("Local Cache initialized.....{0}", cachePath); //try //{ // CloudDrive.InitializeCache(cachePath, 10); //} //catch (Exception e) //{ // Console.WriteLine(e.Message); //} if (IfUnmount) { Console.WriteLine("UnMount Drive " + cloudDriveBlobPath); CloudDrive mountDrive = new CloudDrive(new Uri(cloudDriveBlobPath), credentials); Console.WriteLine("Calling Cloud Drive UnMount API....", 0); mountDrive.Unmount(); Console.WriteLine("Finished Cloud Drive UnMount ."); } else { Console.WriteLine("Mount Drive " + cloudDriveBlobPath); CloudDrive mountDrive = new CloudDrive(new Uri(cloudDriveBlobPath), credentials); Console.WriteLine("Calling Cloud Drive Mount API....", 0); string driveLetter = mountDrive.Mount(0, DriveMountOptions.FixFileSystemErrors | DriveMountOptions.Force); Console.WriteLine("Finished Cloud Drive Mounting at Drive :" + driveLetter, 0); } } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
3. Execute the Mount action in the VM.
Use the preceding command line:
Is the effect after the mount. (Experiment passed in VM role)