Windows Loopback Alternative: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
m (addcat)
No edit summary
 
Line 10: Line 10:
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.
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.
<br/>
<br/>
[[File:Windows-Computer-Management.png]]
http://i40.tinypic.com/favcj8.png


Then go to Storage - Disk Management.
<br/>
<br/>
Then go to Storage - Disk Management. Right click Disk Management and select Create VHD. It will guide you through the creation of a VHD file.
http://i43.tinypic.com/2ywzk8h.png
<br/>

[[File:Windows-Create-VHD.png]]
Right clicking Disk Management and selecting Create VHD will guide you through the creation of a VHD file.


== Attaching a VHD ==
== Attaching a VHD ==

Latest revision as of 19:05, 10 July 2023

Difficulty level

Beginner

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.


Then go to Storage - Disk Management. Right click Disk Management and select Create VHD. It 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