create_arm_debootstrap.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #/bin/sh
  2. ######################
  3. # Debootstrap #
  4. ######################
  5. show_usage() {
  6. cat <<EOF
  7. # NAME
  8. $(basename $0) -- Script to create a minimal deboostrap
  9. # OPTIONS
  10. -d debian release (wheezy, jessie) (default: wheezy)
  11. -a add packages
  12. EOF
  13. exit 1
  14. }
  15. distro=wheezy
  16. targetdir=/olinux/debootstrap
  17. name=olinux
  18. while getopts "a:d:n:" opt; do
  19. case $opt in
  20. d)
  21. distro=$OPTARG
  22. ;;
  23. a)
  24. packages=$OPTARG
  25. ;;
  26. n)
  27. name=$OPTARG
  28. ;;
  29. \?)
  30. show_usage
  31. ;;
  32. esac
  33. done
  34. rm -rf $targetdir && mkdir -p $targetdir
  35. # install packages for debootstap
  36. apt-get install --force-yes -y debootstrap dpkg-dev qemu binfmt-support qemu-user-static dpkg-cross
  37. # Debootstrap
  38. debootstrap --arch=armhf --foreign $distro $targetdir
  39. update-binfmts --disable
  40. mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  41. update-binfmts --enable
  42. cp /usr/bin/qemu-arm-static $targetdir/usr/bin/
  43. cp /etc/resolv.conf $targetdir/etc
  44. chroot $targetdir /debootstrap/debootstrap --second-stage
  45. # Configure debian apt repository
  46. cat <<EOT > $targetdir/etc/apt/sources.list
  47. deb http://ftp.fr.debian.org/debian $distro main contrib non-free
  48. EOT
  49. cat <<EOT > $targerdir/etc/apt/apt.conf.d/71-no-recommends
  50. APT::Install-Suggests "0";
  51. EOT
  52. chroot $targetdir apt-get update
  53. # Add ssh server and ntp client
  54. chroot $targetdir apt-get install -y --force-yes openssh-server ntp $packages
  55. # Use dhcp on boot
  56. cat <<EOT > $targetdir/etc/network/interfaces
  57. auto lo
  58. iface lo inet loopback
  59. allow-hotplug eth0
  60. iface eth0 inet dhcp
  61. EOT
  62. # Configure tty
  63. echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $targetdir/etc/inittab
  64. # add 'olimex' for root password
  65. sed -i -e 's/root:*/root:$6$20Vo8onH$rsNB42ksO1i84CzCTt8e90ludfzIFiIGygYeCNlHYPcDOwvAEPGQQaQsK.GYU2IiZNHG.e3tRFizLmD5lnaHH/' $targetdir/etc/shadow
  66. # add hostname
  67. echo $name > $targetdir/etc/hostname
  68. # Remove useless files
  69. chroot $targetdir apt-get clean
  70. rm $targetdir/etc/resolv.conf
  71. rm $targetdir/usr/bin/qemu-arm-static