Tomato 1.28
[tomato.git] / release / src / router / busybox / examples / bootfloppy / mkrootfs.sh
blob5cdff21a0f5b730dfbf30edfb983438d57c620b7
1 #!/bin/bash
3 # mkrootfs.sh - creates a root file system
6 # TODO: need to add checks here to verify that busybox, uClibc and bzImage
7 # exist
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'
18 # don't-touch variables
19 BASE_DIR=`pwd`
22 while getopts 'b:u:s:t:Cm' opt
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' ;;
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
42 esac
43 done
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
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
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
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 CONFIG_PREFIX=$BASE_DIR/$TARGET_DIR install
80 cd $BASE_DIR
83 # make files in /dev
84 mkdir $TARGET_DIR/dev
85 ./mkdevs.sh $TARGET_DIR/dev
88 # make files in /etc
89 cp -a etc $TARGET_DIR
90 ln -s /proc/mounts $TARGET_DIR/etc/mtab
93 # other miscellaneous setup
94 mkdir $TARGET_DIR/initrd
95 mkdir $TARGET_DIR/proc
98 # Done. Maybe do cleanup.
99 if [ $CLEANUP -eq 1 ]
100 then
101 umount $TARGET_DIR
102 rmdir $TARGET_DIR
103 gzip -9 rootfs