Wednesday, September 9, 2009

Linux boot sequence

When using initrd, the system typically boots as follows:

1) the boot loader loads the kernel and the initial RAM disk
2) the kernel converts initrd into a "normal" RAM disk and
frees the memory used by initrd
3) initrd is mounted read-write as root
4) /linuxrc is executed (this can be any valid executable,
including shell scripts; it is run with uid 0 and can do
basically everything init can do)
5) linuxrc mounts the "real" root file system
6) linuxrc places the root file system at the root directory
using the pivot_root system call
7) the usual boot sequence (e.g. invocation of /sbin/init) is
performed on the root file system
8) the initrd file system is removed

Note that changing the root directory does not involve unmounting
it. It is therefore possible to leave processes running on initrd
during that procedure. Also note that file systems mounted under
initrd continue to be accessible.


Booting off of a SAN disk, requires the relevant module/driver to be loaded.

mkinitrd

# Load kernel modules:
if [ ! -d /lib/modules/`uname -r` ]; then
echo "No kernel modules found for Linux `uname -r`."
elif [ -x ./load_kernel_modules ]; then # use load_kernel_modules script:
echo "/boot/initrd.gz: Loading kernel modules from initrd image:"
. ./load_kernel_modules
else # load modules (if any) in order:
if ls /lib/modules/`uname -r`/*.*o 1> /dev/null 2> /dev/null ; then
echo "/boot/initrd.gz: Loading kernel modules from initrd image:"
for module in /lib/modules/`uname -r`/*.*o ; do
insmod $module
done
unset module
fi
fi

linuxrc script


No comments: