mkrootfs.sh 2.3 KB

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