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: Tue Aug 26 20:59:31 CEST 2008 [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
19 # use aptitude only if it's available
20 if [ -x /usr/bin/aptitude ] ; then
21 APTINSTALL='aptitude -y install '
22 APTUPDATE='aptitude update'
24 APTINSTALL='apt-get --force-yes -y install'
25 APTUPDATE='apt-get update'
28 if [ -z "$STAGES" ] ; then
29 STAGES='/etc/debootstrap/stages'
30 [ -d "$STAGES" ] || mkdir -p "$STAGES"
34 # helper functions {{{
37 echo "$2" > "$STAGES/$1"
39 elif grep -q done "$STAGES/$1" 2>/dev/null ; then
40 echo "[*] Notice: stage $1 has been executed already, skipping execution therefore.">&2
46 # define chroot mirror {{{
48 if [ -n "$ISO" ] ; then
49 echo "deb $ISO $RELEASE main contrib" > /etc/apt/sources.list
50 [ -n "$CHROOTMIRROR" ] && echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" >> /etc/apt/sources.list
52 if [ -n "$CHROOTMIRROR" ] ; then
53 echo "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /etc/apt/sources.list
59 # set up grml repository {{{
61 if [ -n "$GRMLREPOS" ] ; then
62 cat >> /etc/apt/sources.list << EOF
64 # grml: stable repository:
65 deb http://deb.grml.org/ grml-stable main
66 deb-src http://deb.grml.org/ grml-stable main
68 # grml: testing/development repository:
69 deb http://deb.grml.org/ grml-testing main
70 deb-src http://deb.grml.org/ grml-testing main
73 # make sure we have the keys available for aptitude
74 gpg --keyserver subkeys.pgp.net --recv-keys F61E2E7CECDEA787
75 gpg --export F61E2E7CECDEA787 | apt-key add - || /bin/true # not yet sure
76 # why it's necessary, sometimes we get an error even though it works [mika]
78 # make sure we install packages from grml's pool only if not available
80 if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
81 cat >> /etc/apt/preferences << EOF
82 // debian pool (default):
87 // main grml-repository:
89 Pin: origin deb.grml.org
97 # set up kernel-img.conf {{{
99 if ! [ -r /etc/kernel-img.conf ] ; then
100 echo "Setting up /etc/kernel-img.conf"
101 cat > /etc/kernel-img.conf << EOF
102 # Kernel Image management overrides
103 # See kernel-img.conf(5) for details
111 # create default devices {{{
113 if ! [ -r /dev/hda20 ] ; then
114 echo "Creating generic devices in /dev - this might take a while..."
115 cd /dev && MAKEDEV generic
120 # make sure services do not start up {{{
121 install_policy_rcd() {
122 if ! [ -r /usr/sbin/policy-rc.d ] ; then
124 cat > /usr/sbin/policy-rc.d << EOF
128 chmod 775 /usr/sbin/policy-rc.d
133 # install additional packages {{{
135 if [ "$PACKAGES" = 'yes' ] ; then
136 if ! [ -r /etc/debootstrap/packages ] ; then
137 echo "Error: /etc/debootstrap/packages not found, exiting."
141 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $(cat /etc/debootstrap/packages) $GRMLPACKAGES
147 # install extra packages {{{
149 if [ "$EXTRAPACKAGES" = 'yes' ] ; then
150 PACKAGELIST=$(find /etc/debootstrap/extrapackages -type f -name '*.deb')
151 if [ -n "$PACKAGELIST" ]; then
153 # run apt again to resolve any deps
154 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL
160 # sarge specific stuff: mkinitrd {{{
162 if [ "$RELEASE" = 'sarge' ] ; then
163 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
168 # install kernel packages {{{
170 # do not override $KERNEL if set via config file
171 if [ -z "$KERNEL" ] ; then
172 if [ "$ARCH" = 'i386' ] ; then
174 elif [ "$ARCH" = 'amd64' ] ; then
179 if [ -n "$KERNEL" ] ; then
181 if [ "$RELEASE" = 'sarge' ] ; then
182 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
184 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
186 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
191 # reconfigure packages {{{
193 if [ -n "$RECONFIGURE" ] ; then
194 for package in $RECONFIGURE ; do
195 dpkg --list $package 1>/dev/null 2>/dev/null && \
196 DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
197 echo "Warning: $package does not exist, can not reconfigure it."
203 # set password of user root {{{
205 echo "Activating shadow passwords."
208 if [ -n "$ROOTPASSWORD" ] ; then
209 echo root:"$ROOTPASSWD" | chpasswd -m
212 echo "Setting password for user root:"
213 echo -n "Enter new UNIX password for user root: "
215 echo root:"$a" | chpasswd -m
222 # set up /etc/hosts {{{
224 if ! [ -f /etc/hosts ] ; then
225 echo "Setting up /etc/hosts"
226 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
231 # set up /etc/network/interfaces {{{
233 if ! [ -r /etc/network/interfaces ] ; then
234 echo "Setting up /etc/network/interfaces"
235 cat >> /etc/network/interfaces << EOF
238 iface lo inet loopback
242 # iface eth0 inet dhcp
250 # adjust timezone {{{
252 if [ -n "$TIMEZONE" ] ; then
253 echo "Adjusting /etc/localtime"
254 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
259 # helper function for fstab() {{{
261 echo "Setting up /etc/fstab"
262 cat > /etc/fstab << EOF
263 $TARGET / auto defaults,errors=remount-ro 0 1
264 proc /proc proc defaults 0 0
265 /sys /sys sysfs noauto,rw,nosuid,nodev,noexec 0 0
266 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
267 # some other examples:
268 # /dev/sda2 none swap sw 0 0
269 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
270 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
271 # linux:/pub /beer nfs defaults 0 0
272 # tmpfs /tmp tmpfs size=300M 0 0
277 # generate /etc/fstab {{{
279 # set up /etc/fstab if file is not present (cdebootstrap)
280 if [ ! -f /etc/fstab ] ; then
284 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
285 if grep -q UNCONFIGURED /etc/fstab ; then
291 # set up hostname {{{
293 if [ -n "$HOSTNAME" ] ; then
294 echo "Setting hostname to ${HOSTNAME}."
295 echo "$HOSTNAME" > /etc/hostname
300 # generate initrd/initramfs {{{
302 # assume the first available kernel as our main kernel
303 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
304 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
307 if [ -n "$INITRD" ] ; then
308 if [ "$RELEASE" = 'sarge' ] ; then
309 echo "Release sarge detected, will not create an initrd."
311 echo "Generating initrd."
312 update-initramfs -c -t -k $KERNELVER
313 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
314 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
315 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
322 # grub configuration/installation {{{
324 if [ -z "$GROOT" ] ; then
325 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
327 echo "Adjusting grub configuration for use on ${GROOT}."
329 # copy stage-files to /boot/grub/
330 [ -d /boot/grub/ ] || mkdir /boot/grub
332 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
334 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
335 # sarge ships grub files in another directory
336 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
338 # finally install grub
339 if [ -x /usr/sbin/update-grub ] ; then
340 UPDATEGRUB='/usr/sbin/update-grub'
342 UPDATEGRUB='/sbin/update-grub'
345 if [ -f /boot/grub/menu.lst ] ; then
346 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
347 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
348 # not sure why savedefault does not work for me; any ideas?
349 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
356 # make sure we don't have any running processes left {{{
358 for service in ssh mdadm mdadm-raid ; do
359 if [ -x /etc/init.d/"$service" ] ; then
360 /etc/init.d/"$service" stop || /bin/true
366 # unmount all filesystems in chroot, make sure nothing is left {{{
368 # make sure we don't leave any sensible data
369 rm -f /etc/debootstrap/variables
370 [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
371 umount -a 1>/dev/null 2>/dev/null || true
372 umount /proc 1>/dev/null 2>/dev/null || true
373 umount /proc 1>/dev/null 2>/dev/null || true
374 umount -a 1>/dev/null 2>/dev/null || true
378 # execute the functions {{{
379 for i in chrootmirror grmlrepos kernelimg_conf makedev install_policy_rcd \
380 packages extrapackages mkinitrd kernel reconfigure hosts interfaces \
381 timezone fstab hostname initrd grub passwords services finalize ; do
383 $i && stage $i done || exit 1
388 # finally exit the chroot {{{
389 echo "Finished chroot installation, exiting."
393 ## END OF FILE #################################################################
394 # vim: ai tw=80 expandtab foldmethod=marker