summaryrefslogtreecommitdiff
path: root/1_makerootfs.sh
blob: 94157c8427ecdec88c8ddeccf42903bf6e028279 (plain)
  1. #!/bin/sh
  2. set -e
  3. . ./common-settings || exit 1
  4. . ./common-functions || exit 1
  5. mkdir "$targettemp"
  6. case "$debootstrap" in
  7. debootstrap)
  8. debootstrap \
  9. --include=$debootstrap_includes \
  10. --exclude=$debootstrap_excludes \
  11. "$suite" "$targettemp" "$aptsource_base_host"
  12. ;;
  13. cdebootstrap)
  14. cdebootstrap \
  15. --flavour=minimal \
  16. "$suite" "$targettemp" "$aptsource_base_cdebootstrap"
  17. ;;
  18. *)
  19. echo "ERROR: unknown debootstrap binary defined: \"$debootstrap\"" >&2
  20. exit 1
  21. esac
  22. # Tweak configuration files
  23. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$rootdev_target\t/\t$ROOTFS\tro\t0\t1" "none\t/proc\tproc\tdefaults\t0\t0"
  24. mkdir -p "$targettemp/etc/network/"
  25. preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto lo"
  26. preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface lo inet loopback"
  27. if [ -n "$DHCPCLIENT" ]; then
  28. preserveandaddlines "$targettemp/etc/network/interfaces" orig 3 "auto eth0"
  29. preserveandaddlines "$targettemp/etc/network/interfaces" orig 2 "iface eth0 inet dhcp"
  30. # TODO: Write function to apply multiline entry for static ip
  31. #elif [ -n "$hostdefaultip" ]; then
  32. # enableoraddlines "$targettemp/etc/network/interfaces" 2 "iface eth0 inet static"
  33. fi
  34. preserveandaddlines "$targettemp/etc/hosts" orig 1 "127.0.0.1 localhost"
  35. if [ -n "$hostdefaultip" ]; then
  36. preserveandaddlines "$targettemp/etc/hosts" orig 1 "$hostdefaultip $hostname.$domainname $hostname"
  37. fi
  38. if [ -n "$hostname" ] && [ -n "$domainname" ]; then
  39. preserveandaddlines "$targettemp/etc/hostname" orig 1 "$hostname.$domainname"
  40. fi
  41. if [ ! -d "$targettemp/etc/resolv.conf" ]; then
  42. if [ -n "$dns_server" ]; then
  43. preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "nameserver $dns_server"
  44. fi
  45. if [ -n "$domainname" ]; then
  46. preserveandaddlines "$targettemp/etc/resolv.conf" orig 2 "search $domainname"
  47. fi
  48. fi
  49. for aptsource in $aptsources; do
  50. eval uri=\"'$'aptsource_${aptsource}_host\"
  51. eval components=\"'$'aptsource_${aptsource}_components\"
  52. preserveandaddlines "$targettemp/etc/apt/sources.list" orig 2 "deb $uri $suite ${components:-main}"
  53. done
  54. if [ -n "$pubdev_target" ] && [ -n "$pubfs" ]; then
  55. mkdir -p "$targettemp/pub"
  56. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$pubdev_target\t/pub\t$pubfs\tdefaults,noauto,ro\t0\t0"
  57. fi
  58. rm -rf "$targettemp/var/log/ksymoops"
  59. ln -f -s /proc/mounts "$targettemp/etc/mtab"
  60. preserveandaddlines "$targettemp/etc/modules" orig 1 $modules_load
  61. if [ -n "$loghost" ]; then
  62. preserveolderfile "$targettemp/etc/syslog.conf" orig
  63. echo "*.* @$loghost" > "$targettemp/etc/syslog.conf"
  64. fi
  65. # Install/remove additional packages
  66. export DEBIAN_FRONTEND="noninteractive"
  67. case "$debootstrap" in
  68. debootstrap)
  69. ;;
  70. cdebootstrap)
  71. ./chroot.sh temp apt-get update
  72. case "$suite" in
  73. etch|sid)
  74. ./chroot.sh temp apt-get -y --allow-unauthenticated install aptitude
  75. ;;
  76. *)
  77. ./chroot.sh temp apt-get -y install aptitude
  78. ;;
  79. esac
  80. ./chroot.sh temp aptitude -y purge cdebootstrap-helper-diverts
  81. # Hmm - this next one seems like a bug!
  82. rm -rf "$targettemp/var/cache/debootstrap"
  83. ;;
  84. esac
  85. mkdir -p "$targettemp/etc/apt/apt.conf.d"
  86. echo 'Aptitude::CmdLine::Ignore-Trust-Violations "yes";' > "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  87. ./chroot.sh temp aptitude update
  88. # Next command should *not* cause any packages to get uninstalled, so
  89. # questions asked is an error and shouldn't be suppressed
  90. ./chroot.sh temp aptitude markauto '~i!~M(~E|~prequired|~sdevel|~sinterpreters|~slibdevel|~slibs|~soldlibs|~sperl|~spython|~sshells)'
  91. ./chroot.sh temp aptitude install -y --without-recommends debconf-english policyrcd-script-zg2
  92. cp -af tweaks/usr/local/sbin/policy-rc.d "$targettemp/usr/local/sbin/"
  93. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install $aptitude_dhcpclient_install
  94. # Workaround for Debian bug#272257 (see http://bugs.debian.org/281264 )
  95. #rm -f "$targettemp/etc/resolv.conf"
  96. # Prepare kernel installation
  97. # TODO: support yaird and mkramfs too
  98. # FIXME: deal with initrd generated while on host
  99. if [ "$RAMDISKTOOL" = "initrd-tools" ]; then
  100. preserveolderfile "$targettemp/etc/mkinitrd/mkinitrd.conf" orig
  101. perl -pi -e "s¡^ROOT=.*¡ROOT=$rootdev_target¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  102. perl -pi -e "s¡^MODULES=.*¡MODULES=dep¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  103. preserveandaddlines "$targettemp/etc/mkinitrd/modules" orig 1 $modules_install
  104. fi
  105. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 \
  106. "do_symlinks = no" \
  107. "relative_links = yes" \
  108. "do_bootloader = no" \
  109. "do_bootfloppy = no" \
  110. "do_initrd = yes" \
  111. "link_in_boot = no" \
  112. "silent_modules = yes"
  113. # FIXME: check if these are actually still any use with latest kernels
  114. cp -af initrd-tools/usbstick "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  115. chmod 0755 "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  116. cp -af initrd-tools/initrd.usbinit "$targettemp/usr/local/share/initrd.usbinit"
  117. if [ "$FLASHYBRID" = "yes" ]; then
  118. addaddons flashybrid_diskstore flashybrid_diskstore $addons
  119. # preserveandaddlines "$targettemp/etc/flashybrid/config" orig 1 "EMBED_CMDS=\"mount -o remount,ro /; invoke-rc-d mountvirtfs start\""
  120. preserveandaddlines "$targettemp/etc/flashybrid/ramtmp" orig 1 $flashybrid_ramtmp
  121. preserveandaddlines "$targettemp/etc/flashybrid/ramstore" orig 1 $flashybrid_ramstore
  122. preserveandaddlines "$targettemp/etc/flashybrid/diskstore" orig 1 $flashybrid_diskstore
  123. # Disable /dev
  124. # FIXME: Add and honour flag about using udev or not
  125. preserveandhashdisablelines "$targettemp/etc/flashybrid/ramstore" orig 1 "/dev"
  126. # Move off flashybrid directories (but leave empty dir behind)
  127. mkdir -p "$targetoffline" "$targettemp/ram" "$targettemp/disk"
  128. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$diskdev_target\t/disk\t$diskfs\tdefaults,noauto,nolock\t0\t0"
  129. # FIXME: Somehow make this step idempotent
  130. for dir in $flashybrid_diskstore; do
  131. if [ -d "${targettemp}${dir}" ]; then
  132. mkdir -p "$(dirname "${targetoffline}${dir}")"
  133. mv "${targettemp}${dir}" "${targetoffline}${dir}"
  134. else
  135. mkdir -p "${targetoffline}${dir}"
  136. fi
  137. mkdir -p "${targettemp}${dir}"
  138. done
  139. preserveolderfile "$targettemp/etc/default/flashybrid" orig
  140. perl -pi -e "s¡^ENABLED=.*¡ENABLED=yes¡" "$targettemp/etc/default/flashybrid"
  141. fi
  142. if [ -n "$grubdev_host" ]; then
  143. # Prepare GRUB install
  144. mkdir -p "$targettemp/boot/grub"
  145. mkgrubdevmap "$usbdev_target" > "$targettemp/boot/grub/device.map"
  146. # Recent GRUB packages store libraries below /usr/lib
  147. if [ -d "$targettemp/lib/grub/i386-pc/" ]; then
  148. grublibs="/lib/grub/i386-pc"
  149. else
  150. grublibs="/usr/lib/grub/i386-pc"
  151. fi
  152. cp -af "$targettemp/$grublibs/"* "$targettemp/boot/grub"
  153. # FIXME: Invent a hook wrapping both this and other bootloaders
  154. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 "postinst_hook = /sbin/update-grub" "postrm_hook = /sbin/update-grub"
  155. # preserveandaddlines "$targettemp/boot/grub/menu.lst" orig 1 "default 0" "timeout 5" "color cyan/blue white/blue"
  156. # FIXME: Write update-grub wrapper that disables "savedefault" option
  157. ./chroot.sh temp update-grub -y
  158. fi
  159. # Install kernel(s)
  160. # (must be after GRUB preparation but before SYSLINUX)
  161. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_kernel_install
  162. if [ -n "$grubdev_host" ]; then
  163. # FIXME: Write a kernel install hook to always strip
  164. # TODO: Rewrite as single-line perl routine
  165. cp -af "$targettemp/boot/grub/menu.lst" "$targettemp/boot/grub/menu.lst.old"
  166. grep -v -x 'savedefault' "$targettemp/boot/grub/menu.lst.old" > "$targettemp/boot/grub/menu.lst"
  167. rm -f "$targettemp/boot/grub/menu.lst.old"
  168. fi
  169. if [ -n "$syslinuxdev_host" ]; then
  170. mkdir -p "$targettemp_fat"
  171. cp -af "$targettemp/boot/initrd.img-${kernel_name}" "$targettemp_fat/initrd.img"
  172. cp -af "$targettemp/boot/vmlinuz-${kernel_name}" "$targettemp_fat/vmlinuz"
  173. enableoraddlines "$targettemp_fat/syslinux.cfg" 1 "default vmlinuz" "append initrd=initrd.img ramdisk_size=10240 root=$rootdev_target ro"
  174. fi
  175. # Install additional packages
  176. export DEBIAN_FRONTEND="noninteractive"
  177. addaddons aptitude_install_custom aptitude_install $addons
  178. if [ -n "$aptitude_install_custom" ]; then
  179. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install_custom
  180. fi
  181. # Empty package cache
  182. ./chroot.sh temp aptitude clean
  183. # ifupdown temporarily installs a dir, but cannot replace with symlink later due to rad-only rootfs
  184. for context in network resolvconf; do
  185. if [ -d "$targettemp/etc/$context/run" ] && [ ! -L "$targettemp/etc/$context/run" ]; then
  186. rm -rf "$targettemp/etc/$context/run"
  187. ln -s "/dev/shm/$context" "$targettemp/etc/$context/run"
  188. fi
  189. done
  190. # Remove hack to suppress warnings about insecure install
  191. rm -f "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  192. # Strip encryption keys (we don't want them distributed!)
  193. for keyfile in ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; do
  194. rm -f "$targettemp/etc/ssh/$keyfile" "$targettemp/etc/ssh/$keyfile.pub"
  195. done
  196. echo 'Done creating rootfs!'