【问题标题】:VHD not booting in hyper VVHD 无法在 hyper V 中启动
【发布时间】:2013-02-23 17:26:13
【问题描述】:

我正在为具有多个分区的磁盘创建动态 vhd。

涉及的步骤是

  1. 首先我通过创建页眉和页脚并计算 bat(块分配表)大小来创建 VHD。

  2. 然后我使用 win32 API 获取磁盘大小和分区详细信息

  3. 我拍摄卷的快照

  4. 我读取父磁盘的 mbr 并覆盖扇区偏移量,然后将具有多个分区的 mbr 写入 VHD。

  5. 现在对于每个卷影副本,我读取快照并写入 VHD 文件

  6. 此过程成功完成,然后我在 diskmgmt.msc 中打开 vhd。它显示了两个分区,我可以看到这些分区中的数据。

  7. 现在我将此 vhd 复制到 hyper V 机器,然后创建一个新 vm 并将此 vhd 添加到该机器。

  8. 当它启动时,它给我一个错误“磁盘读取错误”,但是当我将此 vhd 添加到现有操作系统并在引导加载程序中添加引导条目时,它可以正常引导。

不知道怎么回事,有谁过来指点一下。

这里是写mbr的代码

/* Stream out the first data block which contains only the MBR */

   BYTE zerosector[512] = {0};

  zerosector[0] = 0x80;

  assert(0 != WriteFile(hFile, zerosector, 512, &nWritten, NULL));  /* here goes the  first block's block bitmap */

  zerosector[0] = 0x00;


 unint16 mcount = 0;
 unint64 indexOffset = 0;

 memcpy(&mbr,mbrbuff,512);
 for(vector<PartOffset*>::iterator pTemp = pPart.begin();pTemp!=pPart.end();pTemp++)
 {

   mbr.partition[mcount].type          = 0x07;
   mbr.partition[mcount].start_sector  = 4096 + indexOffset ;
   mbr.signature                       = 0xAA55;
   mbr.partition[mcount].total_sectors =  (((*pTemp)->total_sectors)) + 1 ; 
   indexOffset +=  ((((*pTemp)->total_sectors))) + 1;
   //if(mcount==0)
     //  indexOffset +=  ((((*pTemp)->start_sector)/512) );
   mcount++;

 }

谢谢

【问题讨论】:

  • 我已经发布了编写 mbr 的代码
  • 你在哪里把你的mbr 变量写到磁盘上?
  • 对于 vhd 偏移量是 1536 字节 + sizeof(块分配表)以字节为单位 + 512 字节对于位图,在这个偏移量我将 mbr 写入 vhd 文件

标签: c++ windows virtualization vhd mbr


【解决方案1】:

DiscUtils 提供访问和写入与 Hyper-V 兼容的 .VHD 文件的参考

看看它是如何构建以DiskFactory 开头的 VHD

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    • 2016-08-12
    • 1970-01-01
    • 2020-05-28
    • 1970-01-01
    • 2019-03-28
    相关资源
    最近更新 更多