AUTHOR:         Jim Gifford <lfs-hints at jg555.com>

DATE: 		2004-02-14

LICENSE: 	GNU Free Documentation License Version 1.2

SYNOPSIS: 	initrd for LFS that will check and repair
		ext2 and ext3 file system errors

DESCRIPTION: 	This hint will assist you in creating a initrd
		for your LFS system, that will check for file
		system errors

PREREQUISITES:  SCSI and USB Modules must be in modules.conf
		Linux built with modules.
			RAM Disk support built in
			initrd selected
			Root Filesystem must be compiled in
		Busybox-1.00-pre7
		e2fsprogs 1.34
HINT:

Introduction to Initial RAMDisk

This hint will help you configure an LFS system for Initial RAMDisk.
Which will allow you to add modules at start-up instead of compiling them
into the kernel.

The script will auto-detect all SCSI, IDE and USB modules and add them
to the initial ramdisk. It will also detect the root from the fstab file

The above items, upon research are best if configured into the kernel. 
You can look at the help of each of the items for more information.

---
Assumptions Made in this document

	I have made the following assumptions in this document.
	Files have been downloaded.

---
Kernel Configuration for 2.4

	You will need to make sure the following items are configured
	in your kernel. With out these, the initrd will not work 
	properly.

	Block devices  --->
		<M> Loopback device support (or <*>)
		<*> RAM disk support
		(4096)   Default RAM disk size
		[*]   Initial RAM disk (initrd) support

	The root and initrd file system must be compiled into the kernel.
	
---
Kernel Configuration for 2.6

	You will need to make sure the following items are configured
	in your kernel. With out these, the initrd will not work
	properly.

	Device Drivers  --->
		Block devices  --->
			<M> Loopback device support (or <*>)
			<*> RAM disk support
			(4096)   Default RAM disk size
			[*]   Initial RAM disk (initrd) support

	The root and initrd file system must be compiled into the kernel.


---
File Systems

	The script has 2 choices of file systems.
	ext2 and ext3.

	ext2 and ext3 are the most common file systems
	in use, but the initrd is usually bigger.
	My initrd with ext3 was only 439k. Compressed with
	gzip -9

---
Needed Programs
	
	e2fsprogs
	----

	Build as normal, but after install issue these commands
		
        cp e2fsck/e2fsck.static /sbin/e2fsck.static
        strip --strip-debug /sbin/e2fsck.static

	busybox 1.00-pre3
	----

	Download From
	http://busybox.net/downloads/busybox-1.00-pre3.tar.bz2	

	Information
	http://busybox.net
	
	Busybox has changed the way the configure the shell. It now
	uses a menu driven option very similar to make menuconfig
	in linux.

	Here is the list of the options needed. Anything else
	will add to the size of your initrd.

	General Configuration --->
		[*] Support for devfs
			NOTE - only if you using devfs
		Build Options  --->
		[*] Build BusyBox as a static binary (no shared libs)
	Coreutils  --->
		[*] echo (basic SUSv3 version taking no options
		[*] ln
	Linux Module Utilities  --->
		[*] insmod
		[*]     Support version 2.1.x to 2.4.x Linux kernels
			NOTE - only if your using a 2.4 kernel
		[*]     Support version 2.6.x Linux kernels
			 NOTE - only if your using a 2.6 kernel
	Another Bourne-like Shell  --->
		[*]     Enable alias support
		[*]     Optimize for size instead of speed
		(0) history size
	Linux System Utilities  --->
		[*] pivot_root
		[*] mount

	The build size on my system was 502k, considerably smaller than
	bash.

	After running make menuconfig you will need to run the
	following commands.

	make
	cp busybox /bin/busybox.static.fsck

---
mkfsckinitrd

	For those who do not want to type out the script. It is
	available on my CVS server at 
	http://cvs.jg555.com/viewcvs.cgi/scripts/system
	
	This script will create the initial RAM Disk image file.
	By default this script creates /boot/initrd-fsck-{kernelversion}.img

	I have sent a mkinitrd file to be placed
	in the hints attachments at 
	http://www.linuxfromscratch.org/hints/downloads/attachments. 
	
	The default location for this file is /sbin

	There are options on the new script, it will not just create
	a initrd anymore. The kernel_version= is the only mandatory
	option

	Options are the following:

	Required
        --kernel_version={version} = use kernel version

	Optional
	--ide = remove ide modules
	--scsi = remove scsi modules
	--usb = remove usb modules
	--devfs = remove devfs settings from initrd
	--initrdfs={ext2|ext3} = use either ext2 or ext3
        --remove-module={module} = remove module
        --add-module={module} = add module

---
initrd script

	The following script needs to placed in /etc/rc.d/init.d.
	If you already have this script added, you do not need to
	add it again. This is the same one from the initrd hint.

	You will then need to link it to rcsysinit.d.

	It is recommended that this script be run right after
	mountfs.

	To link the script change to the /etc/rc.d/rcsysinit.d
	directory and issue the following command.

	ln -sf ../init.d/initrd S41initrd

#!/bin/bash
# Begin $rc_base/init.d/initrd

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

echo "Clearing Initial RAM Disk..."
	if [ -e /initrd/dev/.devfsd ]
		then
      		umount /initrd/dev
   	fi
	umount /initrd/proc
   	umount /initrd
   	blockdev --flushbufs /dev/ram0

# End $rc_base/init.d/initrd
		
---
For Lilo

	In order to use the initrd.img file is to add the
	following entry to you lilo.conf file.

	initrd=/boot/initrd-fsck.img

	So your lilo.conf should look something like this.

	image=/boot/vmlinuz-2.4.18
	label=test
	initrd=/boot/initrd-fsck-2.4.18.img
	read-only

	If you are just testing. You should make a separate
	entry in lilo.conf. This will still allow you to boot.	

---
For Grub

	In order to use the initrd.img file is to add the
	following entry to you menu.lst file.

	initrd /boot/initrd-fsck-2.4.18.img

	So your menu.lst should look something like this.

	title test
	root (hd0,1)
	kernel /boot/vmlinuz-2.4.18
	initrd /boot/initrd-fsck-2.4.18.img

---
For Syslinux

	In order to use the initrd.img file is to add the
	following to syslinux.cfg file.

	append initrd=initrd-fsck-2.4.18.img

	So your syslinux.cfg should look something like this.

	label test
	kernel vmlinuz
	append root=/dev/ram0 initrd=initrd-fsck.img

---

VERSION:        1.3

CHANGELOG:     	1.3 Updated Configurations
		1.2 Updated for 2.6 Kernel
		1.1 Fixed Typos
		1.0 Initial Version

 New Version of this document can be viewed from http://cvs.jg555.com/viewcvs.cgi/lfs-hints