Prepping a CF with grub for a wrap
From ME2000
Contents |
Introduction
This howto takes you through prepping a Compact Flash card with the GRUB bootloader for use in a wrap board. It assumes that you have (or will have) a bzImage kernel and a rootfs.gz compressed root filesystem to add to the cf. Test files are provided at the bottom of this page.
The Detail
First, fdisk the CF, and make a single e2fs partition on the CF as partition 1. /dev/hdc happens to be where my laptop sees the Compact Flash card when I insert it into a CF to PCMCIA adapter, and then into the laptop.
fdisk /dev/hdc
Make a primary partition of type linux, and make it bootable. Do a mke2fs on it as well.
mke2fs /dev/hdc1
At this stage, it cant to do an fsck. Reduces complaining when the kernel is booting due to unchecked filesystems.
fsck /dev/hdc1
Then mount the filesystem
mount /dev/hdc1 /mnt
We have to mount the file system because we tell grub to use the mountpoint as a location to install the grub files. Now we can install grub on the CF. This installs an MBR (Master Boot Record) on the CF, and also writes the various boot stages of the grub loader to the /mnt/boot/grub directory
grub-install --no-floppy --root-directory=/mnt /dev/hdc
Next, check the /mnt/boot/grub/device.map
On my laptop, I ended up with a device.map as
(hd0) /dev/hda (hd1) /dev/hdc
This is not what we want when booting on the wrap, so we change it to just
(hd0) /dev/hda
Now, to add the mnt/boot/grub/menu.lst file. Open a new menu.lst file, and insert the following contents
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1 terminal --timeout=10 serial default 0 timeout 5 title ME2000v3 root (hd0,0) kernel /bzImage init=/initrd root=/dev/ram0 rw console=ttyS0,38400n8 reboot=bios initrd /rootfs.gz boot
As you can see on the kernel line, the boot sequence expects a bzImage kernel file and a rootfs.gz compressed root filesystem file in /
So, copy the bzImage and rootfs.gz that you prepared earlier to /mnt. Then insert into the Wrap, and see how you go. If all goes well, you'll see the grub meny on the serial port at 38400 baud (n81). If things go even better, then your kernel will boot and mount the rootfs, and bring up your distro.
Conclusion
Gone is syslinux, DOS, and it's 8.3 filesystem limitation. Welcome to GRUB.
EndNote
If you're connected to IrishWAN, you could use the following for testing:
Appendix - Screen Grab of full prep
daveh@daveh-desktop:~$ sudo bash
root@daveh-desktop:~#
root@daveh-desktop:~# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 32 MB, 32505856 bytes
1 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 62 * 512 = 31744 bytes
Disk identifier: 0x19af85bd
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (2-1024, default 2):
Using default value 2
Last cylinder, +cylinders or +size{K,M,G} (2-1024, default 1024):
Using default value 1024
Command (m for help): p
Disk /dev/sdb: 32 MB, 32505856 bytes
1 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 62 * 512 = 31744 bytes
Disk identifier: 0x19af85bd
Device Boot Start End Blocks Id System
/dev/sdb1 2 1024 31713 83 Linux
Command (m for help): a
Partition number (1-4): 1
Command (m for help): p
Disk /dev/sdb: 32 MB, 32505856 bytes
1 heads, 62 sectors/track, 1024 cylinders
Units = cylinders of 62 * 512 = 31744 bytes
Disk identifier: 0x19af85bd
Device Boot Start End Blocks Id System
/dev/sdb1 * 2 1024 31713 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
root@daveh-desktop:~# mke2fs /dev/sdb1
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
7936 inodes, 31712 blocks
1585 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=32505856
4 block groups
8192 blocks per group, 8192 fragments per group
1984 inodes per group
Superblock backups stored on blocks:
8193, 24577
Writing inode tables: done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@daveh-desktop:~# fsck /dev/sdb1
fsck 1.41.4 (27-Jan-2009)
e2fsck 1.41.4 (27-Jan-2009)
/dev/sdb1: clean, 11/7936 files, 1390/31712 blocks
root@daveh-desktop:~#
root@daveh-desktop:/# mount /dev/sdb1 /mnt
root@daveh-desktop:/# grub-install --no-floppy --root-directory=/mnt /dev/sdb
Probing devices to guess BIOS drives. This may take a long time.
grub-probe: error: Cannot find a GRUB drive for /dev/sdb1. Check your device.map.
[: 494: =: unexpected operator
Installing GRUB to /dev/sdb as (hd1)...
Installation finished. No error reported.
This is the contents of the device map /mnt/boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.
(hd0) /dev/sda
(hd1) /dev/sdb
root@daveh-desktop:/# cd /mnt/boot/grub
root@daveh-desktop:/mnt/boot/grub# cat device.map
(hd0) /dev/sda
(hd1) /dev/sdb
root@daveh-desktop:/mnt/boot/grub# vi device.map
root@daveh-desktop:/mnt/boot/grub# cat device.map
(hd0) /dev/hda
root@daveh-desktop:/mnt/boot/grub# cat menu.lst
cat: menu.lst: No such file or directory
root@daveh-desktop:/mnt/boot/grub# vi menu.lst
root@daveh-desktop:/mnt/boot/grub# cat menu.lst
serial --unit=0 --speed=38400 --word=8 --parity=no --stop=1
terminal --timeout=10 serial
default 0
timeout 5
title ME2000v3
root (hd0,0)
kernel /bzImage init=/initrd root=/dev/ram0 rw console=ttyS0,38400n8 reboot=bios
initrd /rootfs.gz
boot
root@daveh-desktop:/mnt/boot/grub#
# Then from the machine where the development env is (it's on a VirtualBox Ubuntu guest on a Vista machine)
# copy rootfs.gz and bzImage onto the Compact Flash.
# scp rootfs.gz root@10.4.11.2:/mnt
# scp bzImage root@10.4.11.2:/mnt
# Then unmount the CF, insert into the Alix, and boot.

