Add mbr/ - update --grub handling
[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 Troubleshooting and Pitfalls when booting
94 -----------------------------------------
95
96 ///////////////////////////////////////////////////////////
97 TODO: better list type for the error message / reason part?
98 See http://www.methods.co.nz/asciidoc/userguide.html
99 ///////////////////////////////////////////////////////////
100
101 [horizontal]
102 *Error message*:: ran out of input data. System halted
103
104 *Reason*:: Everything OK, except for the filesystem used on your usb device. So
105 instead of fat16 you use for example fat32. Fix: use the appropriate filesystem
106 (fat16 for usb pens usually). The Bootsplash might be displayed, the kernel
107 loads but you very soon get the error message.
108
109 *Error message*:: Invalid operating system
110
111 *Reason*:: the partition layout is not ok. Very probably there’s no primary
112   partition or none has the flag ‘bootable’ set.
113
114 *Error message*:: No operating system found.
115
116 *Reason*:: you forgot to set the boot-flag on the partition. Or there really isn't
117 any operating system at all.
118
119 *Error message*:: kernel-panic: unable to mount root-fs...
120
121 *Reason*:: Kernel boots but fails to find the root filesystem. root= argument in
122 your kernel commandline is pointing to the wrong device. Adjust root=...,
123 consider using root=UUID=....
124
125 *Error message*::  Could not find kernel image: ...
126
127 *Reason*:: either a broken isolinux/syslinux version or a broken BIOS. Check out
128 whether the vendor provides a BIOS update or if using bootloader grub instead of
129 isolinux/syslinux fixes the problem.
130
131 USB modes
132 ---------
133
134   * USB-HDD: usually the default and prefered booting mode.
135   * USB-ZIP: ??? - can be set up via:
136
137     # mkdiskimage -4    /dev/sdz 1  64 32 # device = 1GB
138     # mkdiskimage -4    /dev/sdz 0 128 32 # device >1GB and <=2GB
139     # mkdiskimage -F -4 /dev/sdz 0 255 63 # device >2GB and <=8GB
140
141     For devices above 8GB (taken from
142     http://www.knoppix.net/wiki/Bootable_USB_Key):
143
144     # mkdiskimage -F -4 /dev/sdz 1 255 63
145     # dd if=/dev/zero of=/dev/sdz bs=1 seek=446 count=64
146     # echo -e ',0\n,0\n,0\n,,C,*' | sfdisk /dev/sdz
147
148     USB-ZIP requires to have 64 heads and 32 sectors and less than 1024
149     cylinder count.
150
151   * USB-Floppy: ???
152
153 TODO
154 ----
155
156 Check out the *real* difference between:
157
158   # mbr-install /dev/ice
159   # lilo -S /dev/null -M /dev/ice ext && lilo -S /dev/null -A /dev/ice 1
160   # cat /usr/lib/syslinux/mbr.bin > /dev/ice
161   # syslinux /dev/iceX
162   # syslinux -sf /dev/iceX
163   # mkdiskimage ... (USB-ZIP?)
164   # ...?
165
166 Partition stuff:
167
168   * How does a correct partition look like?
169   * The partition should start behind MBR at 1st cylinder and 63rd sector?
170   * fdisk -l -u /dev/sdz vs. fdisk -l /dev/sdz
171
172 Resources
173 ---------
174
175 * http://de.wikipedia.org/wiki/Master_Boot_Record
176 * http://en.wikipedia.org/wiki/Master_boot_record
177 * http://michael-prokop.at/blog/2007/04/22/booting-from-usb-pen-troubleshooting-and-pitfalls/
178 * http://www.ata-atapi.com/hiwmbr.html
179 * http://thestarman.pcministry.com/asm/mbr/index.html