̽ÌÖLinux MBRµÄ×÷ÓÃ
Linux MBR£¨Master Boot Record£¬Ö÷Ö¸µ¼¼Í¼£©ÊÇ´æ´¢ÔÚÓ²ÅÌÉϵÚÒ»¸öÉÈÇøµÄÌØÊâÖ¸µ¼¼Í¼£¬ÓÃÓÚÆô¶¯ÅÌËã»ú²¢¼ÓÔزÙ×÷ϵͳ¡£ÏàʶLinux MBRµÄ¹¦Ð§¹ØÓÚÉîÈëÃ÷È·ÅÌËã»úÖ¸µ¼Àú³ÌºÍ²Ù×÷ϵͳ¼ÓÔØÀú³ÌºÜÊÇÖ÷Òª¡£±¾ÎĽ«ÏÈÈÝLinux MBRµÄ¹¦Ð§£¬²¢ÌṩÏêϸµÄ´úÂëʾÀýÀ´×ÊÖú¶ÁÕ߸üºÃµØÃ÷È·¡£
1. Linux MBRµÄ¸ÅÊö
Linux MBR°üÀ¨Á½²¿·ÖÐÅÏ¢£ºÖ÷Ö¸µ¼´úÂëºÍ·ÖÇø±í¡£Ö÷Ö¸µ¼´úÂëÊÇÒ»¸öСµÄ³ÌÐò£¬ÈÏÕæÆô¶¯Ö¸µ¼Àú³Ì£¬²¢½«¿ØÖÆȨת½»¸ø²Ù×÷ϵͳµÄÖ¸µ¼³ÌÐò¡£·ÖÇø±í¼Í¼ÁËÓ²ÅÌ·ÖÇøµÄÐÅÏ¢£¬°üÀ¨Ã¿¸ö·ÖÇøµÄÆðʼλÖᢾÞϸºÍ·ÖÇøÀàÐ͵ȡ£
2. Linux MBRµÄ¹¦Ð§
1. Æô¶¯ÅÌËã»ú
µ±ÅÌËã»ú¿ª»úʱ£¬BIOS»áÊ×ÏȼÓÔØÓ²ÅÌÉϵĵÚÒ»¸öÉÈÇø£¨¼´Linux MBR£©£¬²¢Ö´ÐÐÆäÖеÄÖ¸µ¼´úÂë¡£Ö¸µ¼´úÂë»á³õʼ»¯ÏµÍ³ÇéÐβ¢¼ÓÔزÙ×÷ϵͳµÄÖ¸µ¼³ÌÐò¡£
2. ¼ÓÔزÙ×÷ϵͳ
Linux MBR»á¶ÁÈ¡·ÖÇø±íÐÅÏ¢£¬²¢Æ¾Ö¤ÆäÖмͼµÄ·ÖÇøÐÅÏ¢ÕÒµ½²Ù×÷ϵͳËùÔڵķÖÇø£¬²¢½«¿ØÖÆȨ½»¸ø¸Ã·ÖÇøÖеÄÖ¸µ¼³ÌÐò£¨ÈçGRUB»òLILO£©¡£Ö¸µ¼³ÌÐò»á¼ÌÐø¼ÓÔزÙ×÷ϵͳµÄÄں˺ÍÎļþϵͳ£¬×îÖÕÍê³ÉϵͳµÄÆô¶¯Àú³Ì¡£
3. Ïêϸ´úÂëʾÀý
ÏÂÃæÊÇÒ»¸ö¼òÆÓµÄʾÀý´úÂ룬ÑÝʾÔõÑù¶ÁÈ¡Linux MBRÖеķÖÇø±íÐÅÏ¢£º
#include <stdio.h> #include <unistd.h> #include <fcntl.h> #define SECTOR_SIZE 512 #define PARTITION_TABLE_OFFSET 446 #define PARTITION_TABLE_ENTRY_SIZE 16 int main() { int fd = open("/dev/sda", O_RDONLY); if (fd == -1) { perror("open"); return 1; } unsigned char mbr[SECTOR_SIZE]; if (read(fd, mbr, SECTOR_SIZE) != SECTOR_SIZE) { perror("read"); close(fd); return 1; } unsigned char* partitionTable = mbr + PARTITION_TABLE_OFFSET; for (int i = 0; i < 4; i++) { printf("Partition %d: ", i+1); printf("Status: %02x ", partitionTable[i*PARTITION_TABLE_ENTRY_SIZE]); // Êä³ö¸ü¶à·ÖÇøÐÅÏ¢£¬ÈçÆðʼλÖᢷÖÇøÀàÐÍµÈ } close(fd); return 0; }
µÇ¼ºó¸´ÖÆ
ÉÏÊö´úÂëͨ¹ý·¿ªÓ²ÅÌ×°±¸Îļþ/dev/sda£¬¶ÁÈ¡Ó²Å̵ĵÚÒ»¸öÉÈÇø£¨¼´Linux MBR£©£¬²¢ÆÊÎöÆäÖеķÖÇø±íÐÅÏ¢¡£¶ÁÕß¿ÉÒÔƾ֤×Ô¼ºµÄÐèÇóÀ©Õ¹´úÂ룬Êä³ö¸ü¶à·ÖÇøÐÅÏ¢¡£
½áÓï
ͨ¹ýÉîÈëÏàʶLinux MBRµÄ¹¦Ð§£¬²¢ÍŽáÏêϸµÄ´úÂëʾÀý£¬¶ÁÕß¿ÉÒÔ¸üºÃµØÃ÷È·ÅÌËã»úÖ¸µ¼Àú³ÌºÍ²Ù×÷ϵͳ¼ÓÔØÀú³Ì¡£Ï£Íû±¾ÎÄÄÜ×ÊÖú¶ÁÕß¼ÓÉî¶ÔLinux MBRµÄÃ÷È·£¬²¢¶ÔÅÌËã»úϵͳÓиüÉîÈëµÄÊìϤ¡£
ÒÔÉϾÍÊÇ̽ÌÖLinux MBRµÄ×÷ÓõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡