Hide partition with VHD file during specialize or OOBE pass

All we need is an easy explanation of the problem, so here it is.

I am creating a system based on VHD. The partition is like this:

| VHD file | User Data |

The system volume has a default drive letter C.
Windows 7 automatically assign letter D for “VHD file” volume and E for “User Data”
The “VHD file” volume also contains bootmgr and page file.

My purpose is to hide “VHD file” volume so that no page file will be located in it and user cannot see vhd file and boot directory in it.

Windows 7 doesn’t allow to remove letter after OOBE because the page file is in it. (Thus, we have to relocate page file, restart, and remove letter).

So my guess is do it during OOBE or specialize pass.

The result should be like “SYSTEM RESERVED” 100MB partition — no drive letter, no page file, but with key files in it.

Any ideas are welcome!

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Finally, I made it.

As the first pass is specialize, I let it change drive letters in registry by REG command. But remove a drive letter by registry is hard to code, and use of DISKPART requires a reboot, so I let it happen in oobe mode.

Here is what I code: (If you have some improvement please notify me 🙂

@echo OFF


if "%1"=="specialize" goto specialize
if "%1"=="oobe" (goto oobe) else (goto end)

set KEY_NAME="HKLM\SYSTEM\MountedDevices"

REM Delete Drive D:
set VALUE_NAME=\DosDevices\D:
reg delete %KEY_NAME% /v %VALUE_NAME% /f

REM Get vaules of Drive E:
set VALUE_NAME=\DosDevices\E:
FOR /F "usebackq skip=2 tokens=1-3" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
    set ValueName=%%A
    set ValueType=%%B
    set ValueValue=%%C
if not defined ValueName goto end

REM Create Drive D with value of Drive E
set VALUE_NAME=\DosDevices\D:
reg add %KEY_NAME% /v %VALUE_NAME% /t %ValueType% /d %ValueValue% /f
REM Delete Drive E:
set VALUE_NAME=\DosDevices\E:
reg delete %KEY_NAME% /v %VALUE_NAME% /f
REM Set Page File
set KEY_NAME="HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management"
set VALUE_NAME=PagingFiles
set ValueType=REG_MULTI_SZ
set ValueValue="D:\pagefile.sys 0 0"
reg add %KEY_NAME% /v %VALUE_NAME% /t %ValueType% /d %ValueValue% /f
goto end

REM Delete Drive E:
(echo select volume e & echo remove letter=e) | diskpart


Method 2

Use MDT 2012, this should be able to be done with a task sequence.

Sounds like you may be making this more complicated than it needs to be. MDT is the system Microsoft released back with Vista and Windows 7 to make Operating System Deployment (OSD) much simpler.

Hide partition with VHD file during specialize or OOBE pass
TEST Task Sequence

Hide partition with VHD file during specialize or OOBE pass
Deploy to VHD is an optional Task Sequence Step

Hide partition with VHD file during specialize or OOBE pass
Note that the image can be pushed to whatever drive you want.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply