summaryrefslogtreecommitdiff
path: root/1_makerootfs.sh
blob: 626bc62e5997a342442a01d58350a12318458940 (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 - these next ones seems like a bug!
  82. # (the first is created by older versions of cdebootstrap)
  83. rm -rf "$targettemp/var/cache/debootstrap"
  84. rm -rf "$targettemp/var/cache/bootstrap"
  85. ;;
  86. esac
  87. mkdir -p "$targettemp/etc/apt/apt.conf.d"
  88. echo 'Aptitude::CmdLine::Ignore-Trust-Violations "yes";' > "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  89. ./chroot.sh temp aptitude update
  90. # Next command should *not* cause any packages to get uninstalled, so
  91. # questions asked is an error and shouldn't be suppressed
  92. ./chroot.sh temp aptitude markauto '~i!~M(~E|~prequired|~sdevel|~sinterpreters|~slibdevel|~slibs|~soldlibs|~sperl|~spython|~sshells)'
  93. ./chroot.sh temp aptitude install -y --without-recommends debconf-english policyrcd-script-zg2
  94. cp -af tweaks/usr/local/sbin/policy-rc.d "$targettemp/usr/local/sbin/"
  95. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install $aptitude_dhcpclient_install
  96. # Workaround for Debian bug#272257 (see http://bugs.debian.org/281264 )
  97. #rm -f "$targettemp/etc/resolv.conf"
  98. # Prepare kernel installation
  99. # TODO: support yaird and mkramfs too
  100. # FIXME: deal with initrd generated while on host
  101. if [ "$RAMDISKTOOL" = "initrd-tools" ]; then
  102. preserveolderfile "$targettemp/etc/mkinitrd/mkinitrd.conf" orig
  103. perl -pi -e "s¡^ROOT=.*¡ROOT=$rootdev_target¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  104. perl -pi -e "s¡^MODULES=.*¡MODULES=dep¡" "$targettemp/etc/mkinitrd/mkinitrd.conf"
  105. preserveandaddlines "$targettemp/etc/mkinitrd/modules" orig 1 $modules_install
  106. fi
  107. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 \
  108. "do_symlinks = no" \
  109. "relative_links = yes" \
  110. "do_bootloader = no" \
  111. "do_bootfloppy = no" \
  112. "do_initrd = yes" \
  113. "link_in_boot = no" \
  114. "silent_modules = yes"
  115. # FIXME: check if these are actually still any use with latest kernels
  116. cp -af initrd-tools/usbstick "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  117. chmod 0755 "$targettemp/usr/share/initrd-tools/scripts/usbstick"
  118. cp -af initrd-tools/initrd.usbinit "$targettemp/usr/local/share/initrd.usbinit"
  119. if [ "$FLASHYBRID" = "yes" ]; then
  120. addaddons flashybrid_diskstore flashybrid_diskstore $addons
  121. # preserveandaddlines "$targettemp/etc/flashybrid/config" orig 1 "EMBED_CMDS=\"mount -o remount,ro /; invoke-rc-d mountvirtfs start\""
  122. preserveandaddlines "$targettemp/etc/flashybrid/ramtmp" orig 1 $flashybrid_ramtmp
  123. preserveandaddlines "$targettemp/etc/flashybrid/ramstore" orig 1 $flashybrid_ramstore
  124. preserveandaddlines "$targettemp/etc/flashybrid/diskstore" orig 1 $flashybrid_diskstore
  125. # Disable /dev
  126. # FIXME: Add and honour flag about using udev or not
  127. preserveandhashdisablelines "$targettemp/etc/flashybrid/ramstore" orig 1 "/dev"
  128. # Move off flashybrid directories (but leave empty dir behind)
  129. mkdir -p "$targetoffline" "$targettemp/ram" "$targettemp/disk"
  130. preserveandaddlines "$targettemp/etc/fstab" orig 2 "$diskdev_target\t/disk\t$diskfs\tdefaults,noauto,nolock\t0\t0"
  131. # FIXME: Somehow make this step idempotent
  132. for dir in $flashybrid_diskstore; do
  133. if [ -d "${targettemp}${dir}" ]; then
  134. mkdir -p "$(dirname "${targetoffline}${dir}")"
  135. mv "${targettemp}${dir}" "${targetoffline}${dir}"
  136. else
  137. mkdir -p "${targetoffline}${dir}"
  138. fi
  139. mkdir -p "${targettemp}${dir}"
  140. done
  141. preserveolderfile "$targettemp/etc/default/flashybrid" orig
  142. perl -pi -e "s¡^ENABLED=.*¡ENABLED=yes¡" "$targettemp/etc/default/flashybrid"
  143. fi
  144. if [ -n "$grubdev_host" ]; then
  145. # Prepare GRUB install
  146. mkdir -p "$targettemp/boot/grub"
  147. mkgrubdevmap "$usbdev_target" > "$targettemp/boot/grub/device.map"
  148. # Recent GRUB packages store libraries below /usr/lib
  149. if [ -d "$targettemp/lib/grub/i386-pc/" ]; then
  150. grublibs="/lib/grub/i386-pc"
  151. else
  152. grublibs="/usr/lib/grub/i386-pc"
  153. fi
  154. cp -af "$targettemp/$grublibs/"* "$targettemp/boot/grub"
  155. # FIXME: Invent a hook wrapping both this and other bootloaders
  156. preserveandaddlines "$targettemp/etc/kernel-img.conf" orig 1 "postinst_hook = /sbin/update-grub" "postrm_hook = /sbin/update-grub"
  157. # preserveandaddlines "$targettemp/boot/grub/menu.lst" orig 1 "default 0" "timeout 5" "color cyan/blue white/blue"
  158. # FIXME: Write update-grub wrapper that disables "savedefault" option
  159. ./chroot.sh temp update-grub -y
  160. fi
  161. # Install kernel(s)
  162. # (must be after GRUB preparation but before SYSLINUX)
  163. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_kernel_install
  164. if [ -n "$grubdev_host" ]; then
  165. # FIXME: Write a kernel install hook to always strip
  166. # TODO: Rewrite as single-line perl routine
  167. cp -af "$targettemp/boot/grub/menu.lst" "$targettemp/boot/grub/menu.lst.old"
  168. grep -v -x 'savedefault' "$targettemp/boot/grub/menu.lst.old" > "$targettemp/boot/grub/menu.lst"
  169. rm -f "$targettemp/boot/grub/menu.lst.old"
  170. fi
  171. if [ -n "$syslinuxdev_host" ]; then
  172. mkdir -p "$targettemp_fat"
  173. cp -af "$targettemp/boot/initrd.img-${kernel_name}" "$targettemp_fat/initrd.img"
  174. cp -af "$targettemp/boot/vmlinuz-${kernel_name}" "$targettemp_fat/vmlinuz"
  175. enableoraddlines "$targettemp_fat/syslinux.cfg" 1 "default vmlinuz" "append initrd=initrd.img ramdisk_size=10240 root=$rootdev_target ro"
  176. fi
  177. # Install additional packages
  178. export DEBIAN_FRONTEND="noninteractive"
  179. addaddons aptitude_install_custom aptitude_install $addons
  180. if [ -n "$aptitude_install_custom" ]; then
  181. ./chroot.sh temp aptitude install -y --without-recommends $aptitude_install_custom
  182. fi
  183. # Empty package cache
  184. ./chroot.sh temp aptitude clean
  185. # ifupdown temporarily installs a dir, but cannot replace with symlink later due to rad-only rootfs
  186. for context in network resolvconf; do
  187. if [ -d "$targettemp/etc/$context/run" ] && [ ! -L "$targettemp/etc/$context/run" ]; then
  188. rm -rf "$targettemp/etc/$context/run"
  189. ln -s "/dev/shm/$context" "$targettemp/etc/$context/run"
  190. fi
  191. done
  192. # Remove hack to suppress warnings about insecure install
  193. rm -f "$targettemp/etc/apt/apt.conf.d/99localforcedautoinstall"
  194. # Strip encryption keys (we don't want them distributed!)
  195. for keyfile in ssh_host_key ssh_host_rsa_key ssh_host_dsa_key; do
  196. rm -f "$targettemp/etc/ssh/$keyfile" "$targettemp/etc/ssh/$keyfile.pub"
  197. done
  198. echo 'Done creating rootfs!'