[821] | 1 | #!/bin/bash
|
---|
| 2 | #
|
---|
| 3 | # mkrootfs.sh - creates a root file system
|
---|
| 4 | #
|
---|
| 5 |
|
---|
| 6 | # TODO: need to add checks here to verify that busybox, uClibc and bzImage
|
---|
| 7 | # exist
|
---|
| 8 |
|
---|
| 9 |
|
---|
| 10 | # command-line settable variables
|
---|
| 11 | BUSYBOX_DIR=..
|
---|
| 12 | UCLIBC_DIR=../../uClibc
|
---|
| 13 | TARGET_DIR=./loop
|
---|
| 14 | FSSIZE=4000
|
---|
| 15 | CLEANUP=1
|
---|
| 16 | MKFS='mkfs.ext2 -F'
|
---|
| 17 |
|
---|
| 18 | # don't-touch variables
|
---|
| 19 | BASE_DIR=`pwd`
|
---|
| 20 |
|
---|
| 21 |
|
---|
| 22 | while getopts 'b:u:s:t:Cm' opt
|
---|
| 23 | do
|
---|
| 24 | case $opt in
|
---|
| 25 | b) BUSYBOX_DIR=$OPTARG ;;
|
---|
| 26 | u) UCLIBC_DIR=$OPTARG ;;
|
---|
| 27 | t) TARGET_DIR=$OPTARG ;;
|
---|
| 28 | s) FSSIZE=$OPTARG ;;
|
---|
| 29 | C) CLEANUP=0 ;;
|
---|
| 30 | m) MKFS='mkfs.minix' ;;
|
---|
| 31 | *)
|
---|
| 32 | echo "usage: `basename $0` [-bu]"
|
---|
| 33 | echo " -b DIR path to busybox direcory (default ..)"
|
---|
| 34 | echo " -u DIR path to uClibc direcory (default ../../uClibc)"
|
---|
| 35 | echo " -t DIR path to target direcory (default ./loop)"
|
---|
| 36 | echo " -s SIZE size of root filesystem in Kbytes (default 4000)"
|
---|
| 37 | echo " -C don't perform cleanup (umount target dir, gzip rootfs, etc.)"
|
---|
| 38 | echo " (this allows you to 'chroot loop/ /bin/sh' to test it)"
|
---|
| 39 | echo " -m use minix filesystem (default is ext2)"
|
---|
| 40 | exit 1
|
---|
| 41 | ;;
|
---|
| 42 | esac
|
---|
| 43 | done
|
---|
| 44 |
|
---|
| 45 |
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | # clean up from any previous work
|
---|
| 49 | mount | grep -q loop
|
---|
| 50 | [ $? -eq 0 ] && umount $TARGET_DIR
|
---|
| 51 | [ -d $TARGET_DIR ] && rm -rf $TARGET_DIR/
|
---|
| 52 | [ -f rootfs ] && rm -f rootfs
|
---|
| 53 | [ -f rootfs.gz ] && rm -f rootfs.gz
|
---|
| 54 |
|
---|
| 55 |
|
---|
| 56 | # prepare root file system and mount as loopback
|
---|
| 57 | dd if=/dev/zero of=rootfs bs=1k count=$FSSIZE
|
---|
| 58 | $MKFS -i 2000 rootfs
|
---|
| 59 | mkdir $TARGET_DIR
|
---|
| 60 | mount -o loop,exec rootfs $TARGET_DIR # must be root
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 | # install uClibc
|
---|
| 64 | mkdir -p $TARGET_DIR/lib
|
---|
| 65 | cd $UCLIBC_DIR
|
---|
| 66 | make INSTALL_DIR=
|
---|
| 67 | cp -a libc.so* $BASE_DIR/$TARGET_DIR/lib
|
---|
| 68 | cp -a uClibc*.so $BASE_DIR/$TARGET_DIR/lib
|
---|
| 69 | cp -a ld.so-1/d-link/ld-linux-uclibc.so* $BASE_DIR/$TARGET_DIR/lib
|
---|
| 70 | cp -a ld.so-1/libdl/libdl.so* $BASE_DIR/$TARGET_DIR/lib
|
---|
| 71 | cp -a crypt/libcrypt.so* $BASE_DIR/$TARGET_DIR/lib
|
---|
| 72 | cd $BASE_DIR
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | # install busybox and components
|
---|
| 76 | cd $BUSYBOX_DIR
|
---|
| 77 | make distclean
|
---|
| 78 | make CC=$BASE_DIR/$UCLIBC_DIR/extra/gcc-uClibc/i386-uclibc-gcc
|
---|
| 79 | make PREFIX=$BASE_DIR/$TARGET_DIR install
|
---|
| 80 | cd $BASE_DIR
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | # make files in /dev
|
---|
| 84 | mkdir $TARGET_DIR/dev
|
---|
| 85 | ./mkdevs.sh $TARGET_DIR/dev
|
---|
| 86 |
|
---|
| 87 |
|
---|
| 88 | # make files in /etc
|
---|
| 89 | cp -a etc $TARGET_DIR
|
---|
| 90 | ln -s /proc/mounts $TARGET_DIR/etc/mtab
|
---|
| 91 |
|
---|
| 92 |
|
---|
| 93 | # other miscellaneous setup
|
---|
| 94 | mkdir $TARGET_DIR/initrd
|
---|
| 95 | mkdir $TARGET_DIR/proc
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | # Done. Maybe do cleanup.
|
---|
| 99 | if [ $CLEANUP -eq 1 ]
|
---|
| 100 | then
|
---|
| 101 | umount $TARGET_DIR
|
---|
| 102 | rmdir $TARGET_DIR
|
---|
| 103 | gzip -9 rootfs
|
---|
| 104 | fi
|
---|
| 105 |
|
---|