create_arm_debootstrap.sh 2.1 KB

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