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 09 15:33:33 CEST 2007 [mika]
8 ################################################################################
10 set -e # exit on any error
12 . /etc/debootstrap/config || exit 1
14 if [ -z "$STAGES" ] ; then
15 STAGES='/etc/debootstrap/stages'
16 [ -d "$STAGES" ] || mkdir -p "$STAGES"
22 eerror 'Error: stage() requires at least one argument.'
26 if [ -z "$STAGES" ] ; then
27 eerror 'Error: $STAGES not set.'
32 if [ -f "$STAGES/$1" ] ; then
33 if grep -q done "$STAGES/$1" ; then
34 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
37 echo "$2" > "$STAGES/$1"
41 [ -r /proc/1 ] || mount -t proc none /proc
43 if [ -n "$CHROOTMIRROR" ] ; then
45 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
46 stage chrootmirror done
49 if [ -n "$GRMLREPOS" ] ; then
51 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
55 if ! [ -r /etc/kernel-img.conf ] ; then
57 echo "Setting up /etc/kernel-img.conf"
58 cat > /etc/kernel-img.conf << EOF
59 # Kernel Image management overrides
60 # See kernel-img.conf(5) for details
64 stage kernelimg.conf done
67 # create default devices
68 if ! [ -r /dev/hda20 ] ; then
70 echo "Creating generic devices in /dev - this might take a while..."
71 cd /dev && MAKEDEV generic
75 # install additional packages
76 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
88 # sarge specific stuff
89 if [ "$RELEASE" = 'sarge' ] ; then
91 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
95 if [ -n "$KERNEL" ] ; then
98 if [ "$RELEASE" = 'sarge' ] ; then
99 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
101 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
103 apt-get --force-yes -y install $KERNELPACKAGES
107 if [ -n "$RECONFIGURE" ] ; then
109 for package in $RECONFIGURE ; do
110 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
112 stage reconfigure done
115 # set password of user root
117 echo "Activating shadow passwords."
119 echo "Setting password for user root:"
120 set +e # do not exit if passwd returns error due to missmatching passwords
123 set -e # restore default behaviour again
126 if ! [ -f /etc/hosts ] ; then
128 echo "Setting up /etc/hosts"
129 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
133 if ! [ -f /etc/network/interfaces ] ; then
135 echo "Setting up /etc/network/interfaces"
136 cat >> /etc/network/interfaces << EOF
137 iface lo inet loopback
142 stage interfaces done
146 if [ -n "$TIMEZONE" ] ; then
148 echo "Adjusting /etc/localtime"
149 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
154 echo "Setting up /etc/fstab"
155 cat > /etc/fstab << EOF
156 $TARGET / auto defaults,errors=remount-ro 0 1
157 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
158 proc /proc proc defaults 0 0
159 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
160 # some other examples:
161 # /dev/sda2 none swap sw 0 0
162 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
163 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
164 # linux:/pub /beer nfs defaults 0 0
165 # tmpfs /tmp tmpfs size=300M 0 0
169 # set up /etc/fstab if file is not present (cdebootstrap)
170 if [ ! -f /etc/fstab ] ; then
176 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
177 if grep -q UNCONFIGURED /etc/fstab ; then
184 if [ -n "$HOSTNAME" ] ; then
186 echo "Setting hostname to ${HOSTNAME}."
187 echo "$HOSTNAME" > /etc/hostname
191 # assume the first available kernel as our main kernel
192 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
193 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
196 if [ -n "$INITRD" ] ; then
198 if [ "$RELEASE" = 'sarge' ] ; then
199 echo "Release sarge detected, will not create an initrd."
201 echo "Generating initrd."
202 update-initramfs -c -t -k $KERNELVER
203 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
204 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
205 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
211 if [ -z "$GROOT" ] ; then
212 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
215 echo "Adjusting grub configuration for use on ${GROOT}."
217 # copy stage-files to /boot/grub/
218 [ -d /boot/grub/ ] || mkdir /boot/grub
219 if [ -d /usr/lib/grub/i386-pc/ ] ; then
220 cp /usr/lib/grub/i386-pc/* /boot/grub/
222 # sarge ships grub files in another directory
223 cp /lib/grub/i386-pc/* /boot/grub/
226 # finally install grub
228 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
229 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
230 # not sure why savedefault does not work for me; any ideas?
231 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
236 # make sure we don't have any running processes left
237 for service in ssh mdadm mdadm-raid ; do
238 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
241 # unmount all filesystems in chroot, make sure nothing is left...
242 umount -a 1>/dev/null 2>/dev/null || true
243 umount /proc 1>/dev/null 2>/dev/null || true
244 umount /proc 1>/dev/null 2>/dev/null || true
245 umount -a 1>/dev/null 2>/dev/null || true
247 # finally exit the chroot
248 echo "Finished chroot installation, exiting."
251 ## END OF FILE #################################################################