#!/bin/bash # # /linuxrc: init script to load initrd kernel modules # # # 02-Nov-04 amo Create a minimal initrd.gz to load the rootfs.gz as / # # # Define the path # export PATH="/sbin:/bin:/usr/sbin:/usr/bin" # # function docmd { cmd="$1" # echo "" echo "$cmd" $cmd # stat=$? if [ $stat != 0 ]; then echo "" echo "ERROR: Failed: $cmd " echo "" # exit 1 fi # } # docmd # # # Remove for "chroot xxx /linuxrc" testing # ---------------------------------- mount -n proc /proc -t proc # # # Load the kernel modules if any # # for module in /lib/modules/`uname -r`/*.*o ; do # insmod $module # done # # # Mount the compact flash ( CF:/boot/rootfs.gz ) # ----------------------------------------------- docmd "mount /dev/hda1 /mnt/hda" # # # for debugging # # docmd "df" # docmd "ls -laR /dev /mnt" # # # Just mount the previously formatted rootfs # ------------------------------------------ # modprobe loop - easier to put loop into the kernel # docmd "insmod /lib/modules/2.4.27-ow1/kernel/drivers/block/loop.o" # echo "Might want: losetup /dev/loop0 /mnt/hda/boot/rootfs" # docmd "mount -o rw,loop /mnt/hda/boot/rootfs /mnt/loop0" # docmd "df" # # # unmount the compact flash docmd "umount /dev/hda1" # # Now we're up and running echo "chroot /mnt/loop0 /bin/bash" # exit 1 # # # #xx # Use pivot_root instead of chroot #xx # -------------------------------- #xx echo 0x0100 > /proc/sys/kernel/real-root-dev #xx # # # mount -o defaults --ro -t ext3 /dev/root /sysroot # pivot_root /sysroot /sysroot/initrd # #xx docmd "mount -n -o remount,ro /dev/ram1 /mnt/rootfs" #xx # #xx docmd "pivot_root /mnt/rootfs /mnt/rootfs/initrd" # # # # we're up # ------------ # docmd "chroot /mnt/rootfs /sbin/init 1 " # docmd "chroot /mnt/rootfs /bin/bash " # # # docmd "mount -o remount,rw /dev/ram1 /" # # # # Use dd to create a rootfs ( / ) in memory # ------------------------- # #xx docmd "dd if=/mnt/hda/boot/rootfs of=/dev/ram0 bs=1k" #xx # #xx # unmount the compact flash #xx docmd "umount /dev/hda1" #xx # #xx # #xx # Run linux in /dev/ram #xx # --------------------- #xx # #xx docmd "mount -o rw,remount /dev/ram0 /" #xx # #xx # #xx # Execute from ramdisk ( memory ) #xx # -------------------- #xx # #xx docmd "chroot /" # # # End of file