使用VHDUpload上傳VHD檔案到雲端儲存,並在Azure VM中加掛Azure Drive

來源:互聯網
上載者:User

1.上傳VHD檔案到Azure Blob Storage

VHDUpload程式的原始碼在Windows Azure Training Kit目錄Labs\ExploringWindowsAzureStorageVS2010\Source\Assets\VHDUpload,先編譯成VHDUpload.exe。然後上傳

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)

VHDUpload上傳過程如下所示:

2. 自寫命令列程式Mount Drive

主要代碼如下(請修改成相應的儲存體帳戶和儲存體金鑰,並編譯成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. 在虛擬機器裡執行Mount動作

使用上述命令列:

的E盤是Mount之後的效果。(VM Role裡實驗通過)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.