/******************************************************************************* * VirtualBox 使用物理硬盤 * 說明: * 以前通常都是將數據存儲在虛擬硬盤中,每一個虛擬機的資源使用感受比較臃腫, * 不方便管理,因此打算除了基本編譯系統之外,其餘源代碼存在共享的物理硬盤中, * 這樣對數據統一管理方便一點。 * * 2018-12-17 深圳 寶安西鄉 曾劍鋒 ******************************************************************************/ 1、參考文檔: 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 2、處理方法: 1. 查看當前Windows物理硬盤信息,在Windows cmd中運行:wmic diskdrive list brief C:\WINDOWS\system32>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:\WINDOWS\system32>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. 將虛擬硬盤加入虛擬機系統就能夠使用了。