【发布时间】:2012-03-13 06:25:01
【问题描述】:
我有这个代码,它是项目源代码的一部分。 此代码查找 MBR 类型:GRUB 或 LILO,并相应地设置一个标志。
令人惊讶的是,在 SLES 10-SP1 (SUSE Linux Enterprise Server) 中,它无法确定。
/dev/sda1 是我的交换。
/dev/sda2 是整个 / 所在的位置,包括 MBR。
相同的代码适用于 SLES11 和其他。
这里MBR_SIZE 是#defined 到0x1be。
int lnxfsGetBootType(int pNumber)
{
int i, retval = -1, ccode;
PartInfo *p = &cpuParts[pNumber];
char buffer[SECTOR_SIZE];
var64 offset = 0;
isdLogFileOut(ZISD_LOG_DEVELOPER,"[lnxGBT]\n");
if (getenv("ZENDEVICE") || gUtilPart == 1) {
offset = p->pOffset; // look at the partition BPB
}
//Now try to find the installed boot loader...
lseek64(p->handle, (var64)offset, SEEK_SET); // either MBR or BPB
ccode = read(p->handle, buffer, SECTOR_SIZE);
for (i=0; i<MBR_SIZE-4;i++) {
if (strncmp(&buffer[i], "LILO", 4) == 0) {
if (offset == 0){
retval = FLAG_LNXFS_LILO;
isdLogFileOut(ZISD_LOG_WARNING,"\tLILO MBR found on %s\n",p->header.deviceName);
} else {
retval = FLAG_LNXFS_LILO; // 10.31.06 _BPB;
isdLogFileOut(ZISD_LOG_WARNING,"\tLILO BPB found on %s\n",p->header.deviceName);
}
}
if (strncmp(&buffer[i], "GRUB", 4) == 0) {
if (offset == 0){
retval = FLAG_LNXFS_GRUB;
isdLogFileOut(ZISD_LOG_WARNING,"\tGRUB MBR found on %s\n",p->header.deviceName);
} else {
retval = FLAG_LNXFS_GRUB; // 10.31.06 _BPB;
isdLogFileOut(ZISD_LOG_WARNING,"\tGRUB BPB found on %s\n",p->header.deviceName);
}
}
}
if (retval == -1) {
isdLogFileOut(ZISD_LOG_WARNING,"\tLILO or GRUB mbr/bpb not found on %s\n",p->header.deviceName);
}
return retval;
} // lnxfsGetBootType
Here partinfo, is a struct of partition type:
//Data structure used internally by the image engine to store information about the
//partitions. It encapsulates the PartHeader struct, whcih is used to store partition
//information in image archives
typedef struct _PartInfo
{
PartHeader header;
int handle; //file handle for reading/writing physical device
var32 flags; //Various flags as needed. Defined above.
var64 pOffset; //offset to partition from start of physical device
int deviceNumber; //index into 'devices' where this partition's
// physical device is located
int archIndex; //for restoring only. Index into imgParts of the
// archive partition this physical partition is
// mapped to
int bytesWritten; //track number of sectors written so the device-level
// cache can be flushed
void *info; //partition-type-specific info struct
/* snip */
测试是在 VMWare 下使用不同的虚拟磁盘映像进行的。我已经确认磁盘是用 MBR 而非 GPT 格式化的。
【问题讨论】:
-
@sarnold:不,它正在使用 VMware 和单独的虚拟磁盘进行测试。
-
@sarnold:不,我们没有使用 GPT,它是 MBR。刚刚得到团队确认。
-
@sarnold: vmware4 磁盘映像 :)
-
我将我们对话的结果移到了问题中,并删除了我的 cmets 以使其看起来简单。祝你好运。 :)
-
MBR 不应该位于
/dev/sda的开头(在您的设置中)吗?