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: Don Apr 12 11:55:23 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
18 if [ -z "$STAGES" ] ; then
19 STAGES='/etc/debootstrap/stages'
20 [ -d "$STAGES" ] || mkdir -p "$STAGES"
24 # helper functions {{{
26 if grep -q done "$STAGES/$1" 2>/dev/null ; then
27 echo " * Notice: stage $1 has been executed already, skipping execution therefore."
30 echo "$2" > "$STAGES/$1"
36 # define chroot mirror {{{
38 if [ -n "$CHROOTMIRROR" ] ; then
39 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
44 # set up grml repository {{{
46 if [ -n "$GRMLREPOS" ] ; then
47 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
52 # set up kernel-img.conf {{{
54 if ! [ -r /etc/kernel-img.conf ] ; then
55 echo "Setting up /etc/kernel-img.conf"
56 cat > /etc/kernel-img.conf << EOF
57 # Kernel Image management overrides
58 # See kernel-img.conf(5) for details
66 # create default devices {{{
68 if ! [ -r /dev/hda20 ] ; then
69 echo "Creating generic devices in /dev - this might take a while..."
70 cd /dev && MAKEDEV generic
75 # install additional packages {{{
77 if [ "$PACKAGES" = 'yes' ] ; then
78 if ! [ -r /etc/debootstrap/packages ] ; then
79 echo "Error: /etc/debootstrap/packages not found, exiting."
83 apt-get --force-yes -y install $(cat /etc/debootstrap/packages) $GRMLPACKAGES
89 # sarge specific stuff: mkinitrd {{{
91 if [ "$RELEASE" = 'sarge' ] ; then
92 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
97 # install kernel packages {{{
99 # do not override $KERNEL if set via config file
100 if [ -z "$KERNEL" ] ; then
101 if [ "$ARCH" = 'i386' ] ; then
103 elif [ "$ARCH" = 'amd64' ] ; then
108 if [ -n "$KERNEL" ] ; then
110 if [ "$RELEASE" = 'sarge' ] ; then
111 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
113 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
115 apt-get --force-yes -y install $KERNELPACKAGES
120 # reconfigure packages {{{
122 if [ -n "$RECONFIGURE" ] ; then
123 for package in $RECONFIGURE ; do
124 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
130 # set password of user root {{{
132 echo "Activating shadow passwords."
134 echo "Setting password for user root:"
135 set +e # do not exit if passwd returns error due to missmatching passwords
138 set -e # restore default behaviour again
142 # set up /etc/hosts {{{
144 if ! [ -f /etc/hosts ] ; then
145 echo "Setting up /etc/hosts"
146 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
151 # set up /etc/network/interfaces {{{
153 if ! [ -f /etc/network/interfaces ] ; then
154 echo "Setting up /etc/network/interfaces"
155 cat >> /etc/network/interfaces << EOF
156 iface lo inet loopback
165 # adjust timezone {{{
167 if [ -n "$TIMEZONE" ] ; then
168 echo "Adjusting /etc/localtime"
169 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
174 # helper function for fstab() {{{
176 echo "Setting up /etc/fstab"
177 cat > /etc/fstab << EOF
178 $TARGET / auto defaults,errors=remount-ro 0 1
179 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
180 proc /proc proc defaults 0 0
181 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
182 # some other examples:
183 # /dev/sda2 none swap sw 0 0
184 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
185 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
186 # linux:/pub /beer nfs defaults 0 0
187 # tmpfs /tmp tmpfs size=300M 0 0
192 # generate /etc/fstab {{{
194 # set up /etc/fstab if file is not present (cdebootstrap)
195 if [ ! -f /etc/fstab ] ; then
199 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
200 if grep -q UNCONFIGURED /etc/fstab ; then
206 # set up hostname {{{
208 if [ -n "$HOSTNAME" ] ; then
209 echo "Setting hostname to ${HOSTNAME}."
210 echo "$HOSTNAME" > /etc/hostname
215 # generate initrd/initramfs {{{
217 # assume the first available kernel as our main kernel
218 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
219 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
222 if [ -n "$INITRD" ] ; then
223 if [ "$RELEASE" = 'sarge' ] ; then
224 echo "Release sarge detected, will not create an initrd."
226 echo "Generating initrd."
227 update-initramfs -c -t -k $KERNELVER
228 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
229 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
230 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
237 # grub configuration/installation {{{
239 if [ -z "$GROOT" ] ; then
240 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
242 echo "Adjusting grub configuration for use on ${GROOT}."
244 # copy stage-files to /boot/grub/
245 [ -d /boot/grub/ ] || mkdir /boot/grub
247 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
249 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
250 # sarge ships grub files in another directory
251 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
253 # finally install grub
255 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
256 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
257 # not sure why savedefault does not work for me; any ideas?
258 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
264 # make sure we don't have any running processes left {{{
266 for service in ssh mdadm mdadm-raid ; do
267 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
272 # unmount all filesystems in chroot, make sure nothing is left {{{
274 umount -a 1>/dev/null 2>/dev/null || true
275 umount /proc 1>/dev/null 2>/dev/null || true
276 umount /proc 1>/dev/null 2>/dev/null || true
277 umount -a 1>/dev/null 2>/dev/null || true
281 # execute the functions {{{
282 stage chrootmirror && chrootmirror && stage chrootmirror done
283 stage grmlrepos && grmlrepos && stage grmlrepos done
284 stage kernelimg_conf && kernelimg_conf && stage kernelimg_conf done
285 stage makedev && makedev && stage makedev done
286 stage packages && packages && stage packages done
287 stage mkinitrd && mkinitrd && stage mkinitrd done
288 stage kernel && kernel && stage kernel done
289 stage reconfigure && reconfigure && stage reconfigure done
290 stage passwords && passwords && stage passwords done
291 stage hosts && hosts && stage hosts done
292 stage interfaces && interfaces && stage interfaces done
293 stage timezone && timezone && stage timezone done
294 stage fstab && fstab && stage fstab done
295 stage hostname && hostname && stage hostname done
296 stage initrd && initrd && stage initrd done
297 stage grub && grub && stage grub done
298 stage services && services && stage services done
299 stage finalize && finalize && stage finalize done
302 # finally exit the chroot {{{
303 echo "Finished chroot installation, exiting."
307 ## END OF FILE #################################################################
308 # vim: ai tw=80 expandtab foldmethod=marker