Hide partition with VHD file during specialize or OOBE pass

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

+----------+-----------+
| VHD file | User Data |
+----------+-----------+
  |
+------------+
| SYSTEM |
+------------+

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!


Solution 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

setlocal ENABLEEXTENSIONS

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


:specialize
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
REM END
goto end

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

:end