#!/bin/bash # # /linuxrc: init script to load initrd kernel modules # # # For More Ramdisk Options ... # ---------------------------- # linuxrc.Commands.Help.txt # # # # 02-Nov-04 amo Create a minimal initrd.gz to load the rootfs.gz as / # 13-Nov-04 amo Split off ramdisk options into linuxrc.Commands.Help.txt # # # # Define the path # export PATH="/sbin:/bin:/usr/sbin:/usr/bin" # # # Exit if the Commands fails # ========================== # function docmd { cmd="$1" # ERR="" # # check for the mount commands mnt=`echo "$cmd" | grep ^mount | cut -d ' ' -f 1` # # check for comments com=`echo "$cmd" | grep ^# | cut -d ' ' -f 1` # # if [ "$com" = "#" ]; then # # not a command echo "$cmd" # else echo "" echo "$cmd" $cmd # stat=$? if [ $stat != 0 ]; then echo "" echo "ERROR: Failed: ${stat}: $cmd " # # mount and df fails depending on /proc being mounted or not # 32 == it wants " mount -t type " if [ "$mnt" = "mount" -a $stat != 32 ]; then echo " already mounted" echo "" else echo "#" echo "# Aborting: /linuxrc" echo "#" # ERR="1" fi fi # # show what's mounted after the mount command # if [ "$mnt" = "mount" ]; then docmd "cat /proc/mounts" # ls -la /etc/mtab docmd "cat /etc/mtab" # docmd "mount" # show whats mounted docmd "df" fi # if [ ! -z "$ERR" ]; then exit 1 fi fi # } # docmd # # # Flush and reset first # umount /dev/hda1 umount /dev/ram0 umount /proc # # docmd "#" docmd "# Executing /linurc" docmd "#" # # # leave a " " in front of mount, to avoid the premature output of an empty /proc/mounts # ----------------------------- # # # Check /proc # =========== # if [ ! -f "/proc/mounts" ]; then # # Mount /proc filesystem # ---------------------- #ocmd " mount -n -t proc proc /proc" # # knoppix uses none and /dev/pts docmd " mount -n -t proc none /proc" #ocmd " mount -n -t devfs none /dev/pts" # mount -t devpts /dev/pts /dev/pts # # linux-2.6 # mount -t sysfs /sys /sys >>$log 2>&1 # # else # echo "#" echo "# /proc already mounted " echo "#" # fi # # # Make / writable ( need "-n" for /etc/mtab ) # --------------- docmd " mount -n -o rw,remount /dev/ram0 /" # # Remount it again so that it shows up in the now writable /etc/mtab # ---------------- docmd "mount -o rw,remount /dev/ram0 /" # # docmd "ls -la /" # # # # # Load the kernel modules if any # # for module in /lib/modules/`uname -r`/*.*o ; do # insmod $module # done # # # == # == i donno why /dev/hda1 needs to be rw here # == # # Mount the compact flash ( CF:/boot/rootfs.gz ) # ----------------------------------------------- docmd "mount -o rw /dev/hda1 /mnt/CF" # # no point in continuing if the rootfs is not found docmd "ls -la /mnt/CF/rootfs.img" # # # rootfs is 24MB # -------------- # - # - we need initrd to create the 24MB rootfs # - docmd "mount -o ro,loop /mnt/CF/rootfs.img /mnt/loop0" # # # view the rootfs # docmd "ls -la /mnt/loop0" # # # extra # docmd "df" # # # "man initrd" says to unmount everything before existing linuxrc # but we're still using/needing /mnt/hda/rootfs # # # unmount the compact flash # docmd "umount /mnt/CF" # # # leave /proc, since echo fails # docmd "umount /proc" # sync # # # --------------------- # /dev/ram is loaded -- linuxrc should pass control to /sbin/init by default # --------------------- # # docmd "#" docmd "# Done: /linuxrc ..." docmd "# start /linux.loop in lieu of /sbin/init since" docmd "# /bin, /dev, /etc, /sbin is a preformatted loop device " docmd "#" # # #ocmd "chroot /mnt/loop0 /linuxrc.loop" # # 0100 /dev/ram0 # 0700 /dev/loop0 # 0301 /dev/ram1 # # echo "0x700" > /proc/sys/kernel/real_root_dev # # # causes: # pivot_root: device or resource busy # docmd "pivot_root /mnt/loop0 /initrd " # docmd "chroot /mnt/loop0 /sbin/init 3" # echo "cd /mnt/loop0 && pivot_root . /initrd " cd /mnt/loop0 && pivot_root . /initrd # # # dumps you into /mnt/loop0 and does not execute /sbin/init # docmd "exec chroot . " # # # # - # - pivot_root is needed for chroot + init to work # - # # http://www.sdc.org/~leila/usb-dongle/usb-filesystem/linuxrc # #ocmd "cd /mnt/loop0 " #ocmd "/sbin/pivot_root . /initrd " #ocmd "exec /usr/bin/chroot . /sbin/init 3 " #ocmd "exec chroot . /sbin/init < dev/console 2>&1 " # # # # To manually see what's going on rootFS # -------------------------------------- # # docmd "chroot /mnt/loop0 /bin/bash" # docmd "chroot /mnt/loop0 /linuxrc.loop" # # # a shell ( including /linuxrc ) CANNOT call init --> causes error message: # "error opening/writing control channel /dev/initctl" # # # chroot /mnt/loop0 /sbin/init 1 # # # From man initrd # --------------- # Upon exiting /linuxrc, normal /sbin/init will be invoked # and /dev/ram0 will have been previously moved to /initrd # # except in this case, / cannot be mounted since /dev/loop0 # does not yet exist in the real rootFS, so we will use # linuxrc.loop instead # # # End of file