anyThing is everyThing

收藏、学习、积累、创新

无需虚拟机 从VHD启动Windows 7

  今天我们来讲讲如何不用虚拟机,直接借助VHD原生启动Windows 7(win7)或者Windows Server 2008 R2。传统的做法是借助Virtual PC或者其他虚机,先挂载VHD文件,在里面安装好Windows,然后再把该VHD文件挂载到物理机器上。这样的做法比较复杂一些,那么能不能不要安装Windows,能否通过什么方法直接把Windows安装光盘里的WIM映像文件转换成VHD呢?答案当然是可以的。


  1. WAIK,该工具需要调用WAIK里的ImageX命令。当然,你也可以直接用下面附件中的ImageX:

  2. Wim2Vhd。


  3. 操作计算机,安装Windows 7。准备好Windows 7安装光盘,如果是ISO映像文件,则可以借助UltraISO等挂载工具将其挂载到虚拟光驱上。假设光驱盘符为H:


  1. 用管理员权限执行以下命令


  cscript wim2vhd.wsf /wim:h:\sources\install.wim


  该命令可以查出安装光盘里每个不同SKU映像的名称,我们可以看出Windows 7旗舰版,其SKU名称是ULTIMATE:


  2. 然后运行以下命令,把安装光盘里的旗舰版映像文件转换成一个VHD文件,并且保存到F盘下,名称为Win7Ult.vhd:


  cscript wim2vhd.wsf /wim:h:\sources\install.wim /sku:ultimate /vhd:f:\Win7Ult.vhd


  3. Wim2Vhd脚本会自动创建一个VHD文件,默认大小是40GB,然后系统任务栏的通知区域会弹出气泡,提示加载相应的VHD磁盘驱动,以便挂载这个VHD文件。


  4. 挂载好VHD文件,Wim2Vhd文件会自动调用ImageX命令把Wim映像里的Ultimate SKU释放到所挂载的VHD分区中。


  5. 默认情况下,Wim2Vhd并不会给VHD文件挂载的分区分配盘符,默认挂载到以下的NTFS目录:


  %Temp%\WIM2VHD.WSF\{guid}\mount


  6. 释放完以后,Wim2Vhd会自动执行bcdboot,以便该VHD能够引导,然后自动从所挂载的路径卸载。


  7. 现在已经制作好一个VHD文件,里面已经有安装好的Windows 7系统,按照常规手段在BCDEdit命令中添加一个启动项即可。


  8. 重启计算机,即可选择从VHD中引导,系统会自动进行配置。

 

BCDEdit添加启动项:

当成功的创建VHD文件并且在VHD系统之上部署了操作系统之后,我们需要使用Windows 7的BCDEdit工具来配置系统的多启动菜单:

C:\>bcdedit /copy {current} /d "My New VHD Description"

Note: This will Return the GUID of the Loader Object that you will use to replace <guid> below
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>

Note: vhd=[driveletter:]\<directory>\<vhd filename> is the new syntax supported for BCDEdit.exe to locate VHD File and Bootmgr will locate the partition containing the VHD File to boot from.
C:\>bcdedit /set <guid> detecthal on

Note:

Following is the attached screenshot of the my machine. In this case I have Windows 7 as the default OS and I have added the VHD File in the Boot Entry.

bcd

Well just after that run the following command to test if your boot entry is successfully created using C:\>bcdedit /v

image

Similarly, if you want to add multiple VHDs into Boot entry you can use the following lines to the command prompt

C:\>bcdedit /copy {current} /d "New VHD Description"
C:\>bcdedit /set <guid> device vhd=[driveletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> osdevice vhd=[driverletter:]\<directory>\<vhd filename>
C:\>bcdedit /set <guid> detecthal on

Note:  detecthal is used to force windows to auto detect the Hardware Abstraction Layer.

If you want to delete any existing VHD entry from the Boot Menu you can always use the command C:\>bcdedit /delete <guid> /cleanup This deletes the specified operating system entry from the store and removes the entry from the display order.

不允许评论