1 #!/bin/sh 2 3 PROGNAME=`basename $0` 4 ROOTDIR=$1 5 KERNEL=$2 6 BUILD=$3 7 8 if [ ! "$1" ] || [ "$1" = '--help' ]; then 9 cat 1>&2 <<EOF 10 Usage: $PROGNAME <root filesystem path> <kernel image> <system files path> 11 12 Example: $PROGNAME rootfs openwrt-xburst-qi_lb60-uImage.bin configfiles 13 14 This program copies the given kernel image into the indicated root filesystem, 15 together with files from the given system files directory hierarchy. It also 16 copies two initial configuration files (preinit and preinit-config) from the 17 current working directory. 18 19 A root filesystem can be constructed using the multistrap tool as well as 20 other tools such as debootstrap. The preinit and preinit-config files are 21 intended to perform work on the target system to make the root filesystem 22 usable and bootable. 23 EOF 24 exit 1 25 fi 26 27 if [ ! "$KERNEL" ]; then 28 cat 1>&2 <<EOF 29 $PROGNAME: Need a path to a kernel image. 30 31 The image filename will be something like openwrt-xburst-qi_lb60-uImage.bin 32 EOF 33 exit 1 34 fi 35 36 if [ ! "$BUILD" ]; then 37 echo "$PROGNAME: Need a path to a filesystem containing kernel modules and configuration files." 1>&2 38 exit 1 39 fi 40 41 if [ ! -e preinit ] || [ ! -e preinit-config ]; then 42 echo "$PROGNAME: Need preinit and preinit-config files to deploy in the root filesystem." 1>&2 43 exit 1 44 fi 45 46 # Make a link to the busybox binary acting as a shell. 47 48 if [ ! -e "$ROOTDIR/usr/lib/busybox" ]; then 49 mkdir -p "$ROOTDIR/usr/lib/busybox" 50 ln -s /bin/busybox "$ROOTDIR/usr/lib/busybox/sh" 51 fi 52 53 # The first boot involves a special configuration script. 54 55 cp preinit preinit-config "$ROOTDIR/etc/" 56 57 # Copy the kernel image and any modules. 58 59 cp "$KERNEL" "$ROOTDIR/boot/uImage" 60 61 if [ -e "$BUILD/lib/modules" ]; then 62 if [ ! -e "$ROOTDIR/lib/modules" ]; then 63 mkdir -p "$ROOTDIR/lib/modules" 64 fi 65 cp -R "$BUILD/lib/modules/"* "$ROOTDIR/lib/modules/" 66 cp "$BUILD/etc/modules" "$ROOTDIR/etc/" 67 fi 68 69 # Copy configuration files such as fstab, hostname, interfaces, resolv.conf. 70 71 cp -R "$BUILD/etc/"* "$ROOTDIR/etc/" 72 73 # Also required for a "first boot" script: 74 # /etc/resolv.conf 75 76 # Make devices. 77 78 mknod -m 0600 "$ROOTDIR/dev/console" c 5 1 79 mknod -m 0660 "$ROOTDIR/dev/full" c 1 7 80 mknod -m 0640 "$ROOTDIR/dev/kmem" c 1 2 81 mknod -m 0660 "$ROOTDIR/dev/loop0" b 7 0 82 mknod -m 0640 "$ROOTDIR/dev/mem" c 1 1 83 mknod -m 0666 "$ROOTDIR/dev/null" c 1 3 84 mknod -m 0640 "$ROOTDIR/dev/port" c 1 4 85 mknod -m 0666 "$ROOTDIR/dev/random" c 1 8 86 mknod -m 0660 "$ROOTDIR/dev/tty" c 5 0 87 mknod -m 0666 "$ROOTDIR/dev/urandom" c 1 9 88 mknod -m 0666 "$ROOTDIR/dev/zero" c 1 5 89 90 for N in `seq 0 5` ; do 91 mknod -m 0660 "$ROOTDIR/dev/tty$N" c 4 $N 92 done 93 94 for N in `seq 0 15` ; do 95 mknod -m 0660 "$ROOTDIR/dev/ram$N" b 1 $N 96 done 97 98 ln -s /dev/ram1 "$ROOTDIR/dev/ram" 99 ln -s /proc/kcore "$ROOTDIR/dev/core"