Penguin
Annotated edit history of EPIA-Grub version 13, including all changes. View license author blame.
Rev Author # Line
13 IanMcDonald 1 InNeedOfRefactor
2
1 MattCollins 3 First draft:
4
12 IanMcDonald 5 !!!Using [GRUB] to boot EPIA with > 130gb drive on secondary channel
1 MattCollins 6
2 MattCollins 7 This document is primarily written as an alternative for those experiencing the lilo 'L 99' error found under [LiloNotes].
1 MattCollins 8
9
10 The guidance here resolves several issues for a specific situation. The configuration is such that we are using an EPIA M-II 10k motherboard with a CDR as IDE0 master and a > 136gb hard drive as IDE0 slave. A linux install is already laid out on the drive, but unaccessable due to boot loader issues.
11
12 !! Bios settings
13 The EPIA bios is unable to reliably identify the 203Gb drive I'm using; sometimes it will identify as 136gb, other times as 203gb. To resolve this, first go into the BIOS and set the drive to 'Manual' for primary slave.
14
15 Despite much documentation on the net regarding using LBA or Large mode, the bios will not reliably detect the disk with these options; the only way to hard code the sectors heads and cylinders is to use CHS. When setting CHS use bios autodetection to ensure the Capacity displayed is correct for your hard drive before saving. In my case that was 203Gb.
16
17 !! Interrogating your drive to discover layout
18
19 Next, boot from a linux ISO or floppy boot disk to get to a root shell prompt. 'fdisk /dev/hdb' followed by 'p' should show your layout. In my case, I had a 512 mb swap partition as /dev/hdb1 and the rest of the disk as a single boot partition called /dev/hdb2.
20
21 !! Mount your existing root partition and set it as root
22
3 MattCollins 23 This is done as follows; 'mkdir /mnt' will make a mount point if not already present.
24
25 Next, mount the partition displayed by fdisk, in this case hdb2, as follows:
26 'mount /dev/hdb2 /mnt'.
1 MattCollins 27
28 Finally, we set this as our root partition for further work. This will make life much easier as we will no longer load binaries from CDRom or floppy with the associated loading delays:
29
30 'chroot /mnt bash'
31
32 If you prefer ksh, sh, or another shell simply substitute its name for 'bash' in the above command.
33
34 We are now root editing our inaccessible system.
35
36 !! See if you have network connectivity
37
38 'ifconfig -a' will list network interfaces. If you don't see your local interface, either configure it up with 'ifconfig eth0 inet <ip address> netmask <netmask> up' and 'route add -net default gw <gateway>' or use the 'dhclient' command to retrieve an ip address from any local dhcp server.
39
40 !! Install grub
41
42 Documentation can be found at [http://www.gnu.org/software/grub/]. Using debian (or derivatives such as knoppix) I simply typed 'apt-get install grub'.
43
44 !! Configure grub
45
46 'grub-install --force-lba --no-floppy /dev/hdb' will install grub and layout the appropriate files under /boot. Under debian 'update-grub' will then build a menu of available kernel images, which can be edited under '/boot/grub/menu.list'. For non debian users typing
47
5 MattCollins 48 <pre>
1 MattCollins 49 grub
5 MattCollins 50 </pre>
1 MattCollins 51 followed by
5 MattCollins 52 <pre>
1 MattCollins 53 root (hd0,1)
54 setup (hd0)
5 MattCollins 55 </pre>
1 MattCollins 56
57 will install the basic grub bootloader without a menu. In the above example 'hd0' indicates our first hard drive (the cdrom is not included in that scan), '1' indicates our 2nd partition listed under fdisk (hdb2).
58
6 MattCollins 59 __Note__: grub starts counting partitions from 0, rather than 1, so fdisk hdb1 is grub partition (hd0,0), hdb2 is (hd0,1), etc. Grub also ignores extended partitions, so if you are using any you will need to subtract an additional 1 from the count.
1 MattCollins 60
61 !! Further changes
62
63 So far, so good - but what if the partitions you wish to boot are above the 136gb mark? At this point grub will give you 'Error 18', the bios does not support the cylinder that partition is present on.
64
65 To avoid this error, I repartitioned my drive as follows:
66
67 First, I stole 40mb from my swap partition to make a 'boot' partition within the first 1024 cylinders of the disk, those supported by the BIOS. To ensure no configuration changes were required, I did the following:
68
4 MattCollins 69 # Delete existing swap partition
70 # Create new swap partition 40mb smaller
71 # Create new boot partition within first 1023 cylinders
72 # set new swap partition to be of type swap
73 # write table
74 # Edit /etc/fstab and add a new line as follows:
1 MattCollins 75 <pre>
76 /dev/hdb3 /boot ext3 defaults 0 1
77 </pre>
78
6 MattCollins 79 __Note__: 'hdb3' will only be correct if you created your new boot space as partition three during the fdisk operations.
1 MattCollins 80
4 MattCollins 81 # Copy boot files over:
1 MattCollins 82 <pre>
83 mount /dev/hdb3 /mnt
84 cd /boot
85 find . | cpio -pdv /mnt
86 umount /mnt
87 rm -rf *
88 </pre>
89
90 Be very careful to ensure you only type the rm -rf command while still under the /boot directory, and that all the files successfully copied during the cpio stage.
91
92 At this point, either 'update-grub' under debian or 'system (hd0,2)' using the 'grub' command will set grub to boot off your new boot partition to load the kernel, allowing OS images to be above cylinder 1023.
93
94 Once again, edit your menu.lst file to ensure your OS entries list the correct partitions for the actual operating system images.
95
96 An example follows:
97
98 <pre>
99 title test, kernel 2.6.13.2-chw-3
100 root (hd0,2)
101 kernel /vmlinuz-2.6.13.2-chw-3 root=/dev/hdb2 ro
102 savedefault
103 boot
104 </pre>
105
106 This line will provide a grub menu option titled 'test, kernel 2.6.13.2-chw-3' located on our new boot partition (hd0,2) (hard disk 0, fdisk partition , which we just created). Once located the kernel will be loaded with the line 'root=/dev/hdb2', telling it to find the rest of the operating system under linux hard disk hdb2. If you wish to create subsequent OS images to test other distros, os's or builds on, the kernel is simply loaded with a different root= argument.
107
6 MattCollins 108 __Fdisk example__:
1 MattCollins 109
110 The commands for fdisk are shown below:
111 <pre>
112 fdisk /dev/hdb
113
114 The number of cylinders for this disk is set to 24792.
115 There is nothing wrong with that, but this is larger than 1024,
116 and could in certain setups cause problems with:
117 1) software that runs at boot time (e.g., old versions of LILO)
118 2) booting and partitioning software from other OSs
119 (e.g., DOS FDISK, OS/2 FDISK)
120
121 Command (m for help): p
122
123 Disk /dev/hdb: 203.9 GB, 203928109056 bytes
124 255 heads, 63 sectors/track, 24792 cylinders
125 Units = cylinders of 16065 * 512 = 8225280 bytes
126
127 Device Boot Start End Blocks Id System
128 /dev/hdb1 1 65 522080+ 82 Linux swap / Solaris
129 /dev/hdb2 66 23432 198619627+ 83 Linux
130
131 Command (m for help): d
132 Partition number (1-6): 1
133
134 Command (m for help): n
135 Command action
136 l logical (5 or over)
137 p primary partition (1-4)
138 p
139 Selected partition 1
140 First cylinder (1-24792, default 1): 1
141
142 Last cylinder or +size or +sizeM or +sizeK (1-60): 60 <-- note we have reduced the cylinder count here by 5
143
144 Command (m for help): n
145 Command action
146 l logical (5 or over)
147 p primary partition (1-4)
148 p
149 Selected partition 1
150 First cylinder (1-24792, default 1): 61
151
152 Last cylinder or +size or +sizeM or +sizeK (1-60): 65
153
154 Command (m for help): t
155 Partition number (1-6): 1
156 Hex code (type L to list codes): 82
157 Changed system type of partition 1 to 82 (Linux swap / Solaris)
158
159 Command (m for help):w
160 partition written to disk
161
162 Command (m for help): q
163 </pre>
164
165 !! Final words:
166
4 MattCollins 167 But... other distros? Our whole disk is eaten by hdb2. Well, ext2 and ext3 filesystems can be resized without losing data. To do so use the 'resize2fs' command; if your partition is ext3 you will need to disable journaling with the 'tune2fs -O ^has_journal /dev/hdX' command first, use resize2fs to shrink your disk spanning drive, then re-enable it once done using 'tune2fs -j /dev/hdX'.
9 MattCollins 168
169 Once resized use fdisk to delete the old partition data and recreate it __starting at the same cylinder__ but finishing just above the new end point. This can be calculated by the following method:
170
171 <pre>
172 (number of cylinders reported in fdisk) / (old size in blocks reported by 'fsck.ext2 /dev/hdb2') = cylinders per block
173 (new size in blocks reported by 'resize2fs /dev/hdb2 <size>') * (cylinders per block) = size of new partition in cylinders
10 MattCollins 174 </pre>
9 MattCollins 175
10 MattCollins 176 So:
177
178 # Disable journaling with 'tune2fs -O ^has_journal /dev/hdX'
179 # fsck.ext2 -f /dev/hdX to check the filesystem is ok.
180 # resize2fs /dev/hdX <new, smaller, size>
181 # under fdisk, set the start partition to be the old starting cylinder, and define the size as +<size of new partition in cylinders> using the method described above.
182 # use fsck.ext2 to ensure your new size isn't smaller than the filesystem; if it is, fsck.ext2 will immediately quit warning you of this issue. If not, you're likely to have overshot by a few blocks.
183 # use 'resize2fs /dev/hdbX' to grow the filesystem to use the full size of the new partition,
184 # finally, re-enable journaling with the 'tune2fs -j /dev/hdX' command.
4 MattCollins 185
6 MattCollins 186 __Note__: this MUST be done with the drive unmounted - once again, boot off your cd or floppy, and work on the drive unmounted.
4 MattCollins 187
188 With your boot partition in the first 1023 cylinders as outlined above it is perfectly possible to place your subsequent OS layouts in extended partitions anywhere on the disk.
189
190 Create a new extended partition as partition 4, then divide up the space amongst as many drives as you like. I made two 5gb partitions for a 'stable' and 'test' OS image, while keeping /dev/hdb2 simply as a 'data' partition for my home directories and PVR recordings.
7 MattCollins 191
192 Once resized, my filesystem looked as follows:
193
194 Fdisk:
195 <pre>
196 Disk /dev/hdb: 203.9 GB, 203928109056 bytes
197 255 heads, 63 sectors/track, 24792 cylinders
198 Units = cylinders of 16065 * 512 = 8225280 bytes
199
200 Device Boot Start End Blocks Id System
201 /dev/hdb1 1 60 481918+ 82 Linux swap / Solaris
202 /dev/hdb2 66 23432 187695427+ 83 Linux
203 /dev/hdb3 61 65 40162+ 83 Linux
204 /dev/hdb4 23433 24792 10924200 5 Extended
205 /dev/hdb5 23433 24112 5462068+ 83 Linux
206 /dev/hdb6 24113 24792 5462068+ 83 Linux
207 </pre>
208
8 MattCollins 209 /etc/fstab for /dev/hdb6:
7 MattCollins 210 <pre>
211 # filesystem mountpoint type options dump pass
212 /dev/hdb6 / ext3 defaults,errors=remount-ro 0 1
213 /dev/hdb3 /boot ext3 defaults 0 1
214 /dev/hdb2 /data ext3 defaults 0 2
215 /dev/hdb1 none swap defaults 0 0
216
217 proc /proc proc defaults 0 0
218 sysfs /sys sysfs defaults 0 0
219 </pre>
220
221 /boot/grub/menu.lst:
222 <pre>
223 default 0
224 timeout 5
225 color cyan/blue white/blue
226 title stable, kernel 2.6.13.2-chw-3
227 root (hd0,2)
228 kernel /vmlinuz-2.6.13.2-chw-3 root=/dev/hdb6 ro
229 savedefault
230 boot
231 title stable, kernel 2.6.13.2-chw-3 (recovery mode)
232 root (hd0,2)
233 kernel /vmlinuz-2.6.13.2-chw-3 root=/dev/hdb6 ro
234 savedefault
235 boot
236 title test, kernel 2.6.13.2-chw-3
237 root (hd0,2)
238 kernel /vmlinuz-2.6.13.2-chw-3 root=/dev/hdb2 ro
239 savedefault
240 boot
241 title test, kernel 2.6.13.2-chw-3 (recovery mode)
242 root (hd0,2)
243 kernel /vmlinuz-2.6.13.2-chw-3 root=/dev/hdb2 ro single
244 savedefault
245 boot
246 </pre>
247
248 /boot/grub/device.map
249 <pre>
250 (hd0) /dev/hdb
251 </pre>
11 MattCollins 252
253 Any questions, I'm at matt at clues dot com ;)