Would really like to learn more about embedded linux. Found an incredible website \
about Bootdisks and the boot process at http://www.tldp.org/HOWTO/Bootdisk-HOWTO \ which will be a good \
start. Later I will tackle Linux from Stratch at http://www.linuxfromscratch.org/lfs/view/stable/chapter01/how.html

Also found some nice articles on a Tiny Busybox system written by the creator of BusyBox himself!
Part 1 http://www.linuxjournal.com/article/4335
Part 2 http://www.linuxjournal.com/article/4395

The Boot Process[-][--][++]

  1. BIOS calles sector 0, cylinder 0 of boot device
  2. Code on sector 0, cylinder 0 (bootloader or just a kernel) is executed
  3. Kernel (or bootloader) takes over and boots
  4. Kernel inits all device drivers (thats where those 4mill+ lines of code come it, all drivers)
  5. Kernel looks for root filesystem (/), or haults
  6. Kernel Executes /bin/init or /sbin/init from that root filesystem
  7. Init reads /etc/inittab
  8. Inittab looks at its sysinit line and executes the named scripts (usually /etc/rc.d/rc.S)
  9. Inittab looks at its initdefault line and executes that runlevel (scripts in /etc/rc.d/rc.X or /etc/rcX.d)

The basics needed for a root filesystem[-][--][++]

  1. The basic file system structure, a minimum set of directories: /dev, /proc, /bin, /etc, /lib, /usr, /tmp
  2. Basic set of utilities: sh, ls, cp, mv, etc.,
  3. Minimum set of config files: rc, inittab, fstab, etc.,
  4. Devices: /dev/hd*, /dev/tty*, /dev/fd0, etc.,
  5. Runtime library to provide basic functions used by utilities

Compressed file system[-][--][++]

We describe how to build a compressed filesystem, so called because it is compressed on disk and, when booted, \
is uncompressed onto a ramdisk. With a compressed filesystem you can fit many files \
(approximately six megabytes) onto a standard 1440K diskette. Because the filesystem is much larger than a \
diskette, it cannot be built on the diskette. We have to build it elsewhere, compress it, then copy it to the diskette.

Building our Bootdisk[-][--][++]

Development Location[-][--][++]

We need a temp space where we can build the linux system, before we compress it. So we use a normal linux laptop, and \
create a loopback device, which will be 4mb in size, just enough to hold our bootdisk stuff.

# dd if=/dev/zero of=/mnt/bootdisk_file bs=1k count=4094

Note: This /mnt/bootdisk_file is not a dir, it's a file

Make the filesystem ext2[-][--][++]

The Linux kernel recognizes two file system types for root disks to be automatically copied to ramdisk. These are minix and ext2, of which ext2 is preferred.
ALso, we could use any type of block device for our temp location, **here I am going to use a loop back device (a file \
mounted like a block device). You could easily use a spare partition, or ram disk /dev/ram0 or anything, as long as it's big enough \
to hold our uncompressed temporary work.

# mke2fs -m 0 -N 2000 /mnt/bootdisk_file

-N 2000 is the number if inodes to use (2000), default is 360 inodes on a 1.44Mb diskette but each device you will create \
later in /mnt/bootdisk/dev takes up 1 inode, so you will soon run out. We will set our filesystem file to have 2000 inodes.

Mount the new filesystem[-][--][++]

# mkdir /mnt/bootdisk
# mount -t ext2 -o loop /mnt/bootdisk_file /mnt/bootdisk

Now we have what looks like a normal block device, like a hard drive, but it's actually the contents of that bootdisk_file

Create dir structure[-][--][++]

NOTE, from now on we will be working in the /mnt/bootdisk folder, so think relatively

# mkdir dev
# mkdir proc
# mkdir etc
# mkdir sbin
# mkdir bin
# mkdir lib
# mkdir mnt
# mkdir usr

dev directory[-][--][++]

Device files are special, and must be created with 'mknod' command, or you can simply copy them from your existing linux system \
but you must copy them with the -R flag, just like this. Note for the /dev/fd[01] to work, you must have your floppy in the \
drive and recognized (reboot if it doesn't find it).

For some reason, my laptop does not recognize my floppy in linux, so I will use a spare partition

Note you MUST include console, kmem, mem, null, ram0, tty1

cp -dpR /dev/fd[01]* /mnt/bootdisk/dev
cp -dpR /dev/tty[0-6] /mnt/bootdisk/dev
cp -dpR /dev/console /mnt/bootdisk/dev
cp -dpR /dev/kmem /mnt/bootdisk/dev
cp -dpR /dev/mem /mnt/bootdisk/dev
cp -dpR /dev/null /mnt/bootdisk/dev
cp -dpR /dev/ram0 /mnt/bootdisk/dev

On my qlap01 I did

cp -dpR /dev/tty[0-6] /mnt/bootdisk/dev
cp -dpR /dev/sd* /mnt/bootdisk/dev
cp -dpR /dev/console /mnt/bootdisk/dev
cp -dpR /dev/kmem /mnt/bootdisk/dev
cp -dpR /dev/mem /mnt/bootdisk/dev
cp -dpR /dev/null /mnt/bootdisk/dev
cp -dpR /dev/ram* /mnt/bootdisk/dev

Which device files you copy/make is up to you, if it's not on the floppys dev folder, it won't be accessible. So if you want \
to use this disk to restore from a tape device, then ftape must be mknod'ed. Get it.

Note that one inode is required for each device special file, and inodes can at times be a scarce resource, especially
on diskette filesystems. You'll need to be selective about the device files you include. For example, if you do not have
SCSI disks you can safely ignore /dev/sd*; if you don't intend to use serial ports you can ignore /dev/ttyS*.