北京30平米小户型楼盘:从VHD文件启动计算机 - 喻勇(Frank Yu)的技术博客 - Site Home -...

来源:百度文库 编辑:偶看新闻 时间:2024/04/30 15:57:31
TechNet Blogs > 喻勇(Frank Yu)的技术博客 > 从VHD文件启动计算机

从VHD文件启动计算机

Frank Yu 19 Jan 2009 1:00 AM
  • Comments 12

 

 

/*以下内容根据Aviraj Ajgekar的博客文章编译和修改。*/

之前的文章提到了Windows 7对VHD文件的内建支持,从此以后VHD文件的地位得到了提升:-) 它可以被操作系统认为是一块物理的硬盘进行管理和读写。

我们知道,现在启动系统的方式多种多样,可以从光盘、硬盘、软盘、U盘、网络等等不同的渠道来完成。既然VHD可以被Windows 7认为是一块独立的物理硬盘,那么我们是否可以从VHD启动操作系统呢?

 

答案是肯定的。Windows 7的引导程序也同样包含了对VHD文件的读写驱动,因此在装有Windows 7引导程序(Boot Loader)的计算机上,可以通过配置BCDEdit的方式,把VHD上的操作系统加入到启动时显示的多系统选择菜单。

 

下面我们来看一下具体的步骤:

注意,我们不能在物理计算机上通过光盘把系统安装到VHD文件。首先我们需要一个已经安装了操作系统的VHD文件,这可以通过几种方式来完成:

1. 在Virtual PC或者Hyper-V中完成安装,并且运行sysprep,然后关机,这是的VHD文件可以被Windows 7的Boot Loader启动。

2. 使用ImageX工具,把之前备份的操作系统镜像文件(ImageX格式)恢复到VHD中。

这两种方法的具体步骤,在Aviraj Ajgekar的博客中有详细的描述。

 

Adding the VHD Entry in Boot Menu and then Boot from VHD

当成功的创建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 below
C:\>bcdedit /set device vhd=[driveletter:]\\
C:\>bcdedit /set osdevice vhd=[driverletter:]\\

Note: vhd=[driveletter:]\\ 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 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.

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

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 device vhd=[driveletter:]\\
C:\>bcdedit /set osdevice vhd=[driverletter:]\\
C:\>bcdedit /set 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 /cleanup This deletes the specified operating system entry from the store and removes the entry from the display order.

Well, we are ready to Boot from VHD. Once you restart the computer you will see additional entry in Boot Menu along with the default Windows 7 or Windows Server 7 OS.

Here is the screenshot from newly booted Windows Server 2008 R2 Beta from VHD. I have installed Desktop Experience Pack and enabled Aero Glass.

看到这里,大家不免有一些问题:从VHD启动之后的系统,到底是运行在虚拟机上?还是直接运行在物理硬件之上?从VHD启动,还需要哪些必备的条件?是否会有性能的损失?下面我来回答这些问题:

 

1. Windows 7的引导程序和Windows 7本身都包含了对VHD文件的读写驱动程序,因此我们可以在启动计算机的时候,访问VHD并且从其上启动;我们也可以在Windows 7中直接创建、加载和卸载VHD文件。这些都是VHD读写驱动的功劳,跟Virtual PC或者Hyper-V没有直接的关系。因此Windows 7不需要安装任何虚拟化软件。

2. 从VHD启动之后,计算机的操作系统直接访问硬件,不是以虚拟化的方式运行。

3. 这里面唯一的区别,就是对文件系统读写访问的时候,需要经过额外的一层VHD读写驱动的解析,这里面有一些微量的I/O性能开销,但是跟虚拟化的情况相比,性能基本上接近了真机。我查了一些测试资料,有一组直接读取硬盘和读写VHD的比较,性能差别微乎其微。如下图:

4. 因为对VHD的支持仅包含在Windows 7中,因此我们不能在Windows 7中创建VHD后通过光盘给VHD安装任何操作系统。

 

这些仅仅是对这个功能的一些简单介绍和概括,相信大家在今后的应用中会有更多的体会和收获。

Windows 7, VHD Boot