根据对PC BIOS 的了解,引导时首先要读入引导扇区。
我安装完毕Oracle Enterprise Linux x86_64 5.3以后,用 fdisk -l 看,可以看到:
[root@localhost ~]# fdisk -l
Disk /dev/sda: 12.8 GB, 12884901888 bytes
255 heads, 63 sectors/track, 1566 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1566 12474472+ 8e Linux LVM
可以看到分了两个区。
根据如下的说法,一个物理硬盘,最多可以分成四个区
(因为引导扇区512字节中。除了末尾两个字节为标志位,留下64个字节给分区表,一个分区表16个字节,一共可以容纳4个)
用如下命令读取其引导扇区的内容:
dd if=/dev/sda of=/root/bootsector bs=512 count=1
把读出来的二进制文件拿出来看,内容如下:
EB,48,90,10,8E,D0,BC,00,B0,B8,00,00,8E,D8,8E,C0, FB,BE,00,7C,BF,00,06,B9,00,02,F3,A4,EA,21,06,00, 00,BE,BE,07,38,04,75,0B,83,C6,10,81,FE,FE,07,75, F3,EB,16,B4,02,B0,01,BB,00,7C,B2,80,8A,74,03,02, 80,00,00,80,41,FC,02,00,00,08,FA,90,90,F6,C2,80, 75,02,B2,80,EA,59,7C,00,00,31,C0,8E,D8,8E,D0,BC, 00,20,FB,A0,40,7C,3C,FF,74,02,88,C2,52,BE,7F,7D, E8,34,01,F6,C2,80,74,54,B4,41,BB,AA,55,CD,13,5A, 52,72,49,81,FB,55,AA,75,43,A0,41,7C,84,C0,75,05, 83,E1,01,74,37,66,8B,4C,10,BE,05,7C,C6,44,FF,01, 66,8B,1E,44,7C,C7,04,10,00,C7,44,02,01,00,66,89, 5C,08,C7,44,06,00,70,66,31,C0,89,44,04,66,89,44, 0C,B4,42,CD,13,72,05,BB,00,70,EB,7D,B4,08,CD,13, 73,0A,F6,C2,80,0F,84,EA,00,E9,8D,00,BE,05,7C,C6, 44,FF,00,66,31,C0,88,F0,40,66,89,44,04,31,D2,88, CA,C1,E2,02,88,E8,88,F4,40,89,44,08,31,C0,88,D0, C0,E8,02,66,89,04,66,A1,44,7C,66,31,D2,66,F7,34, 88,54,0A,66,31,D2,66,F7,74,04,88,54,0B,89,44,0C, 3B,44,08,7D,3C,8A,54,0D,C0,E2,06,8A,4C,0A,FE,C1, 08,D1,8A,6C,0C,5A,8A,74,0B,BB,00,70,8E,C3,31,DB, B8,01,02,CD,13,72,2A,8C,C3,8E,06,48,7C,60,1E,B9, 00,01,8E,DB,31,F6,31,FF,FC,F3,A5,1F,61,FF,26,42, 7C,BE,85,7D,E8,40,00,EB,0E,BE,8A,7D,E8,38,00,EB, 06,BE,94,7D,E8,30,00,BE,99,7D,E8,2A,00,EB,FE,47, 52,55,42,20,00,47,65,6F,6D,00,48,61,72,64,20,44, 69,73,6B,00,52,65,61,64,00,20,45,72,72,6F,72,00, BB,01,00,B4,0E,CD,10,AC,3C,00,75,F4,C3,00,00,00, 00,00,00,00,00,00,00,00,43,D2,06,00,00,00,80,01, 01,00,83,FE,3F,0C,3F,00,00,00,8E,2F,03,00,00,00, 01,0D,8E,FE,FF,FF,CD,2F,03,00,D1,B0,7C,01,00,00, 00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00, 00,00,00,00,00,00,00,00,00,00,00,00,00,00,55,AA,
80,01, 01,00,83,FE,3F,0C,3F,00,00,00,8E,2F,03,00,
是第一个分区表,第一个字节80表示是活动分区。就是这里的 /dev/sda1
00,00, 01,0D,8E,FE,FF,FF,CD,2F,03,00,D1,B0,7C,01,
是第二个分区,第一个字节 00表示是 非活动分区。就是这里的 /dev/sda2
参考:
http://www.docin.com/p-394748574.html
而 第 5 个字节,表达的是 分区类型:83 为Linux 分区,8e 为 Linux LVM 分区
如果我们把两个分区表的 第一个字节的80 和 00 互换改为:,
00,01,
01,00,83,FE,3F,0C,3F,00,00,00,8E,2F,03,00,80,00,
01,0D,8E,FE,FF,FF,CD,2F,03,00,D1,B0,7C,01,
然后把修改后的 bootsector 文件写回到引导扇区,
dd if=/bootector of=/dev/sda bs=512 count=1
再看fdisk -l ,会看到:
/dev/sda1 1 13 104391 83 Linux
/dev/sda2 * 14 1566 12474472+ 8e Linux LVM
可以看到 × 的位置发生了变化,* 就表示那个分区是活动的(就是有效的可引导分区)。
为了安全起见,应当再把 bootsector 的内容中 第一个字节的80 和 00 互换回来。
80,01,
01,00,83,FE,3F,0C,3F,00,00,00,8E,2F,03,00,00,00,
01,0D,8E,FE,FF,FF,CD,2F,03,00,D1,B0,7C,01,
dd if=/bootector of=/dev/sda bs=512 count=1
本文转自健哥的数据花园博客园博客,原文链接:http://www.cnblogs.com/gaojian/archive/2012/10/19/2730878.html,如需转载请自行联系原作者