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