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 # Latest change: Mon Apr 16 14:48:41 CEST 2007 [mika]
8 ################################################################################
10 set -e # exit on any error
12 . /etc/debootstrap/config || exit 1
13 . /etc/debootstrap/variables || exit 1
15 [ -r /proc/1 ] || mount -t proc none /proc
17 # use aptitude only if it's available
18 if [ -x /usr/bin/aptitude ] ; then
19 APTINSTALL='aptitude -y install '
20 APTUPDATE='aptitude update'
22 APTINSTALL='apt-get --force-yes -y install'
23 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 "$CHROOTMIRROR" ] ; then
48 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
53 # set up grml repository {{{
55 if [ -n "$GRMLREPOS" ] ; then
56 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
61 # set up kernel-img.conf {{{
63 if ! [ -r /etc/kernel-img.conf ] ; then
64 echo "Setting up /etc/kernel-img.conf"
65 cat > /etc/kernel-img.conf << EOF
66 # Kernel Image management overrides
67 # See kernel-img.conf(5) for details
75 # create default devices {{{
77 if ! [ -r /dev/hda20 ] ; then
78 echo "Creating generic devices in /dev - this might take a while..."
79 cd /dev && MAKEDEV generic
84 # install additional packages {{{
86 if [ "$PACKAGES" = 'yes' ] ; then
87 if ! [ -r /etc/debootstrap/packages ] ; then
88 echo "Error: /etc/debootstrap/packages not found, exiting."
92 $APTINSTALL $(cat /etc/debootstrap/packages) $GRMLPACKAGES
98 # sarge specific stuff: mkinitrd {{{
100 if [ "$RELEASE" = 'sarge' ] ; then
101 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
106 # install kernel packages {{{
108 # do not override $KERNEL if set via config file
109 if [ -z "$KERNEL" ] ; then
110 if [ "$ARCH" = 'i386' ] ; then
112 elif [ "$ARCH" = 'amd64' ] ; then
117 if [ -n "$KERNEL" ] ; then
119 if [ "$RELEASE" = 'sarge' ] ; then
120 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
122 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
124 $APTINSTALL $KERNELPACKAGES
129 # reconfigure packages {{{
131 if [ -n "$RECONFIGURE" ] ; then
132 for package in $RECONFIGURE ; do
133 dpkg --list $package 1>/dev/null 2>/dev/null && \
134 DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
135 echo "Warning: $package does not exist, can not reconfigure it."
141 # set password of user root {{{
143 echo "Activating shadow passwords."
145 echo "Setting password for user root:"
146 set +e # do not exit if passwd returns error due to missmatching passwords
149 set -e # restore default behaviour again
153 # set up /etc/hosts {{{
155 if ! [ -f /etc/hosts ] ; then
156 echo "Setting up /etc/hosts"
157 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
162 # set up /etc/network/interfaces {{{
164 if ! [ -f /etc/network/interfaces ] ; then
165 echo "Setting up /etc/network/interfaces"
166 cat >> /etc/network/interfaces << EOF
167 iface lo inet loopback
176 # adjust timezone {{{
178 if [ -n "$TIMEZONE" ] ; then
179 echo "Adjusting /etc/localtime"
180 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
185 # helper function for fstab() {{{
187 echo "Setting up /etc/fstab"
188 cat > /etc/fstab << EOF
189 $TARGET / auto defaults,errors=remount-ro 0 1
190 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
191 proc /proc proc defaults 0 0
192 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
193 # some other examples:
194 # /dev/sda2 none swap sw 0 0
195 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
196 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
197 # linux:/pub /beer nfs defaults 0 0
198 # tmpfs /tmp tmpfs size=300M 0 0
203 # generate /etc/fstab {{{
205 # set up /etc/fstab if file is not present (cdebootstrap)
206 if [ ! -f /etc/fstab ] ; then
210 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
211 if grep -q UNCONFIGURED /etc/fstab ; then
217 # set up hostname {{{
219 if [ -n "$HOSTNAME" ] ; then
220 echo "Setting hostname to ${HOSTNAME}."
221 echo "$HOSTNAME" > /etc/hostname
226 # generate initrd/initramfs {{{
228 # assume the first available kernel as our main kernel
229 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
230 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
233 if [ -n "$INITRD" ] ; then
234 if [ "$RELEASE" = 'sarge' ] ; then
235 echo "Release sarge detected, will not create an initrd."
237 echo "Generating initrd."
238 update-initramfs -c -t -k $KERNELVER
239 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
240 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
241 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
248 # grub configuration/installation {{{
250 if [ -z "$GROOT" ] ; then
251 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
253 echo "Adjusting grub configuration for use on ${GROOT}."
255 # copy stage-files to /boot/grub/
256 [ -d /boot/grub/ ] || mkdir /boot/grub
258 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
260 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
261 # sarge ships grub files in another directory
262 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
264 # finally install grub
265 if [ -x /usr/sbin/update-grub ] ; then
266 UPDATEGRUB='/usr/sbin/update-grub'
268 UPDATEGRUB='/sbin/update-grub'
271 if [ -f /boot/grub/menu.lst ] ; then
272 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
273 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
274 # not sure why savedefault does not work for me; any ideas?
275 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
282 # make sure we don't have any running processes left {{{
284 for service in ssh mdadm mdadm-raid ; do
285 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
290 # unmount all filesystems in chroot, make sure nothing is left {{{
292 umount -a 1>/dev/null 2>/dev/null || true
293 umount /proc 1>/dev/null 2>/dev/null || true
294 umount /proc 1>/dev/null 2>/dev/null || true
295 umount -a 1>/dev/null 2>/dev/null || true
299 # execute the functions {{{
300 stage chrootmirror && chrootmirror && stage chrootmirror done
301 stage grmlrepos && grmlrepos && stage grmlrepos done
302 stage kernelimg_conf && kernelimg_conf && stage kernelimg_conf done
303 stage makedev && makedev && stage makedev done
304 stage packages && packages && stage packages done
305 stage mkinitrd && mkinitrd && stage mkinitrd done
306 stage kernel && kernel && stage kernel done
307 stage reconfigure && reconfigure && stage reconfigure done
308 stage passwords && passwords && stage passwords done
309 stage hosts && hosts && stage hosts done
310 stage interfaces && interfaces && stage interfaces done
311 stage timezone && timezone && stage timezone done
312 stage fstab && fstab && stage fstab done
313 stage hostname && hostname && stage hostname done
314 stage initrd && initrd && stage initrd done
315 stage grub && grub && stage grub done
316 stage services && services && stage services done
317 stage finalize && finalize && stage finalize done
320 # finally exit the chroot {{{
321 echo "Finished chroot installation, exiting."
325 ## END OF FILE #################################################################
326 # vim: ai tw=80 expandtab foldmethod=marker