Windows Loopback Alternative

From OSDev Wiki
Jump to: navigation, search

It is a well known fact that Windows doesn't support loopback devices but there is an alternative available for Windows 7 users. Windows 7 has a support for so called Virtual Hard Disks which are just plain bin files with data. Windows 7 also includes the interface for creation and management of those VHD files.


Creating a VHD

To create a VHD you must first open the Computer Management window, which is most easily accessed by right clicking My Computer and selecting Manage.
favcj8.png

Then go to Storage - Disk Management.
2ywzk8h.png

Right clicking Disk Management and selecting Create VHD will guide you through the creation of a VHD file.

Attaching a VHD

By right clicking Disk Management, and selecting Attach VHD, you can attach any VHD ( Possibly any binary file) and mount it to a specific drive.

Use

You can setup your IDE ( I have used Visual Studio) to automatically detach a VHD after compilation and run the OS in a emulator, such as QEMU. Here is how you can achieve such behavior.

Windows contains a command line program called diskpart which is used for mounting of the VHDs, but you need to supply a script for it in order to work.
c:\os\harddrive.vhd shows the location of the VHD file used.

Script for attaching (Saved as VHDScriptAttach.txt) :

select vdisk file=c:\os\harddrive.vhd
attach vdisk

Script for detaching (Saved as VHDScriptDetach.txt) :

select vdisk file=c:\os\harddrive.vhd
detach vdisk

After that you need to setup your IDE/Compiler to run this batch script after compilation/on debug.

diskpart -s VHDScriptDetach.txt
qemu.exe -hda C:\OS\Harddrive.vhd
diskpart -s VHDScriptAttach.txt
Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox