In this post I will chow how to create and mount a virtual drive. Virtual drive is a file Virtual Hard Drive. That means you can use it as any other NTF drive within System.IO namespace. In some scenarios it can be very helpful to write data to virtual drive and then to do something with the VHD drive. For example, when working with Windows Azure you can mount to this drive, write to it (by using System.IO namespace) and finally download a copy of that file (disc) for analyzing purposes.
Interesting in this scenario is that the data in this drive is in fact Windows Azure blob storage data, which can also be accessed by standard blob storage API.
Create Disk and Attach
Save following script in some file like creatediskscript.txt. This will create the fixed disk of 50 MB, formatted as NTFS and mount it as drive V.
create vdisk file="c:\temp\mydrive.vhd" maximum=50 type=fixed
select vdisk file="c:\temp\mydrive.vhd"
attach vdisk
create partition primary
assign letter=v
format fs=ntfs label=vhd quick
exit
Open a command line console and execute the script:
diskpart /s c:\temp\discscript.txt
after executing of the script you will experience well known dialog, which is initiated by Virtual Disk Service:
After that you can use the disk as any other drive. Finally to disconnect do following:
Attach to Disk
Following script shows how to attach to an existing disk:
select vdisk file="c:\temp\mydrive.vhd"
attach vdisk
exit
Detach Disk
select vdisk file="c:\temp\mydrive.vhd"
detach vdisk
exit
Posted
Jul 26 2010, 01:38 AM
by
Damir Dobric