create_arm_debootstrap.sh 2.2 KB

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