Merge remote-tracking branch 'origin/pr/16'
[grml2usb.git] / doc / mbr.8.txt
1 Master Boot Record, Booting from USB etc.(8)
2 ============================================
3
4 Name
5 ----
6 mbr - Master Boot Record, Booting from USB etc.
7
8 Synopsis
9 --------
10
11 None. :)
12
13 [IMPORTANT]
14 This document is work in progress.
15
16 [NOTE]
17 We are using /dev/sdz as the typical device name. Adjust it to whatever
18 your device corresponds to of course, it's just to prevent any data loss due to
19 wrong copy/paste.
20
21 Layout
22 ------
23
24 The Master Boot Record (MBR) is the first data block with 512 bytes on the x86
25 architecture providing a partition table and a bootloader.  In the first 446
26 bytes is the bootcode, providing the bootloader (400 bytes), a disk signature (4
27 bytes) and NULL (2 bytes).  The following 64 bytes are the partition table,
28 followed by 2 bytes which are the MBR signature.
29
30 Bootcode
31 ~~~~~~~~
32
33 The bootcode consists of bootloader and disk signature:
34
35 Bootloader
36 ^^^^^^^^^^
37
38 Windows: ntldr with boot.ini (Windows NT/XP) or bootmgr with \Boot\BCD (Windows Vista)
39
40 Disk Signature
41 ^^^^^^^^^^^^^^
42
43 Operating systems like Windows identify the disk using the disk signature.
44 Running 'fixmbr' doesn't touch the disk signature but just the bootloader.
45 Running 'fdisk /mbr' touches the bootloader *and* the disk signature (it writes
46 a standard MBR, it won't touch the partition table though).
47 TODO: what about fixboot?
48
49 Partition table
50 ~~~~~~~~~~~~~~~
51
52 Harddisk addressable: 8GB (Cylinder Head Sector, CHS), 2TB (Logical Block
53 Addressing with 32bit, LBA) or >2TB (GUID Partition Table, GPT)
54
55 MBR Signature
56 ~~~~~~~~~~~~~
57
58 The 2 bytes 55 and AA (both hex), known as the Magic Number. This signature
59 tells the system that there should exist a valid MBR - otherwise you'll get
60 something like "No operating system" or "Non-Bootable Disk".
61
62 Backup and Restore
63 ------------------
64
65 Clone whole MBR:
66
67   # dd if=/dev/sdz of=mbr_backup.dd bs=512 count=1
68
69 Restore the MBR again:
70
71   # dd if=mbr_backup.dd of=/dev/sdz bs=512 count=1
72
73 Clone MBR *without* partition table:
74
75   # dd if=/dev/sdz of=mbr_bootcode.dd bs=446 count=1
76
77 Restore MBR *without* partition table again:
78
79   # dd if=mbr_bootcode.dd of=/dev/sdz bs=446 count=1
80
81 Backup partition layout:
82
83   # sfdisk -d /dev/sdz > backup.sfdisk
84
85 Restore partition layout again:
86
87   # sfdisk /dev/sdz < backup.sfdisk
88
89 Write new, clean MBR:
90
91   lilo -M /dev/sdz -s /dev/null
92
93 USB modes
94 ---------
95
96   * USB-HDD: usually the default and preferred booting mode.
97   * USB-ZIP: ??? - can be set up via:
98
99     # mkdiskimage -4    /dev/sdz 1  64 32 # device = 1GB
100     # mkdiskimage -4    /dev/sdz 0 128 32 # device >1GB and <=2GB
101     # mkdiskimage -F -4 /dev/sdz 0 255 63 # device >2GB and <=8GB
102
103     For devices above 8GB (taken from
104     http://www.knoppix.net/wiki/Bootable_USB_Key):
105
106     # mkdiskimage -F -4 /dev/sdz 1 255 63
107     # dd if=/dev/zero of=/dev/sdz bs=1 seek=446 count=64
108     # echo -e ',0\n,0\n,0\n,,C,*' | sfdisk /dev/sdz
109
110     USB-ZIP requires to have 64 heads and 32 sectors and less than 1024
111     cylinder count.
112
113   * USB-Floppy: ???
114
115 TODO
116 ----
117
118 Check out the *real* difference between:
119
120   # mbr-install /dev/ice
121   # lilo -S /dev/null -M /dev/ice ext && lilo -S /dev/null -A /dev/ice 1
122   # cat /usr/lib/syslinux/mbr.bin > /dev/ice
123   # syslinux /dev/iceX
124   # syslinux -sf /dev/iceX
125   # mkdiskimage ... (USB-ZIP?)
126   # ...?
127
128 Partition stuff:
129
130   * How does a correct partition look like?
131   * The partition should start behind MBR at 1st cylinder and 63rd sector?
132   * fdisk -l -u /dev/sdz vs. fdisk -l /dev/sdz
133
134 Resources
135 ---------
136
137 * http://de.wikipedia.org/wiki/Master_Boot_Record
138 * http://en.wikipedia.org/wiki/Master_boot_record
139 * http://michael-prokop.at/blog/2007/04/22/booting-from-usb-pen-troubleshooting-and-pitfalls/
140 * http://www.ata-atapi.com/hiwmbr.html
141 * http://thestarman.pcministry.com/asm/mbr/index.html