create_arm_debootstrap.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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-Suggests "0";
  53. EOT
  54. chroot $targetdir apt-get update
  55. # Add ssh server and ntp client
  56. chroot $targetdir apt-get install -y --force-yes openssh-server ntp $packages
  57. # Use dhcp on boot
  58. cat <<EOT > $targetdir/etc/network/interfaces
  59. auto lo
  60. iface lo inet loopback
  61. allow-hotplug eth0
  62. iface eth0 inet dhcp
  63. EOT
  64. # Configure tty
  65. echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $targetdir/etc/inittab
  66. # add 'olinux' for root password
  67. sed -i -e 's/root:*/root:$6$20Vo8onH$rsNB42ksO1i84CzCTt8e90ludfzIFiIGygYeCNlHYPcDOwvAEPGQQaQsK.GYU2IiZNHG.e3tRFizLmD5lnaHH/' $targetdir/etc/shadow
  68. # add hostname
  69. echo $name > $targetdir/etc/hostname
  70. # Remove useless files
  71. chroot $targetdir apt-get clean
  72. rm $targetdir/etc/resolv.conf
  73. rm $targetdir/usr/bin/qemu-arm-static