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 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
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 && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
139 # set password of user root {{{
141 echo "Activating shadow passwords."
143 echo "Setting password for user root:"
144 set +e # do not exit if passwd returns error due to missmatching passwords
147 set -e # restore default behaviour again
151 # set up /etc/hosts {{{
153 if ! [ -f /etc/hosts ] ; then
154 echo "Setting up /etc/hosts"
155 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
160 # set up /etc/network/interfaces {{{
162 if ! [ -f /etc/network/interfaces ] ; then
163 echo "Setting up /etc/network/interfaces"
164 cat >> /etc/network/interfaces << EOF
165 iface lo inet loopback
174 # adjust timezone {{{
176 if [ -n "$TIMEZONE" ] ; then
177 echo "Adjusting /etc/localtime"
178 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
183 # helper function for fstab() {{{
185 echo "Setting up /etc/fstab"
186 cat > /etc/fstab << EOF
187 $TARGET / auto defaults,errors=remount-ro 0 1
188 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
189 proc /proc proc defaults 0 0
190 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
191 # some other examples:
192 # /dev/sda2 none swap sw 0 0
193 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
194 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
195 # linux:/pub /beer nfs defaults 0 0
196 # tmpfs /tmp tmpfs size=300M 0 0
201 # generate /etc/fstab {{{
203 # set up /etc/fstab if file is not present (cdebootstrap)
204 if [ ! -f /etc/fstab ] ; then
208 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
209 if grep -q UNCONFIGURED /etc/fstab ; then
215 # set up hostname {{{
217 if [ -n "$HOSTNAME" ] ; then
218 echo "Setting hostname to ${HOSTNAME}."
219 echo "$HOSTNAME" > /etc/hostname
224 # generate initrd/initramfs {{{
226 # assume the first available kernel as our main kernel
227 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
228 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
231 if [ -n "$INITRD" ] ; then
232 if [ "$RELEASE" = 'sarge' ] ; then
233 echo "Release sarge detected, will not create an initrd."
235 echo "Generating initrd."
236 update-initramfs -c -t -k $KERNELVER
237 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
238 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
239 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
246 # grub configuration/installation {{{
248 if [ -z "$GROOT" ] ; then
249 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
251 echo "Adjusting grub configuration for use on ${GROOT}."
253 # copy stage-files to /boot/grub/
254 [ -d /boot/grub/ ] || mkdir /boot/grub
256 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
258 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
259 # sarge ships grub files in another directory
260 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
262 # finally install grub
264 if [ -f /boot/grub/menu.lst ] ; then
265 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
266 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
267 # not sure why savedefault does not work for me; any ideas?
268 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
275 # make sure we don't have any running processes left {{{
277 for service in ssh mdadm mdadm-raid ; do
278 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
283 # unmount all filesystems in chroot, make sure nothing is left {{{
285 umount -a 1>/dev/null 2>/dev/null || true
286 umount /proc 1>/dev/null 2>/dev/null || true
287 umount /proc 1>/dev/null 2>/dev/null || true
288 umount -a 1>/dev/null 2>/dev/null || true
292 # execute the functions {{{
293 stage chrootmirror && chrootmirror && stage chrootmirror done
294 stage grmlrepos && grmlrepos && stage grmlrepos done
295 stage kernelimg_conf && kernelimg_conf && stage kernelimg_conf done
296 stage makedev && makedev && stage makedev done
297 stage packages && packages && stage packages done
298 stage mkinitrd && mkinitrd && stage mkinitrd done
299 stage kernel && kernel && stage kernel done
300 stage reconfigure && reconfigure && stage reconfigure done
301 stage passwords && passwords && stage passwords done
302 stage hosts && hosts && stage hosts done
303 stage interfaces && interfaces && stage interfaces done
304 stage timezone && timezone && stage timezone done
305 stage fstab && fstab && stage fstab done
306 stage hostname && hostname && stage hostname done
307 stage initrd && initrd && stage initrd done
308 stage grub && grub && stage grub done
309 stage services && services && stage services done
310 stage finalize && finalize && stage finalize done
313 # finally exit the chroot {{{
314 echo "Finished chroot installation, exiting."
318 ## END OF FILE #################################################################
319 # vim: ai tw=80 expandtab foldmethod=marker