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: Die Apr 10 11:11:02 CEST 2007 [mika]
8 ################################################################################
10 set -e # exit on any error
12 . /etc/debootstrap/config || exit 1
14 [ -r /proc/1 ] || mount -t proc none /proc
17 if [ -z "$STAGES" ] ; then
18 STAGES='/etc/debootstrap/stages'
19 [ -d "$STAGES" ] || mkdir -p "$STAGES"
23 # helper functions {{{
25 if grep -q done "$STAGES/$1" 2>/dev/null ; then
26 ewarn "Notice: stage $1 has been executed already, skipping execution therefore." ; eend 0
29 echo "$2" > "$STAGES/$1"
35 # define chroot mirror {{{
37 if [ -n "$CHROOTMIRROR" ] ; then
38 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
43 # set up grml repository {{{
45 if [ -n "$GRMLREPOS" ] ; then
46 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
51 # set up kernel-img.conf {{{
53 if ! [ -r /etc/kernel-img.conf ] ; then
54 echo "Setting up /etc/kernel-img.conf"
55 cat > /etc/kernel-img.conf << EOF
56 # Kernel Image management overrides
57 # See kernel-img.conf(5) for details
65 # create default devices {{{
67 if ! [ -r /dev/hda20 ] ; then
68 echo "Creating generic devices in /dev - this might take a while..."
69 cd /dev && MAKEDEV generic
74 # install additional packages {{{
76 if [ "$PACKAGES" = 'yes' ] ; then
77 if ! [ -r /etc/debootstrap/packages ] ; then
78 echo "Error: /etc/debootstrap/packages not found, exiting."
82 apt-get --force-yes -y install $(cat /etc/debootstrap/packages) $GRMLPACKAGES
88 # sarge specific stuff: mkinitrd {{{
90 if [ "$RELEASE" = 'sarge' ] ; then
91 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
96 # install kernel packages {{{
98 if [ -n "$KERNEL" ] ; then
100 if [ "$RELEASE" = 'sarge' ] ; then
101 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
103 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
105 apt-get --force-yes -y install $KERNELPACKAGES
110 # reconfigure packages {{{
112 if [ -n "$RECONFIGURE" ] ; then
113 for package in $RECONFIGURE ; do
114 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
120 # set password of user root {{{
122 echo "Activating shadow passwords."
124 echo "Setting password for user root:"
125 set +e # do not exit if passwd returns error due to missmatching passwords
128 set -e # restore default behaviour again
132 # set up /etc/hosts {{{
134 if ! [ -f /etc/hosts ] ; then
135 echo "Setting up /etc/hosts"
136 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
141 # set up /etc/network/interfaces {{{
143 if ! [ -f /etc/network/interfaces ] ; then
144 echo "Setting up /etc/network/interfaces"
145 cat >> /etc/network/interfaces << EOF
146 iface lo inet loopback
155 # adjust timezone {{{
157 if [ -n "$TIMEZONE" ] ; then
158 echo "Adjusting /etc/localtime"
159 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
164 # helper function for fstab() {{{
166 echo "Setting up /etc/fstab"
167 cat > /etc/fstab << EOF
168 $TARGET / auto defaults,errors=remount-ro 0 1
169 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
170 proc /proc proc defaults 0 0
171 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
172 # some other examples:
173 # /dev/sda2 none swap sw 0 0
174 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
175 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
176 # linux:/pub /beer nfs defaults 0 0
177 # tmpfs /tmp tmpfs size=300M 0 0
182 # generate /etc/fstab {{{
184 # set up /etc/fstab if file is not present (cdebootstrap)
185 if [ ! -f /etc/fstab ] ; then
189 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
190 if grep -q UNCONFIGURED /etc/fstab ; then
196 # set up hostname {{{
198 if [ -n "$HOSTNAME" ] ; then
199 echo "Setting hostname to ${HOSTNAME}."
200 echo "$HOSTNAME" > /etc/hostname
205 # generate initrd/initramfs {{{
207 # assume the first available kernel as our main kernel
208 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
209 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
212 if [ -n "$INITRD" ] ; then
213 if [ "$RELEASE" = 'sarge' ] ; then
214 echo "Release sarge detected, will not create an initrd."
216 echo "Generating initrd."
217 update-initramfs -c -t -k $KERNELVER
218 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
219 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
220 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
227 # grub configuration/installation {{{
229 if [ -z "$GROOT" ] ; then
230 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
232 echo "Adjusting grub configuration for use on ${GROOT}."
234 # copy stage-files to /boot/grub/
235 [ -d /boot/grub/ ] || mkdir /boot/grub
237 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
239 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
240 # sarge ships grub files in another directory
241 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
243 # finally install grub
245 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
246 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
247 # not sure why savedefault does not work for me; any ideas?
248 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
254 # make sure we don't have any running processes left {{{
256 for service in ssh mdadm mdadm-raid ; do
257 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
262 # unmount all filesystems in chroot, make sure nothing is left {{{
264 umount -a 1>/dev/null 2>/dev/null || true
265 umount /proc 1>/dev/null 2>/dev/null || true
266 umount /proc 1>/dev/null 2>/dev/null || true
267 umount -a 1>/dev/null 2>/dev/null || true
271 # execute the functions {{{
272 stage chrootmirror && chrootmirror && stage chrootmirror done
273 stage grmlrepos && grmlrepos && stage grmlrepos done
274 stage kernelimg_conf && kernelimg_conf && stage kernelimg_conf done
275 stage makedev && makedev && stage makedev done
276 stage packages && packages && stage packages done
277 stage mkinitrd && mkinitrd && stage mkinitrd done
278 stage kernel && kernel && stage kernel done
279 stage reconfigure && reconfigure && stage reconfigure done
280 stage passwords && passwords && stage passwords done
281 stage hosts && hosts && stage hosts done
282 stage interfaces && interfaces && stage interfaces done
283 stage timezone && timezone && stage timezone done
284 stage fstab && fstab && stage fstab done
285 stage hostname && hostname && stage hostname done
286 stage initrd && initrd && stage initrd done
287 stage grub && grub && stage grub done
288 stage services && services && stage services done
289 stage finalize && finalize && stage finalize done
292 # finally exit the chroot {{{
293 echo "Finished chroot installation, exiting."
297 ## END OF FILE #################################################################
298 # vim: ai tw=80 expandtab foldmethod=marker