Use vhdupload to upload vhd files to cloud storage and add azure drive to Azure VM.

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.