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