qi-emdebian

qi-emdebian-postsetup

11:76e07972f125
5 months ago Paul Boddie Added apt to the list of necessary (or at least very useful) packages.
     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 if [ `stat -c %U "$ROOTDIR"` != "root" ]; then
    47     cat 1>&2 <<EOF
    48 $PROGNAME: It appears that the root filesystem is not owned by root.
    49 
    50 This will probably produce a non-functioning system when copied to the target
    51 device. It is recommended that you re-run multistrap as a privileged user, but
    52 if you wish to continue with the current configuration, change the owner of the
    53 root filesystem to root and then try running this script again.
    54 EOF
    55     exit 1
    56 fi
    57 
    58 # Make a link to the busybox binary acting as a shell.
    59 
    60 if [ ! -e "$ROOTDIR/usr/lib/busybox" ]; then
    61     mkdir -p "$ROOTDIR/usr/lib/busybox"
    62     ln -s /bin/busybox "$ROOTDIR/usr/lib/busybox/sh"
    63 fi
    64 
    65 # The first boot involves a special configuration script.
    66 
    67 cp preinit preinit-config "$ROOTDIR/etc/"
    68 
    69 # Copy the kernel image and any modules.
    70 
    71 cp "$KERNEL" "$ROOTDIR/boot/uImage"
    72 
    73 if [ -e "$BUILD/lib/modules" ]; then
    74     if [ ! -e "$ROOTDIR/lib/modules" ]; then
    75         mkdir -p "$ROOTDIR/lib/modules"
    76     fi
    77     cp -R "$BUILD/lib/modules/"* "$ROOTDIR/lib/modules/"
    78     cp "$BUILD/etc/modules" "$ROOTDIR/etc/"
    79 fi
    80 
    81 # Copy configuration files such as fstab, hostname, interfaces, resolv.conf.
    82 
    83 cp -R "$BUILD/etc/"* "$ROOTDIR/etc/"
    84 
    85 # Also required for a "first boot" script:
    86 # /etc/resolv.conf
    87 
    88 # Make devices.
    89 
    90 mknod -m 0600 "$ROOTDIR/dev/console"  c 5 1
    91 mknod -m 0660 "$ROOTDIR/dev/full"     c 1 7
    92 mknod -m 0640 "$ROOTDIR/dev/kmem"     c 1 2
    93 mknod -m 0660 "$ROOTDIR/dev/loop0"    b 7 0
    94 mknod -m 0640 "$ROOTDIR/dev/mem"      c 1 1
    95 mknod -m 0666 "$ROOTDIR/dev/null"     c 1 3
    96 mknod -m 0640 "$ROOTDIR/dev/port"     c 1 4
    97 mknod -m 0666 "$ROOTDIR/dev/random"   c 1 8
    98 mknod -m 0660 "$ROOTDIR/dev/tty"      c 5 0
    99 mknod -m 0666 "$ROOTDIR/dev/urandom"  c 1 9
   100 mknod -m 0666 "$ROOTDIR/dev/zero"     c 1 5
   101 
   102 for N in `seq 0 5` ; do
   103     mknod -m 0660 "$ROOTDIR/dev/tty$N" c 4 $N
   104 done
   105 
   106 for N in `seq 0 15` ; do
   107     mknod -m 0660 "$ROOTDIR/dev/ram$N" b 1 $N
   108 done
   109 
   110 ln -s /dev/ram1 "$ROOTDIR/dev/ram"
   111 ln -s /proc/kcore "$ROOTDIR/dev/core"