TechTipsApp

Technology tips blog

  • Articles
    Categories
    • Tech news
    • Internet
    • Social Network
    • Google
    • Geeky Tips
    • Android
    • Windows 10
    Top Posts
    • Install Windows XP from USB
    • Install Windows 7 from USB
    • Open Facebook When It's Blocked
    • Partition Hard Drive Without Formatting
    • Reset Windows 7 Password
    • About
    • Contact
    • Privacy policy
    • Advertise
    • Terms of Conduct & Copyright Policy

How to Create and Permanently Attach a Virtual Hard Disk in Windows 7

Tanmay Windows 7 33 Comments

Virtual Hard Disk (VHD) is a file, created in Windows 7, that behaves as a separate usual hard disk drive of the computer. You can keep your favorite files and folders, apply disk encryption etc. Even, you can boot from that virtual disk drive by configuring the boot manager. This tutorial shows how to create a virtual disk drive in Windows 7, attach an existing VHD and lastly, the procedure of making the attachment permanent in step by step.

Create Virtual Hard Disk (VHD)

You can create a virtual hard disk from Computer Management wizard.
Right-click on My Computer and select “Manage”.

or, type compmgmt.msc at the Windows 7 start menu search box and hit Enter. The Computer Management wizard will appear. Now follow the steps below.
Right-click on “Disk Management” under “Storage” and click on “Create VHD”.

In the next wizard select the location and the VHD file name by clicking on “Browse”, put the size of the virtual hard disk in MB and click on OK.

This will create the Virtual Hard Disk with the level Disk 1.

Now right-click on Disk 1 and select initialize then click “Next”.

After initializing the disk, you have to allocate the disk space. So right-click on the unallocated space and select “New Simple Volume”.

In “New Simple Volume” wizard put the volume size and click on “Next”.

Assign a drive letter for the drive by choosing from the drop down list of available letters. Click on “Next”.

Before formatting the volume, choose the file system, give a volume level and click on “Next” then “Finish”.

You are done! You cannotice that your new virtual hard disk has been listed with the other disk drives.

Attach an existing Virtual Hard Disk

Right click on My Computer icon then select “Manage” to open Computer Management wizard. Now under the “Storage” entry, right-click on “Disk management”. Select “Attach VHD” and locate the existing vhd file and click on OK. That’s all.
So after creating a new Virtual Hard drive or attaching an existing one, you can access it from the Windows 7 explorer window.

But the problem is that every time you restart your computer, you lost the virtual drive and you’ll have to reattach the VHD again. There is a simple tricks by which you can make the virtual drive permanent and you won’t have to reattach that after every time you start your computer.
Related: Create Virtual Drive for any folder.

Permanently attach Virtual Hard Disk in Windows 7

To make the virtual hard disk permanent, create a batch file to attach the VHD and run that at start up by creating a registry entry. Here is the complete procedure.
Creating the batch file
Copy the following code and paste in a notepad document.

@echo off
SET TEMPFILE="%TEMP%%RANDOM%.TXT"
echo SELECT VDISK FILE=Your vhd file name with location >%TEMPFILE%
echo ATTACH VDISK>>%TEMPFILE%
DISKPART /s %TEMPFILE%
del %TEMPFILE%

Replace the high lighted part with the vhd file name along with location. As for example  E:myvirtualdrive.vhd
Now save the file as some_name.bat. Also change the “Save as type” to “All files” before saving. After creating the batch file copy the file (some_name.bat) and paste at C: > Windows > System 32 folder. When pasting the file there you will get a security message. Just click on “Continue”.
Creating the registry entry
Press Win key + R and type “regedit” and hit Enter to open the registry editor. Now navigate to the following path from the left pane of the editor:

HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Windows > CurrentVersion > Run

Now create a new string value under “Run”. Right-click on the empty space of the right pane and select New > String Value.

Give a name of the value. Here it is VHD. Now right click on the value VHD and select “Modify”.

At the Value data field put “c:windowssystem32some_name.bat” and click OK.

Restart your computer. You cannotice the virtual drive that you created or attached has been permanently occupied in the explorer or any other places.

Post Tags: Drive, Hard Drive, Virtual
Similar Articles from This Blog
Partitioning Hard Drive in Windows 7 Without Formatting
How to Hide Disk Drives {Partitions} in Windows Computer
How to Hide Disk Drives {Partitions} in Windows Computer
Partition Hard Drive in Windows 7 Starter Without Formatting
Partition Hard Drive in Windows 7 Starter Without Formatting
How to Track USB Drive Activity in Your Computer
How to Track USB Drive Activity in Your Computer
Recover Missing Or Unallocated Space on USB Drive Using Windows Diskpart Commands
Recover Missing Or Unallocated Space on USB Drive Using Windows Diskpart Commands
How To Recover Data From Crashed Operating System
How To Recover Data From Crashed Operating System

Comments

  1. anj :

    I tried this just now – It doesn’t seem to be working for me. I’ll try it again, but when I restarted my computer the drive didn’t even exist.

    Reply
  2. anj :

    Tried it a second time. Still no luck, when the computer restarts, there’s no virtual drive listed in my computer. :/
    The only thing that comes up as different is that when I click atach to the virtual disk, it tells me that it’salready attatched. – could this have something to do with my problem?

    Reply
  3. Tanmay :

    Anj: The procedure works fine. I tested that several times. Confirm that you are creating the registry key at the exact location where i said. One more thing when you copy the batch script then please retype the ” signs from your keypad.The problem may be with the rich font.

    Reply
  4. Robert :

    I created a VHD on a network drive and was able to do a backup to it. So it worked! However, when I try to reattach to the drive later after rebooting, I get the error message: “This version does not support this version of the file format”. Any ideas?

    Reply
  5. Tanmay :

    Are you trying with NTFS format?

    Reply
  6. Robert :

    Yes, I used NTFS.

    Reply
  7. T :

    diskpart -s doesn’t seem to work for me. The command prompt just flashed and closed. But it worked if I did line by line inside diskpart command prompt.
    What am I missing?

    Reply
  8. Tanmay :

    Put the following code:
    @echo off
    SET TEMPFILE=”%TEMP%%RANDOM%.TXT”
    echo SELECT VDISK FILE= put your VHD file name with its location >%TEMPFILE%
    echo ATTACH VDISK>>%TEMPFILE%
    DISKPART /s %TEMPFILE%
    del %TEMPFILE%
    Remember that if copy this code then paste, you should re-type the ” (quotes) from your keyboard.
    Let me know if this solved your problem.

    Reply
  9. wade :

    you have to put the path in “”
    e.g.
    @echo off
    SET TEMPFILE=”%TEMP%%RANDOM%.TXT”
    echo SELECT VDISK FILE= “C:virtuadriveyouspecify.vhd” >%TEMPFILE%
    echo ATTACH VDISK>>%TEMPFILE%
    DISKPART /s %TEMPFILE%
    del %TEMPFILE%

    Reply
    • Lubo :

      true but you also have to include the backslash:
      “C:virtuadriveyouspecify.vhd”

      Reply
  10. sid :

    what a waste of time, it doesnt work, u have to reattach it every time 😐

    Reply
  11. K. :

    It probably needs to have the correct permissions to work, which are not accounted for in this process.
    A much more elegant solution that doesn’t require manipulating the registry is here: http://coding.infoconex.com/post/2009/11/26/Automatically-attaching-VHD-files-in-Windows-7-and-Windows-2008.aspx
    Just be sure to read all the comments as well and adjust the Administrator settings accordingly.

    Reply
  12. Satyajit :

    what would be code to display two virtual drives???

    Reply
  13. Mike :

    Yea I did all that, changed the ” and still nothing everytime I restart. Getting annoying. Followed it step by step.
    Working with windows 7. I restart it and comes up with CMD saying do I want to make those changes, click yes and nothing.?????

    Reply
  14. bill :

    Has anyone confirmed that their batch file actually works before using it in a reboot scenario? Detach the VHD and run the batch. If that works, then figure out 1. Why the batch is not executing at boot time and/or 2. Why it does not attach the vdisk..
    Also, all versions of Windows may not be supported. I know that you cannot _boot_ to a Windows 7 Home edition vdisk. Perhaps there are restrictions on mounting at boot time as well…

    Reply
  15. david :

    Is there a way to undo this?

    Reply
  16. Eric :

    I created the script and tested it on Win7-Pro and it works. The VHD is attached and usable. I then made the regedit change and rebooted. It brought up Notepad with the script in it. I tired changing the default assignment of .bat files from Notepad to CMD.exe and made things worse. Now it brings up a Command window which just sits there. I can drag a copy of my .bat file into the window and execute it, but that is way clumsy. I tired reversing the default assignment of .bat files back to Notepad, but that doesn’t take. It is now permanently glued to CMD.exe. A
    Any idea how to undo that assignment and what the assignment should be?

    Reply
  17. Richard :

    ahhaha thanks..
    works for me..
    no need to reattached after restarting..
    yea!!!

    Reply
  18. alihasana :

    Dear All,
    Its attach, but each and every restart its reloading, again i need give permission
    Is there any solution for this problem
    Thanks in advance, i hope i may get good response from your end

    Reply
  19. JP :

    This worked perfectly! Is there a way to make the VHD available while booting the OS to make the choice of other OS installed in the VHD?

    Reply
    • Jo :

      I created the vhd on my windows 7 system. tested the batch file and it work perfectly when I started 7. I loaded windows 10 on the virtual drive. I restarted my laptop and chose start windows 10 in the boot manager I received this error:VHD_BOOT_INITIALIZATION_FAILED.Do I need to put the batch file in another location or make another entry in the registry?

      Reply
  20. ralleyrale :

    am I lost something? I don’t understand the 3rd picture. where is the ” vhd_sample.vhd ” come from? does it download from website? please help me….

    Reply
  21. Shaunnis :

    Permanently attach Virtual Hard Disk in Windows 7…
    WORKS GREAT on Server 2008 R2 Standard
    Thanks!!!!

    Reply
  22. Kendall :

    Tool to do this for you for free. http://bmvhdloader.com. Made this tool for this reason. Free for everyone. Pass it around.

    Reply
    • hehehehe :

      Thanks Kendall
      Successfully attached 1TB VHD

      Reply
      • Mohammad :

        1TB! I tried to make a 12gb vhd and it kept saying there is not enough space on disk but I have 300gb free.

        Reply
  23. Confused :

    It’s confusing that it says ‘put “c:windowssystem32some_name.bat” ‘ but in the image you’ve typed it with s. Are we meant to put the s in or not?

    Reply
  24. anotherone :

    Simple VHD Manager is portable freeware which helps VHD users simplify some of these operations:
    – You can easily create VHD/VHDX files
    – You can attach and detach VHD/VHDX/ISO files via drag and drop
    – You can permanently attach a virtual hard disk in Windows 10 , Windows 8,1 , Windos 8, Windows 7
    – You can easily add and/or remove VHD/VHDX/ISO files to the boot menu

    Reply
  25. A Jonathan Valdes :

    I tested edit the registry and this not work for me, so I opted for create a service than launched the disk on every reboot this was the best option and works perfectly.
    Remember.
    – First test your bat works manually
    – Create the services with NSSM
    – Enjoy
    Believe me I try make the registry work for serveral hours without success!

    Reply
  26. sabdip :

    i had create one virtual drive but some registry change then it cannot display to me how can retrieve that virtual drive because i had store some data on that drive

    Reply
  27. PJX :

    Worked for me, although i’d initially forgotten to put the files extension of the VHD, once i added that it worked no issues

    Reply
  28. dbithead :

    Why do you label your auto attach section as “Permanently attach Virtual Hard Disk in Windows 7”? This is not accurate as the disk number the VHD is attached as changes depending on what other drives you have configured.
    EG if you have a usb stick inserted one day when you boot, the VHD gets one disk number but if the USB stick is missing next time you boot the disk number will be different from the last boot.

    Reply
  29. jpo :

    it works if you use the \ in the paths, which he leaves out.
    in the script he gives example of E:myvirtualdrive but is should be E:\myvirtualdrive

    Reply

Leave a Comment Cancel reply

Your email address will not be published. Required fields are marked *

About Us

Tech Tips App is a technology blog, looking forward to broaden the mental horizons of technical geeks round the web. Striving hard to quench your technical thirst, we have put our best efforts on the line of exhaust to satisfy your versatile technical vocabulary.

Recently Published

  1. Partitioning Hard Drive in Windows 7 Without Formatting
  2. How to Find My Contacts on Google Map
  3. Introducing SMS Organizer by Microsoft is the Best SMS App
  4. How to Fix Windows Update When It Gets Stuck
  5. How to Get Rid of Windows 10 Automatic Repair Loop [Solved]
  6. Best Antivirus for Windows 10 (Is Windows Defender Good Enough?)
  7. Best Facebook Messenger Bots to Get more out of Messenger
  8. How to Fax a Document From Your Smartphone
  9. Top Social Media Platforms You Should Always Know About
  10. Bitcoin vs Altcoin: Where to Invest? – Guide For Dummies

© 2021 Tech Tips App All Rights Reserved  Post Sitemap