From 55f11ffe73e1a02fbfc8d156ff06ca3922c1ed98 Mon Sep 17 00:00:00 2001 From: Jose V Beneyto Date: Wed, 4 Jul 2012 06:44:07 +0000 Subject: [PATCH] Improvements to use busybox --install to create links dinamically --- Makefile | 6 ++-- busybox-1.19.4.config | 4 +-- filesystem/rc | 81 +++++++++++++++++++++++++++++++++++++------ work/initramfs.lst | 49 +++++++------------------- 4 files changed, 89 insertions(+), 51 deletions(-) diff --git a/Makefile b/Makefile index 62eba8c..82c75e9 100644 --- a/Makefile +++ b/Makefile @@ -113,11 +113,13 @@ $(WORK)/initramfs.cpio.gz-$(KERNEL_VERSION): check-root busybox dialog $(TOPDIR) install -v -m 0755 $(TOPDIR)/filesystem/{setup,crux} $(WORK)/mnt/usr/bin /sbin/ldconfig -r $(WORK)/mnt cd $(WORK)/mnt && \ - $(WORK)/gen_init_cpio $(WORK)/initramfs.lst | cpio -id && \ + sed -e "s/#KERNEL_VERSION#/$(KERNEL_VERSION)/g; s/#BUSYBOX_VERSION#/$(BUSYBOX_VERSION)/g" \ + $(WORK)/initramfs.lst > $(WORK)/initramfs.lst-sed && \ + $(WORK)/gen_init_cpio $(WORK)/initramfs.lst-sed | cpio -id && \ find * | cpio -H newc -o > $(WORK)/initramfs.cpio && \ gzip -v9 $(WORK)/initramfs.cpio mv $(WORK)/initramfs.cpio.gz{,-$(KERNEL_VERSION)} - #rm -rf $(WORK)/mnt + rm -rf $(WORK)/mnt initramfs: $(WORK)/initramfs.cpio.gz-$(KERNEL_VERSION) diff --git a/busybox-1.19.4.config b/busybox-1.19.4.config index a9de529..2f12add 100644 --- a/busybox-1.19.4.config +++ b/busybox-1.19.4.config @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Busybox version: 1.19.4 -# Tue Mar 6 12:35:21 2012 +# Mon Jul 2 21:32:06 2012 # CONFIG_HAVE_DOT_CONFIG=y @@ -23,7 +23,7 @@ CONFIG_FEATURE_BUFFERS_USE_MALLOC=y CONFIG_SHOW_USAGE=y CONFIG_FEATURE_VERBOSE_USAGE=y # CONFIG_FEATURE_COMPRESS_USAGE is not set -# CONFIG_FEATURE_INSTALLER is not set +CONFIG_FEATURE_INSTALLER=y # CONFIG_INSTALL_NO_USR is not set # CONFIG_LOCALE_SUPPORT is not set # CONFIG_UNICODE_SUPPORT is not set diff --git a/filesystem/rc b/filesystem/rc index 8fd3474..693ec70 100755 --- a/filesystem/rc +++ b/filesystem/rc @@ -95,6 +95,8 @@ find_and_mount_media() { fi } +/bin/busybox --install -s /bin + # # main script # @@ -105,10 +107,15 @@ echo "" exec >/dev/console &1 -echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting filesystems... " -mount -a && \ -mount -o remount,rw / -checkReturn +echo -e -n " ${BOLD}${BLUE}*${NORM} Mounting " +echo -e -n "${BOLD}${GREEN}/proc${NORM}" +mount -t proc proc /proc + +PRINTK="`cat /proc/sys/kernel/printk`" +echo "0" > /proc/sys/kernel/printk + +echo -e ", ${BOLD}${GREEN}/sys${NORM}." +mount -t sysfs sysfs /sys echo -e -n " ${BOLD}${BLUE}*${NORM} Populating /dev via mdev... " mdev -s @@ -141,11 +148,65 @@ echo -e -n " ${BOLD}${BLUE}*${NORM} Saving boot messages... " dmesg > /var/log/boot checkReturn -echo -e " ${BOLD}${BLUE}*${NORM} Trying to find and mount the media installer..." -find_and_mount_media - -echo -echo "The system is coming up. Please wait." -echo +grep -q "devicetimeout=*" /proc/cmdline +if [ $? -eq 0 ] +then + for opt in `cat /proc/cmdline` + do + echo "$opt" | grep -q "devicetimeout=" + if [ $? -eq 0 ] + then + DEVTIMEOUT=`echo $opt | cut -d'=' -f2` + fi + done +else + DEVTIMEOUT=10 +fi +echo -e " ${BOLD}${BLUE}*${NORM} Waiting $DEVTIMEOUT seconds for devices to settle..." +sleep $DEVTIMEOUT + +# if root=/dev/XXX was specified on the command line, use that as the new root +# instead of searching for the media and using it. if it fails, fall back to the media +grep -q "root=/dev/*" /proc/cmdline +if [ $? -eq 0 ] +then + for opt in `cat /proc/cmdline` + do + echo "$opt" | grep -q "root=" + if [ $? -eq 0 ] + then + ROOTDEV=`echo $opt | cut -d'=' -f2` + fi + done + mkdir -p /newroot + # check the specified root device to see if it has an init + mount $ROOTDEV /newroot + if [ $? -ne 0 ] + then + echo -e " ${BOLD}${RED}*${NORM} Unable to mount the specified root device! Falling back to the live media." + find_and_mount_media + else + if [ -x /newroot/sbin/init ] + then + echo -e " ${BOLD}${BLUE}*${NORM} Mounted root device $ROOTDEV." + else + echo -e " ${BOLD}${RED}*${NORM} The specified root device ($ROOTDEV) does not appear to be usable! Falling back to the live media." + umount /newroot + find_and_mount_media + fi + fi +else + find_and_mount_media +fi + +echo -e "${BOLD}${BLUE}*${NORM} Switching root.\n" +echo "$PRINTK" > /proc/sys/kernel/printk +echo > /proc/sys/kernel/hotplug +umount /sys +umount /proc +exec /bin/switch_root /newroot /sbin/init + +echo "Something's broken, here's a shell." +exec /bin/sh # End of file diff --git a/work/initramfs.lst b/work/initramfs.lst index 7db1494..e8aeaca 100644 --- a/work/initramfs.lst +++ b/work/initramfs.lst @@ -1,40 +1,15 @@ -dir / 755 0 0 - -nod /dev/console 664 0 0 c 5 1 - +# base directories/device nodes +dir /proc 755 0 0 +dir /sys 755 0 0 +dir /lib 755 0 0 +dir /dev 755 0 0 +nod /dev/console 640 0 0 c 5 1 nod /dev/null 664 0 0 c 1 3 -nod /dev/tty 664 0 0 c 5 0 - -nod /dev/tty0 644 0 0 c 4 0 -nod /dev/tty1 644 0 0 c 4 1 -nod /dev/tty2 644 0 0 c 4 2 -nod /dev/tty3 644 0 0 c 4 3 -nod /dev/tty4 644 0 0 c 4 4 -nod /dev/tty5 644 0 0 c 4 5 -nod /dev/tty6 644 0 0 c 4 6 -nod /dev/tty7 644 0 0 c 4 7 - -nod /dev/rd/0 664 0 0 b 1 0 - -nod /dev/ram0 664 0 0 b 1 0 - -nod /dev/hda0 644 0 0 b 3 0 -nod /dev/hda1 644 0 0 b 3 1 - -nod /dev/mmcblk0 664 0 0 b 179 0 - -nod /dev/mmcblk0p0 644 0 0 b 179 0 -nod /dev/mmcblk0p1 644 0 0 b 179 1 -nod /dev/mmcblk0p2 644 0 0 b 179 2 -nod /dev/mmcblk0p3 644 0 0 b 179 3 - -nod /dev/mtd0 644 0 0 c 90 0 -nod /dev/mtd1 644 0 0 c 90 1 -nod /dev/mtd2 644 0 0 c 90 2 -nod /dev/mtd3 644 0 0 c 90 3 +# init itself +file /init init 755 0 0 -nod /dev/mtdblock0 644 0 0 c 31 0 -nod /dev/mtdblock1 644 0 0 c 31 1 -nod /dev/mtdblock2 644 0 0 c 31 2 -nod /dev/mtdblock3 644 0 0 c 31 3 +# busybox and links +dir /bin 755 0 0 +file /bin/busybox ../busybox-#BUSYBOX_VERSION#/busybox 4755 0 0 +slink /bin/sh busybox 777 0 0 -- 2.26.2