mbr

記錄MBR內容


更新記錄

item note
20170126 第一版

目錄


MBR

  • 硬碟內容分部如下[disk layout] 圖片來源:disk

The first sector (512 bytes) is the MBR and consists of

  • 446 bytes bootloader
  • 64 bytes partition table
  • 2 byte signature (0xAA55)
  • parted

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    [root@localhost ~]# parted -s /dev/sda print
    Model: ATA OCZ-ARC100 (scsi)
    Disk /dev/sda: 120GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos
    Disk Flags:

    Number Start End Size Type File system Flags
    1 1049kB 1117MB 1116MB primary ext4 boot
    2 1117MB 64.1GB 63.0GB primary ext4
  • mbr

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    [root@localhost ~]# dd bs=512 count=1 if=/dev/sda | od -Ax -tx1z -v
    1+0 records in
    1+0 records out
    512 bytes copied, 3.8772e-05 s, 13.2 MB/s
    000000 eb 63 90 10 8e d0 bc 00 b0 b8 00 00 8e d8 8e c0 >.c..............<
    000010 fb be 00 7c bf 00 06 b9 00 02 f3 a4 ea 21 06 00 >...|.........!..<
    000020 00 be be 07 38 04 75 0b 83 c6 10 81 fe fe 07 75 >....8.u........u<
    000030 f3 eb 16 b4 02 b0 01 bb 00 7c b2 80 8a 74 01 8b >.........|...t..<
    000040 4c 02 cd 13 ea 00 7c 00 00 eb fe 00 00 00 00 00 >L.....|.........<
    000050 00 00 00 00 00 00 00 00 00 00 00 80 01 00 00 00 >................<
    000060 00 00 00 00 ff fa 90 90 f6 c2 80 74 05 f6 c2 70 >...........t...p<
    000070 74 02 b2 80 ea 79 7c 00 00 31 c0 8e d8 8e d0 bc >t....y|..1......<
    000080 00 20 fb a0 64 7c 3c ff 74 02 88 c2 52 be 05 7c >. ..d|<.t...R..|<
    000090 b4 41 bb aa 55 cd 13 5a 52 72 3d 81 fb 55 aa 75 >.A..U..ZRr=..U.u<
    0000a0 37 83 e1 01 74 32 31 c0 89 44 04 40 88 44 ff 89 >7...t21..D.@.D..<
    0000b0 44 02 c7 04 10 00 66 8b 1e 5c 7c 66 89 5c 08 66 >D.....f..\|f.\.f<
    0000c0 8b 1e 60 7c 66 89 5c 0c c7 44 06 00 70 b4 42 cd >..`|f.\..D..p.B.<
    0000d0 13 72 05 bb 00 70 eb 76 b4 08 cd 13 73 0d 5a 84 >.r...p.v....s.Z.<
    0000e0 d2 0f 83 de 00 be 85 7d e9 82 00 66 0f b6 c6 88 >.......}...f....<
    0000f0 64 ff 40 66 89 44 04 0f b6 d1 c1 e2 02 88 e8 88 >d.@f.D..........<
    000100 f4 40 89 44 08 0f b6 c2 c0 e8 02 66 89 04 66 a1 >.@.D.......f..f.<
    000110 60 7c 66 09 c0 75 4e 66 a1 5c 7c 66 31 d2 66 f7 >`|f..uNf.\|f1.f.<
    000120 34 88 d1 31 d2 66 f7 74 04 3b 44 08 7d 37 fe c1 >4..1.f.t.;D.}7..<
    000130 88 c5 30 c0 c1 e8 02 08 c1 88 d0 5a 88 c6 bb 00 >..0........Z....<
    000140 70 8e c3 31 db b8 01 02 cd 13 72 1e 8c c3 60 1e >p..1......r...`.<
    000150 b9 00 01 8e db 31 f6 bf 00 80 8e c6 fc f3 a5 1f >.....1..........<
    000160 61 ff 26 5a 7c be 80 7d eb 03 be 8f 7d e8 34 00 >a.&Z|..}....}.4.<
    000170 be 94 7d e8 2e 00 cd 18 eb fe 47 52 55 42 20 00 >..}.......GRUB .<
    000180 47 65 6f 6d 00 48 61 72 64 20 44 69 73 6b 00 52 >Geom.Hard Disk.R<
    000190 65 61 64 00 20 45 72 72 6f 72 0d 0a 00 bb 01 00 >ead. Error......<
    0001a0 b4 0e cd 10 ac 3c 00 75 f4 c3 00 00 00 00 00 00 >.....<.u........<
    0001b0 00 00 00 00 00 00 00 00 9d 35 b3 27 00 00 80 20 >.........5.'... <
    0001c0 21 00 83 c3 3c 87 00 08 00 00 00 40 21 00 00 c3 >!...<......@!...<
    0001d0 3d 87 83 fe ff ff 00 48 21 00 00 00 55 07 00 00 >=......H!...U...<
    0001e0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 >................<
    0001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa >..............U.<
    000200

電腦開機程序

電腦開機程序

  • 當電腦的電源開啟,BIOS就會由主機板上的快閃記憶體(flash memory)執行

    • BIOS會把自己從快閃記憶體中,解壓縮到系統的主記憶體
    • bios: ex. openbios
  • BIOS将寻找第一个可启动的设备(通常为硬盘),而后从MBR中载入启动程序,然后把控制交给这段代码

  • BIOS開機完成後,bootloader就接手初始化硬體設備、建立記憶體空間的映射,以便為作業系統內核準備好正確的軟硬體環

    • 第一阶段引导程序位于主引导记录(MBR),用以引导位于某个分区上的第二阶段引导程序
    • bootloader: ex. NTLDR、BOOTMGR和GNU GRUB等。

GPT跟MBR的差別

GPT跟MBR的差別

  • BIOS所採用的磁碟分割方式為「MBR」(Master Boot Record),MBR只能定址約2TB左右的大小(2.2 × 1012位元組),
    而且也只支援最大4個主分割區,也就是如果你有一顆3TB以上的硬碟,一定無法只分割為一個分割區而能用完全部容量

  • GPT(GUID Partition Table)從特性上看來,確實比MBR優秀不少,光是可以支援最大容量到18EB(約為1887萬TB),
    以及分割區最大可以到128個,就足夠打到MBR站不起來了

  • GRUB on MBR
    partition table number: 4

    [GRUB on MBR]
  • GRUB on GPT

    [GRUB on MBR]

    圖片來源:GNU GRUB wiki


參考