VirtualBox 使用物理硬盘

/*******************************************************************************
 *                      VirtualBox 使用物理硬盘
 * 说明:
 *     之前一般都是将数据存储在虚拟硬盘中,每个虚拟机的资源使用感觉比较臃肿,
 * 不方便管理,所以打算除了基本编译系统以外,其他源代码存在共享的物理硬盘中,
 * 这样对数据统一管理方便一点。
 *
 *                                2018-12-17 深圳 宝安西乡 曾剑锋
 ******************************************************************************/

一、参考文档:
    1. Virtualbox直接运行物理分区的系统
        https://callmewing.com/2016/03/29/Virtualbox%E7%9B%B4%E6%8E%A5%E8%BF%90%E8%A1%8C%E7%89%A9%E7%90%86%E5%88%86%E5%8C%BA%E7%9A%84%E7%B3%BB%E7%BB%9F/
    2. 让VirtualBox使用物理硬盘作为虚拟硬盘镜像
        http://www.voidcn.com/article/p-zkqkeoid-bce.html

二、处理方法:
    1. 查看当前Windows物理硬盘信息,在Windows cmd中运行:wmic diskdrive list brief
        C:WINDOWSsystem32>wmic diskdrive list brief
        Caption           DeviceID            Model             Partitions  Size
        LITEON CV8-8E256  \.PHYSICALDRIVE0  LITEON CV8-8E256  6           256052966400
    2. 把Virtual Box的安装路径添加到PATH环境变量里面,为了能够使用VBoxManage创建物理硬盘映射出来的虚拟硬盘;
    3. 查看指定物理硬盘分区信息:
        C:WINDOWSsystem32>VBoxManage internalcommands listpartitions -rawdisk \.PhysicalDrive0
        Number  Type   StartCHS       EndCHS      Size (MiB)  Start (Sect)
        1       0x00  0   /0  /0   0   /0  /0            100         2048
        2       0x00  0   /0  /0   0   /0  /0             16       206848
        3       0x00  0   /0  /0   0   /0  /0          81920       239616
        4       0x00  0   /0  /0   0   /0  /0         150180    168011776
        5       0x00  0   /0  /0   0   /0  /0            512    475580416
        6       0x00  0   /0  /0   0   /0  /0          10445    476628992
        7       0x00  0   /0  /0   0   /0  /0           1024    498020352
    4. 创建物理硬盘映射出的虚拟硬盘: VBoxManage internalcommands createrawvmdk -filename "</path/to/your/virtual/disk/file>" -rawdisk "<DeviceID>"
        1. VBoxManage internalcommands createrawvmdk -filename "zengjf.vmdk" -rawdisk "\.PhysicalDrive0"
        2. zengjf.vmdk内容:
            # Disk DescriptorFile
            version=1
            CID=cf9fb569
            parentCID=ffffffff
            createType="fullDevice"

            # Extent description
            RW 500118192 FLAT "\.PhysicalDrive0" 0

            # The disk Data Base 
            #DDB

            ddb.virtualHWVersion = "4"
            ddb.adapterType="ide"
            ddb.geometry.cylinders="16383"
            ddb.geometry.heads="16"
            ddb.geometry.sectors="63"
            ddb.uuid.image="76610083-f7ca-458a-be76-abc5a064906f"
            ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
            ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
            ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
    5. 创建指定分区物理硬盘映射出的虚拟硬盘: VBoxManage internalcommands createrawvmdk -filename "</path/to/your/virtual/disk/file>" -rawdisk "<DeviceID>" -partitions 1,5,6,7
        1. VBoxManage internalcommands createrawvmdk -filename "zengjf.vmdk" -rawdisk "\.PhysicalDrive0" -partitions 1,2
        2. zengjf.vmdk内容:
            # Disk DescriptorFile
            version=1
            CID=738ed84b
            parentCID=ffffffff
            createType="partitionedDevice"
            
            # Extent description
            RW 63 FLAT "zengjf-pt.vmdk" 0
            RW 1985 ZERO 
            RW 204800 FLAT "\.PhysicalDrive0" 2048
            RW 32768 FLAT "\.PhysicalDrive0" 206848
            RW 167772160 ZERO 
            RW 307568640 ZERO 
            RW 1048576 ZERO 
            RW 21391360 ZERO 
            RW 2097152 ZERO 
            RW 655 ZERO 
            RW 33 FLAT "zengjf-pt.vmdk" 63
            
            # The disk Data Base 
            #DDB
            
            ddb.virtualHWVersion = "4"
            ddb.adapterType="ide"
            ddb.geometry.cylinders="16383"
            ddb.geometry.heads="16"
            ddb.geometry.sectors="63"
            ddb.uuid.image="2a0e378d-073c-48a3-9f82-4803dbb5d6b8"
            ddb.uuid.parent="00000000-0000-0000-0000-000000000000"
            ddb.uuid.modification="00000000-0000-0000-0000-000000000000"
            ddb.uuid.parentmodification="00000000-0000-0000-0000-000000000000"
        3. zengjf-pt.vmdk是二进制文件,这里不列出来;
    6. 将虚拟硬盘加入虚拟机系统就可以使用了。
原文地址:https://www.cnblogs.com/zengjfgit/p/10129928.html