create_arm_debootstrap.sh 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #!/bin/sh
  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. -b olinux board (see config_board.sh) (default: a20lime)
  13. -a add packages to deboostrap
  14. -n hostname (default: olinux)
  15. -t target directory for debootstrap (default: /olinux/debootstrap)
  16. -i install sunxi kernel files; you should have build them before.
  17. -y install yunohost (doesn't work with cross debootstrap)
  18. -c cross debootstrap
  19. -p use aptcacher proxy
  20. EOF
  21. exit 1
  22. }
  23. DEBIAN_RELEASE=wheezy
  24. TARGET_DIR=/olinux/debootstrap
  25. DEB_HOSTNAME=olinux
  26. REP=$(dirname $0)
  27. while getopts ":a:b:d:n:t:i:ycp" opt; do
  28. case $opt in
  29. d)
  30. DEBIAN_RELEASE=$OPTARG
  31. ;;
  32. b)
  33. BOARD=$OPTARG
  34. ;;
  35. a)
  36. PACKAGES=$OPTARG
  37. ;;
  38. n)
  39. DEB_HOSTNAME=$OPTARG
  40. ;;
  41. t)
  42. TARGET_DIR=$OPTARG
  43. ;;
  44. i)
  45. INSTALL_KERNEL=$OPTARG
  46. ;;
  47. y)
  48. INSTALL_YUNOHOST=yes
  49. ;;
  50. c)
  51. CROSS=yes
  52. ;;
  53. p)
  54. APTCACHER=yes
  55. ;;
  56. \?)
  57. show_usage
  58. ;;
  59. esac
  60. done
  61. . ${REP}/config_board.sh
  62. rm -rf $TARGET_DIR && mkdir -p $TARGET_DIR
  63. chroot_deb (){
  64. LC_ALL=C LANGUAGE=C LANG=C chroot $1 /bin/bash -c "$2"
  65. }
  66. if [ ${CROSS} ] ; then
  67. # Debootstrap
  68. mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
  69. bash ${REP}/script/binfmt-misc-arm.sh unregister
  70. bash ${REP}/script/binfmt-misc-arm.sh
  71. debootstrap --arch=armhf --foreign $DEBIAN_RELEASE $TARGET_DIR
  72. cp /usr/bin/qemu-arm-static $TARGET_DIR/usr/bin/
  73. cp /etc/resolv.conf $TARGET_DIR/etc
  74. chroot_deb $TARGET_DIR '/debootstrap/debootstrap --second-stage'
  75. elif [ ${APTCACHER} ] ; then
  76. debootstrap $DEBIAN_RELEASE $TARGET_DIR http://localhost:3142/ftp.fr.debian.org/debian/
  77. else
  78. debootstrap $DEBIAN_RELEASE $TARGET_DIR
  79. fi
  80. # mount proc, sys and dev
  81. mount -t proc chproc $TARGET_DIR/proc
  82. mount -t sysfs chsys $TARGET_DIR/sys
  83. mount -t devtmpfs chdev $TARGET_DIR/dev || mount --bind /dev $TARGET_DIR/dev
  84. mount -t devpts chpts $TARGET_DIR/dev/pts || mount --bind /dev/pts $TARGET_DIR/dev/pts
  85. # Configure debian apt repository
  86. cat <<EOT > $TARGET_DIR/etc/apt/sources.list
  87. deb http://ftp.fr.debian.org/debian $DEBIAN_RELEASE main contrib non-free
  88. deb http://security.debian.org/ $DEBIAN_RELEASE/updates main contrib non-free
  89. EOT
  90. cat <<EOT > $TARGET_DIR/etc/apt/apt.conf.d/71-no-recommends
  91. APT::Install-Suggests "0";
  92. EOT
  93. if [ ${APTCACHER} ] ; then
  94. cat <<EOT > $TARGET_DIR/etc/apt/apt.conf.d/01proxy
  95. Acquire::http::Proxy "http://localhost:3142";
  96. EOT
  97. fi
  98. chroot_deb $TARGET_DIR 'apt-get update'
  99. # Add ssh server and ntp client
  100. chroot_deb $TARGET_DIR "apt-get install -y --force-yes openssh-server ntp parted locales $PACKAGES"
  101. # Use dhcp on boot
  102. cat <<EOT > $TARGET_DIR/etc/network/interfaces
  103. auto lo
  104. iface lo inet loopback
  105. allow-hotplug eth0
  106. iface eth0 inet dhcp
  107. EOT
  108. # Debootstrap optimisations from igorpecovnik
  109. # change default I/O scheduler, noop for flash media, deadline for SSD, cfq for mechanical drive
  110. cat <<EOT >> $TARGET_DIR/etc/sysfs.conf
  111. block/mmcblk0/queue/scheduler = noop
  112. #block/sda/queue/scheduler = cfq
  113. EOT
  114. # flash media tunning
  115. if [ -f "$TARGET_DIR/etc/default/tmpfs" ]; then
  116. sed -e 's/#RAMTMP=no/RAMTMP=yes/g' -i $TARGET_DIR/etc/default/tmpfs
  117. sed -e 's/#RUN_SIZE=10%/RUN_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs
  118. sed -e 's/#LOCK_SIZE=/LOCK_SIZE=/g' -i $TARGET_DIR/etc/default/tmpfs
  119. sed -e 's/#SHM_SIZE=/SHM_SIZE=128M/g' -i $TARGET_DIR/etc/default/tmpfs
  120. sed -e 's/#TMP_SIZE=/TMP_SIZE=1G/g' -i $TARGET_DIR/etc/default/tmpfs
  121. fi
  122. # Generate locales
  123. sed -i "s/^# fr_FR.UTF-8 UTF-8/fr_FR.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen
  124. sed -i "s/^# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/" $TARGET_DIR/etc/locale.gen
  125. chroot_deb $TARGET_DIR "locale-gen en_US.UTF-8"
  126. # Update timezone
  127. echo 'Europe/Paris' > $TARGET_DIR/etc/timezone
  128. chroot_deb $TARGET_DIR "dpkg-reconfigure -f noninteractive tzdata"
  129. # Configure tty
  130. echo T0:2345:respawn:/sbin/getty -L ttyS0 115200 vt100 >> $TARGET_DIR/etc/inittab
  131. # Good right on some directories
  132. chroot_deb $TARGET_DIR 'chmod 1777 /tmp/'
  133. chroot_deb $TARGET_DIR 'chgrp mail /var/mail/'
  134. chroot_deb $TARGET_DIR 'chmod g+w /var/mail/'
  135. chroot_deb $TARGET_DIR 'chmod g+s /var/mail/'
  136. # Set hostname
  137. echo $DEB_HOSTNAME > $TARGET_DIR/etc/hostname
  138. # Add firstrun and secondrun init script
  139. install -m 755 -o root -g root ${REP}/script/secondrun $TARGET_DIR/etc/init.d/
  140. install -m 755 -o root -g root ${REP}/script/firstrun $TARGET_DIR/etc/init.d/
  141. chroot_deb $TARGET_DIR "insserv firstrun >> /dev/null"
  142. if [ $INSTALL_KERNEL ] ; then
  143. cp ${INSTALL_KERNEL}/*.deb $TARGET_DIR/tmp/
  144. chroot_deb $TARGET_DIR 'dpkg -i /tmp/*.deb'
  145. rm $TARGET_DIR/tmp/*
  146. cp ${INSTALL_KERNEL}/boot.scr $TARGET_DIR/boot/
  147. chroot_deb $TARGET_DIR "ln -s /boot/dtb/$DTB /boot/board.dtb"
  148. fi
  149. if [ $INSTALL_YUNOHOST ] ; then
  150. chroot_deb $TARGET_DIR "apt-get install -y --force-yes git"
  151. chroot_deb $TARGET_DIR "git clone https://github.com/YunoHost/install_script /tmp/install_script"
  152. chroot_deb $TARGET_DIR "cd /tmp/install_script && ./autoinstall_yunohostv2 || exit 0"
  153. fi
  154. # Add 'olinux' for root password and force to change it at first login
  155. chroot_deb $TARGET_DIR '(echo olinux;echo olinux;) | passwd root'
  156. chroot_deb $TARGET_DIR 'chage -d 0 root'
  157. # Remove useless files
  158. chroot_deb $TARGET_DIR 'apt-get clean'
  159. rm $TARGET_DIR/etc/resolv.conf
  160. if [ ${CROSS} ] ; then
  161. rm $TARGET_DIR/usr/bin/qemu-arm-static
  162. fi
  163. if [ ${APTCACHER} ] ; then
  164. rm $TARGET_DIR/etc/apt/apt.conf.d/01proxy
  165. fi
  166. # Umount proc, sys, and dev
  167. umount -l $TARGET_DIR/dev/pts
  168. umount -l $TARGET_DIR/dev
  169. umount -l $TARGET_DIR/proc
  170. umount -l $TARGET_DIR/sys