create_arm_debootstrap.sh 2.0 KB

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