2 # Filename: /etc/debootstrap/chroot-script
3 # Purpose: script executed in chroot when installing Debian via grml-debootstrap
4 # Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 # Bug-Reports: see http://grml.org/bugs/
6 # License: This file is licensed under the GPL v2.
7 ################################################################################
9 set -e # exit on any error
11 . /etc/debootstrap/config || exit 1
12 . /etc/debootstrap/variables || exit 1
14 [ -r /proc/1 ] || mount -t proc none /proc
18 # use aptitude only if it's available
19 if [ -x /usr/bin/aptitude ] ; then
20 APTINSTALL='aptitude -y --without-recommends install '
21 APTUPDATE='aptitude update'
23 APTINSTALL='apt-get --force-yes -y install'
24 APTUPDATE='apt-get update'
27 if [ -z "$STAGES" ] ; then
28 STAGES='/etc/debootstrap/stages'
29 [ -d "$STAGES" ] || mkdir -p "$STAGES"
33 # helper functions {{{
36 echo "$2" > "$STAGES/$1"
38 elif grep -q done "$STAGES/$1" 2>/dev/null ; then
39 echo "[*] Notice: stage $1 has been executed already, skipping execution therefore.">&2
45 # define chroot mirror {{{
47 if [ -n "$ISO" ] ; then
48 echo "deb $ISO $RELEASE main contrib" > /etc/apt/sources.list
49 [ -n "$CHROOTMIRROR" ] && echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" >> /etc/apt/sources.list
51 if [ -n "$CHROOTMIRROR" ] ; then
52 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
58 # set up grml repository {{{
60 if [ -n "$GRMLREPOS" ] ; then
61 cat >> /etc/apt/sources.list << EOF
63 # grml: stable repository:
64 deb http://deb.grml.org/ grml-stable main
65 deb-src http://deb.grml.org/ grml-stable main
67 # grml: testing/development repository:
68 deb http://deb.grml.org/ grml-testing main
69 deb-src http://deb.grml.org/ grml-testing main
72 # make sure we have the keys available for aptitude
73 gpg --keyserver subkeys.pgp.net --recv-keys F61E2E7CECDEA787
74 gpg --export F61E2E7CECDEA787 | apt-key add - || /bin/true # not yet sure
75 # why it's necessary, sometimes we get an error even though it works [mika]
77 # make sure we install packages from grml's pool only if not available
79 if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
80 cat >> /etc/apt/preferences << EOF
81 // debian pool (default):
86 // main grml-repository:
88 Pin: origin deb.grml.org
96 # set up kernel-img.conf {{{
98 if ! [ -r /etc/kernel-img.conf ] ; then
99 echo "Setting up /etc/kernel-img.conf"
100 cat > /etc/kernel-img.conf << EOF
101 # Kernel Image management overrides
102 # See kernel-img.conf(5) for details
110 # create default devices {{{
112 if ! [ -r /dev/hda20 ] ; then
113 echo "Creating generic devices in /dev - this might take a while..."
114 cd /dev && MAKEDEV generic
119 # make sure services do not start up {{{
120 install_policy_rcd() {
121 if ! [ -r /usr/sbin/policy-rc.d ] ; then
123 cat > /usr/sbin/policy-rc.d << EOF
127 chmod 775 /usr/sbin/policy-rc.d
132 # install additional packages {{{
134 if [ "$PACKAGES" = 'yes' ] ; then
135 if ! [ -r /etc/debootstrap/packages ] ; then
136 echo "Error: /etc/debootstrap/packages not found, exiting."
140 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $(grep -v '^#' /etc/debootstrap/packages) $GRMLPACKAGES
146 # install extra packages {{{
148 if [ "$EXTRAPACKAGES" = 'yes' ] ; then
149 PACKAGELIST=$(find /etc/debootstrap/extrapackages -type f -name '*.deb')
150 if [ -n "$PACKAGELIST" ]; then
152 # run apt again to resolve any deps
153 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL
159 # sarge specific stuff: mkinitrd {{{
161 if [ "$RELEASE" = 'sarge' ] ; then
162 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
167 # install kernel packages {{{
169 # do not override $KERNEL if set via config file
170 if [ -z "$KERNEL" ] ; then
171 if [ "$ARCH" = 'i386' ] ; then
173 elif [ "$ARCH" = 'amd64' ] ; then
178 if [ -n "$KERNEL" ] ; then
180 if [ "$RELEASE" = 'sarge' ] ; then
181 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
183 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
185 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
190 # reconfigure packages {{{
192 if [ -n "$RECONFIGURE" ] ; then
193 for package in $RECONFIGURE ; do
194 dpkg --list $package 1>/dev/null 2>/dev/null && \
195 DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
196 echo "Warning: $package does not exist, can not reconfigure it."
202 # set password of user root {{{
205 echo "Activating shadow passwords."
208 if [ -n "$ROOTPASSWORD" ] ; then
209 echo root:"$ROOTPASSWD" | chpasswd -m
214 echo "Setting password for user root:"
215 while [ "$a" != "$b" ] ; do
216 echo -n "Enter new UNIX password for user root: "
219 echo -n "Retype new UNIX password for user root: "
222 if [ "$a" != "$b" ] ; then
223 echo "Sorry, passwords do not match. Retry."
227 echo root:"$a" | chpasswd -m
236 # set up /etc/hosts {{{
238 if ! [ -f /etc/hosts ] ; then
239 echo "Setting up /etc/hosts"
240 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
245 # set up /etc/network/interfaces {{{
247 if ! [ -r /etc/network/interfaces ] ; then
248 echo "Setting up /etc/network/interfaces"
249 cat >> /etc/network/interfaces << EOF
252 iface lo inet loopback
256 # iface eth0 inet dhcp
264 # adjust timezone {{{
266 if [ -n "$TIMEZONE" ] ; then
267 echo "Adjusting /etc/localtime"
268 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
273 # helper function for fstab() {{{
275 echo "Setting up /etc/fstab"
276 cat > /etc/fstab << EOF
277 $TARGET / auto defaults,errors=remount-ro 0 1
278 proc /proc proc defaults 0 0
279 /sys /sys sysfs noauto,rw,nosuid,nodev,noexec 0 0
280 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
281 # some other examples:
282 # /dev/sda2 none swap sw 0 0
283 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
284 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
285 # linux:/pub /beer nfs defaults 0 0
286 # tmpfs /tmp tmpfs size=300M 0 0
291 # generate /etc/fstab {{{
293 # set up /etc/fstab if file is not present (cdebootstrap)
294 if [ ! -f /etc/fstab ] ; then
298 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
299 if grep -q UNCONFIGURED /etc/fstab ; then
305 # set up hostname {{{
307 if [ -n "$HOSTNAME" ] ; then
308 echo "Setting hostname to ${HOSTNAME}."
309 echo "$HOSTNAME" > /etc/hostname
314 # generate initrd/initramfs {{{
316 # assume the first available kernel as our main kernel
317 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
318 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
321 if [ -n "$INITRD" ] ; then
322 if [ "$RELEASE" = 'sarge' ] ; then
323 echo "Release sarge detected, will not create an initrd."
325 echo "Generating initrd."
326 update-initramfs -c -t -k $KERNELVER
327 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
328 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
329 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
336 # grub configuration/installation {{{
338 if [ -z "$GROOT" ] ; then
339 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
341 echo "Adjusting grub configuration for use on ${GROOT}."
343 # copy stage-files to /boot/grub/
344 [ -d /boot/grub/ ] || mkdir /boot/grub
346 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
348 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
349 # sarge ships grub files in another directory
350 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
352 # finally install grub
353 if [ -x /usr/sbin/update-grub ] ; then
354 UPDATEGRUB='/usr/sbin/update-grub'
356 UPDATEGRUB='/sbin/update-grub'
359 if [ -f /boot/grub/menu.lst ] ; then
360 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
361 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
362 # not sure why savedefault does not work for me; any ideas?
363 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
370 # make sure we don't have any running processes left {{{
372 for service in ssh mdadm mdadm-raid ; do
373 if [ -x /etc/init.d/"$service" ] ; then
374 /etc/init.d/"$service" stop || /bin/true
380 # unmount all filesystems in chroot, make sure nothing is left {{{
382 # make sure we don't leave any sensible data
383 rm -f /etc/debootstrap/variables
384 [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
385 umount -a 1>/dev/null 2>/dev/null || true
386 umount /proc 1>/dev/null 2>/dev/null || true
387 umount /proc 1>/dev/null 2>/dev/null || true
388 umount -a 1>/dev/null 2>/dev/null || true
392 # execute the functions {{{
393 for i in chrootmirror grmlrepos kernelimg_conf makedev install_policy_rcd \
394 packages extrapackages mkinitrd kernel reconfigure hosts interfaces \
395 timezone fstab hostname initrd grub passwords services finalize ; do
397 $i && stage $i done || exit 1
402 # finally exit the chroot {{{
403 echo "Finished chroot installation, exiting."
407 ## END OF FILE #################################################################
408 # vim: ai tw=80 expandtab foldmethod=marker