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 23:27:30 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 grep -q done "$STAGES/$1" 2>/dev/null ; then
33 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
35 echo "$2" > "$STAGES/$1"
39 [ -r /proc/1 ] || mount -t proc none /proc
41 if [ -n "$CHROOTMIRROR" ] ; then
43 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
44 stage chrootmirror done
47 if [ -n "$GRMLREPOS" ] ; then
49 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
53 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
62 stage kernelimg.conf done
65 # create default devices
66 if ! [ -r /dev/hda20 ] ; then
68 echo "Creating generic devices in /dev - this might take a while..."
69 cd /dev && MAKEDEV generic
73 # install additional packages
74 if [ "$PACKAGES" = 'yes' ] ; then
76 if ! [ -r /etc/debootstrap/packages ] ; then
77 echo "Error: /etc/debootstrap/packages not found, exiting."
81 apt-get --force-yes -y install $(cat /etc/debootstrap/packages) $GRMLPACKAGES
86 # sarge specific stuff
87 if [ "$RELEASE" = 'sarge' ] ; then
89 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
93 if [ -n "$KERNEL" ] ; then
96 if [ "$RELEASE" = 'sarge' ] ; then
97 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
99 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
101 apt-get --force-yes -y install $KERNELPACKAGES
105 if [ -n "$RECONFIGURE" ] ; then
107 for package in $RECONFIGURE ; do
108 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
110 stage reconfigure done
113 # set password of user root
115 echo "Activating shadow passwords."
117 echo "Setting password for user root:"
118 set +e # do not exit if passwd returns error due to missmatching passwords
121 set -e # restore default behaviour again
124 if ! [ -f /etc/hosts ] ; then
126 echo "Setting up /etc/hosts"
127 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
131 if ! [ -f /etc/network/interfaces ] ; then
133 echo "Setting up /etc/network/interfaces"
134 cat >> /etc/network/interfaces << EOF
135 iface lo inet loopback
140 stage interfaces done
144 if [ -n "$TIMEZONE" ] ; then
146 echo "Adjusting /etc/localtime"
147 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
152 echo "Setting up /etc/fstab"
153 cat > /etc/fstab << EOF
154 $TARGET / auto defaults,errors=remount-ro 0 1
155 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
156 proc /proc proc defaults 0 0
157 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
158 # some other examples:
159 # /dev/sda2 none swap sw 0 0
160 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
161 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
162 # linux:/pub /beer nfs defaults 0 0
163 # tmpfs /tmp tmpfs size=300M 0 0
167 # set up /etc/fstab if file is not present (cdebootstrap)
168 if [ ! -f /etc/fstab ] ; then
174 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
175 if grep -q UNCONFIGURED /etc/fstab ; then
182 if [ -n "$HOSTNAME" ] ; then
184 echo "Setting hostname to ${HOSTNAME}."
185 echo "$HOSTNAME" > /etc/hostname
189 # assume the first available kernel as our main kernel
190 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
191 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
194 if [ -n "$INITRD" ] ; then
196 if [ "$RELEASE" = 'sarge' ] ; then
197 echo "Release sarge detected, will not create an initrd."
199 echo "Generating initrd."
200 update-initramfs -c -t -k $KERNELVER
201 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
202 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
203 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
209 if [ -z "$GROOT" ] ; then
210 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
213 echo "Adjusting grub configuration for use on ${GROOT}."
215 # copy stage-files to /boot/grub/
216 [ -d /boot/grub/ ] || mkdir /boot/grub
217 if [ -d /usr/lib/grub/i386-pc/ ] ; then
218 cp /usr/lib/grub/i386-pc/* /boot/grub/
220 # sarge ships grub files in another directory
221 cp /lib/grub/i386-pc/* /boot/grub/
224 # finally install grub
226 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
227 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
228 # not sure why savedefault does not work for me; any ideas?
229 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
234 # make sure we don't have any running processes left
235 for service in ssh mdadm mdadm-raid ; do
236 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
239 # unmount all filesystems in chroot, make sure nothing is left...
240 umount -a 1>/dev/null 2>/dev/null || true
241 umount /proc 1>/dev/null 2>/dev/null || true
242 umount /proc 1>/dev/null 2>/dev/null || true
243 umount -a 1>/dev/null 2>/dev/null || true
245 # finally exit the chroot
246 echo "Finished chroot installation, exiting."
249 ## END OF FILE #################################################################