#!/bin/bash # # /linuxrc.usb.usb: 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 # 20-Nov-04 amo Split off common mount and checking to linuxrc.common.sh # 23-Nov-04 amo Use CFRW to debug mount CF as rw vs ro options -> linuxrc -> /etc/fstab # 26-Mar-05 amo Modified for CF ( hda1 ) or USB ( sda1 ) # 27-Mar-05 amo "root=/dev/ram0 1" has no single user, root=/dev/loop0 is readonly # 29-Mar-05 amo use /dev/sda2 ( usb or cf ) to uncompress rootfs.gz into and chroot into it # 02-Apr-05 amo Explicity set PATH and remount / # 03-Apr-05 amo Fixed localtime w/ hwclock # # # # Include the common functions and definitions # -------------------------------------------- # define docmd(), mount_proc() source /LinuxRC/linuxrc.common.sh # set | grep ^PATH # # export PATH=/sbin:/usr/sbin:/bin:/usr/bin # # InitLevel=3 # if [ "$1" = "1" ]; then InitLevel=1 fi # # # Flush and reset first # # CF #mount /dev/hda1 # # USB #mount /dev/sda1 # #mount /dev/ram0 #mount /proc # # docmd "#" docmd "# Executing /linurc" docmd "#" # # # leave a " " in front of mount, to avoid the premature output of an empty /proc/mounts # ----------------------------- # # # Check /proc # =========== # # mount_proc # # echo "mount.proc.sh" # mount -n -o rw,remount / # mount -t proc proc /proc # # # Make / writable ( need "-n" for /etc/mtab ) # --------------- docmd " mount -n -o rw -t ext2 /dev/ram0 /" # # # Remount it again so that it shows up in the now writable /etc/mtab # ---------------- docmd " mount -o rw,remount -t ext2 /dev/ram0 /" # # docmd "ls -la /" # # docmd " touch /Read-Write-Test.txt " # if [ ! -f "/Read-Write-Test.txt" ]; then # docmd "# FATAL ERROR /dev/ram0 is NOT read write.." # exit 1 # else # rm -f "/Read-Write-Test.txt" # fi # docmd " ls -la /mnt " # # # Load the kernel modules if any # # for module in /lib/modules/`uname -r`/*.*o ; do # insmod $module # done # docmd " /etc/rc.d/rc.usb-stick start " # # == # == i donno why /dev/hda1 needs to be rw here # == # # Mount the compact flash ( CF:/boot/rootfs.gz ) # ----------------------------------------------- # == # == pivot_root/chroot works if both /mnt/CF and *.img are "ro" # == # ----------------------------------------------- # - with "ro", system boots into RootFS with "ro" but is in fact ro # ----------------------------------------------- # CFRW="ro" #ocmd " mount -o $CFRW /dev/hda1 /mnt/CF" docmd " mount -o $CFRW /dev/sda1 /mnt/USB" # # # ERREXIT="exit-on-critical-error" # # no point in continuing if the rootfs is not found docmd "ls -la /mnt/USB/boot/rootfs.tgz" # # # # rootfs is 32MB # -------------- # - # - we need initrd to create the 32MB rootfs # - pivot_root expects a directory name # - when we pivot_root and chroot into /mnt/loop0, we want to rw into /dev/tty, /var/* # - # # # This make the rootfs "ro" # cmd " mount -o $CFRW,loop /mnt/USB/boot/rootfs.img /mnt/loop0" # # # # # # Create some working area # # ------------------------- umount /mnt/RootFS umount /mnt/sda2 docmd "mkfs.jfs -q /dev/sda2 " docmd "mount /dev/sda2 /mnt/sda2" # # # # # # # Uncompress the rootFS /dev/loop to run in memory # # ------------------------------------------------ # # /root/losetup.sh.txt # docmd "dd if=/dev/zero of=/mnt/sda2/LoopFile bs=1024k count=32" # #ocmd "losetup /dev/loop0 /mnt/LoopFile" # docmd "mkfs.jfs -q /mnt/sda2/LoopFile" # mkdir /mnt/RootFS docmd "mount -o loop,rw /mnt/sda2/LoopFile /mnt/RootFS" # # docmd "#" docmd "# Setting system time from the hardware clock (localtime)." docmd "#" docmd "/sbin/hwclock --localtime --hctosys" docmd "date" docmd "#" # # docmd "cd /mnt/RootFS && tar zxfp /mnt/USB/boot/rootfs.tgz " # sync # # # losetup -d /dev/loop0 # # umount /mnt/sda2/LoopFile umount /mnt/sda2 umount /mnt/sda1 # # # not criticl anymore ERREXIT="" # # # view the rootfs # docmd "ls -la /mnt/RootFS" # # final sanity check docmd "df" # docmd "cat /proc/mounts" # # sync # # # --------------------- # /dev/ram is loaded -- linuxrc should pass control to /sbin/init by default # --------------------- # # # docmd "#" # docmd "# Done: /linuxrc ..." # #ocmd "# start /linux.loop in lieu of /sbin/init since" # #ocmd "# /bin, /dev, /etc, /sbin is a preformatted loop device " # docmd "#" # # # Tell the kernel, / is already mounted # -------------------------------------- # /dev/loop0 7,0 # /dev/loop1 7,1 # docmd "# /dev/loop0 == 0x700 == 1792" docmd "# /dev/loop1 == 0x701 == 1793" docmd "echo '0x700' > /proc/sys/kernel/real-root-dev" docmd "#" # # # # Attempt to Get rid of "pivot_root: Device or Resource is busy" # --------------------------------- # - "busy error" seems to be non-fatal when "mount ro" # - "busy error" exits if "mount rw" # # # # # pivot_root does not seem to be needed # # # docmd "cd /mnt/RootFS" # docmd "umount /proc" # docmd "pivot_root . /initrd" # docmd "#" # # # --------------------------------------------------- # use a variable to make sure chroot is done properly # --------------------------------------------------- MntRootFS="/mnt/RootFS" # docmd "cd $MntRootFS" # # # # Invoking chroot from inside linuxrc causes: # ------------------------------------------ # "error opening/writing control channel /dev/initctl" # # - use pivot-root to avoid the above error # # Continue with normal bootup # ============================ # echo "# " echo "exec chroot $MntRootFS /sbin/init $InitLevel" echo "#" # # # Upon exiting /linuxrc, normal /sbin/init is supposed to be executed # if [ "$1" = "" -o "$InitLevel" = "3" -o "$InitLevel" = "1" ]; then # exec chroot $MntRootFS /sbin/init $InitLevel # # &1 # /dev/console 2>&1 # else # # Interactive debugging, turn on the mouse # docmd "/etc/rc.d/rc.gpm start" docmd "#" # fi # # Creating RootFS worked # exit 0 # # # End of file