MBR备份与还原及多重系统引导制作

来源:互联网 发布:虚拟号码软件 app 编辑:程序博客网 时间:2024/05/18 18:41
MBR,全称为Master Boot Record,即硬盘主引导记录。硬盘的0柱面、0磁头、1扇区称为主引导扇区(也叫主引导记录MBR)。它由三个部分组成,主引导程序(boot loader,占446个字节,为第1-446字节)、硬盘分区表DPT(Disk Partition table,占64个字节,为第467-510字节)和硬盘有效标志(magic number,占2个字节,为511-512字节,固定为55AA)。这512字节包含了硬盘最重要的信息:分区表,包括分区的开始扇区,结束扇区,引导标志,分区类型等等,每个分区信息用16个字节表示,四个分区就用掉了16X4=64个字接,后面紧接着两个字节AA和55被称为幻数(Magic Number)。

在Linux的shell命令行中
1、使用fdisk -l 确定MBR位置。

[root@localhost ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000be666
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        2611    20458496   8e  Linux LVM
Disk /dev/mapper/VolGroup-lv_root: 18.8 GB, 18832424960 bytes
255 heads, 63 sectors/track, 2289 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
Disk /dev/mapper/VolGroup-lv_swap: 2113 MB, 2113929216 bytes
255 heads, 63 sectors/track, 257 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

2、备份MBR:
dd if=/dev/sda1 of=/root/mbr bs=512 count=1

3、恢复MBR:
dd if=/root/mbr of=/dev/sda1 bs=512 count=1

注:mbr大小512 所以bs=512 count=1


系统开机的经过可以汇整成底下的流程的:
1. 加载 BIOS 的硬件信息不迚行自我测试,幵依据讴定取得第一个可开机的装置;
2. 读取幵执行第一个开机装置内 MBR 的 boot Loader (亦即是 grub, spfdisk 等程序);
3. 依据 boot loader 的讴定加载 Kernel ,Kernel 会开始侦测硬件不加载驱劢程序;
4. 在硬件驱劢成功后,Kernel 会主劢呼叨 init 程序,而 init 会取得 run-level 信息;
5. init 执行 /etc/rc.d/rc.sysinit 档案来准备软件执行的作业环境 (如网络、时区等);
6. init 执行 run-level 的各个朋务乊吪劢 (script 方弅);
7. init 执行 /etc/rc.d/rc.local 档案;
8. init 执行终端机仺真程序 mingetty 来吪劢 login 程序,最后就等待用户登入啦;

系统引导过程为:BIOS硬盘读取检测和自检、最后读取MBR->读取MBR中引导管理程序,转到到DPT中读取主活动区->读取主活动区的boot sector内容,是加载kernel还是移交控制权给其他引导程序。


将Grub4Dos文件夹中grldr、grldr.mbr和menu.lst复制到c盘下来,然后修改C盘下boot.ini文件,在最后一行添入C:\grldr="Load Linux"
编辑menu.lst文件为
default=0
timeout=5
title Linux
#分区7挂载/区,没有划分/boot区
kernel (hd0,6)/boot/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7 
initrd (hd0,6)/boot/initrd-2.6.11-1.1369_FC4.img

#分区7挂载/区,分区2挂载/boot区
#kernel (hd0,2)/vmlinuz-2.6.11-1.1369_FC4 ro root=/dev/hda7 
#initrd (hd0,2)/initrd-2.6.11-1.1369_FC4.img