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 ################################################################################
9 set -e # exit on any error
11 . /etc/debootstrap/config || exit 1
12 . /etc/debootstrap/variables || exit 1
14 [ -r /proc/1 ] || mount -t proc none /proc
18 # use aptitude only if it's available
19 if [ -x /usr/bin/aptitude ] ; then
20 APTINSTALL='aptitude -y --without-recommends install '
21 APTUPDATE='aptitude update'
23 APTINSTALL='apt-get --force-yes -y install'
24 APTUPDATE='apt-get update'
27 if [ -z "$STAGES" ] ; then
28 STAGES='/etc/debootstrap/stages'
29 [ -d "$STAGES" ] || mkdir -p "$STAGES"
33 # helper functions {{{
36 echo "$2" > "$STAGES/$1"
38 elif grep -q done "$STAGES/$1" 2>/dev/null ; then
39 echo "[*] Notice: stage $1 has been executed already, skipping execution therefore.">&2
45 # define chroot mirror {{{
47 [ -n "$KEEP_SRC_LIST" ] && return
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 # user might have provided their own apt sources.list
63 if ! grep -q grml /etc/apt/sources.list 2>/dev/null ; then
64 cat >> /etc/apt/sources.list << EOF
66 # grml: stable repository:
67 deb http://deb.grml.org/ grml-stable main
68 deb-src http://deb.grml.org/ grml-stable main
70 # grml: testing/development repository:
71 deb http://deb.grml.org/ grml-testing main
72 deb-src http://deb.grml.org/ grml-testing main
77 # make sure we have the keys available for aptitude
78 gpg --keyserver subkeys.pgp.net --recv-keys F61E2E7CECDEA787
79 gpg --export F61E2E7CECDEA787 | apt-key add - || /bin/true # not yet sure
80 # why it's necessary, sometimes we get an error even though it works [mika]
82 # make sure we install packages from grml's pool only if not available
84 if ! grep -q grml /etc/apt/preferences 2>/dev/null ; then
85 cat >> /etc/apt/preferences << EOF
86 // debian pool (default):
91 // main grml-repository:
93 Pin: origin deb.grml.org
101 # set up kernel-img.conf {{{
103 if ! [ -r /etc/kernel-img.conf ] ; then
104 echo "Setting up /etc/kernel-img.conf"
105 cat > /etc/kernel-img.conf << EOF
106 # Kernel Image management overrides
107 # See kernel-img.conf(5) for details
115 # create default devices {{{
117 if ! [ -r /dev/hda20 ] ; then
118 echo "Creating generic devices in /dev - this might take a while..."
119 cd /dev && MAKEDEV generic
124 # make sure services do not start up {{{
125 install_policy_rcd() {
126 if ! [ -r /usr/sbin/policy-rc.d ] ; then
128 cat > /usr/sbin/policy-rc.d << EOF
132 chmod 775 /usr/sbin/policy-rc.d
137 # install additional packages {{{
139 # Pre-seed the debconf database with answers. Each question will be marked
140 # as seen to prevent debconf from asking the question interactively.
141 [ -f /etc/debootstrap/debconf-selections ] && {
142 echo "Preseeding the debconf database, some lines might be skipped..."
143 cat /etc/debootstrap/debconf-selections | debconf-set-selections
146 if [ "$PACKAGES" = 'yes' ] ; then
147 if ! [ -r /etc/debootstrap/packages ] ; then
148 echo "Error: /etc/debootstrap/packages not found, exiting."
152 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $(grep -v '^#' /etc/debootstrap/packages) $GRMLPACKAGES
158 # install extra packages {{{
160 if [ "$EXTRAPACKAGES" = 'yes' ] ; then
161 PACKAGELIST=$(find /etc/debootstrap/extrapackages -type f -name '*.deb')
162 if [ -n "$PACKAGELIST" ]; then
164 # run apt again to resolve any deps
165 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL
171 # sarge specific stuff: mkinitrd {{{
173 if [ "$RELEASE" = 'sarge' ] ; then
174 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
179 # install kernel packages {{{
181 # do not override $KERNEL if set via config file
182 if [ -z "$KERNEL" ] ; then
183 if [ "$ARCH" = 'i386' ] ; then
185 elif [ "$ARCH" = 'amd64' ] ; then
190 if [ -n "$KERNEL" ] ; then
192 if [ "$RELEASE" = 'sarge' ] ; then
193 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
195 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
197 DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL $KERNELPACKAGES
202 # reconfigure packages {{{
204 if [ -n "$RECONFIGURE" ] ; then
205 for package in $RECONFIGURE ; do
206 dpkg --list $package 1>/dev/null 2>/dev/null && \
207 DEBIAN_FRONTEND=$DEBIAN_FRONTEND dpkg-reconfigure $package || \
208 echo "Warning: $package does not exist, can not reconfigure it."
214 # set password of user root {{{
217 echo "Activating shadow passwords."
220 if [ -n "$ROOTPASSWORD" ] ; then
221 echo root:"$ROOTPASSWORD" | chpasswd -m
222 export ROOTPASSWORD=''
226 echo "Setting password for user root:"
227 while [ "$a" != "$b" ] ; do
228 echo -n "Enter new UNIX password for user root: "
231 echo -n "Retype new UNIX password for user root: "
234 if [ "$a" != "$b" ] ; then
235 echo "Sorry, passwords do not match. Retry."
239 echo root:"$a" | chpasswd -m
248 # set up /etc/hosts {{{
250 if ! [ -f /etc/hosts ] ; then
251 echo "Setting up /etc/hosts"
252 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
257 # set up /etc/network/interfaces {{{
259 if ! [ -r /etc/network/interfaces ] ; then
260 echo "Setting up /etc/network/interfaces"
261 cat >> /etc/network/interfaces << EOF
264 iface lo inet loopback
268 # iface eth0 inet dhcp
276 # adjust timezone {{{
278 if [ -n "$TIMEZONE" ] ; then
279 echo "Adjusting /etc/localtime"
280 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
285 # helper function for fstab() {{{
287 echo "Setting up /etc/fstab"
288 if [ -n "$TARGET_UUID" ] ; then
289 echo "/dev/disk/by-uuid/${TARGET_UUID} / auto defaults,errors=remount-ro 0 1" > /etc/fstab
291 echo "${TARGET} / auto defaults,errors=remount-ro 0 1" > /etc/fstab
294 cat >> /etc/fstab << EOF
295 proc /proc proc defaults 0 0
296 /sys /sys sysfs noauto,rw,nosuid,nodev,noexec 0 0
297 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
298 # some other examples:
299 # /dev/sda2 none swap sw 0 0
300 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
301 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
302 # linux:/pub /beer nfs defaults 0 0
303 # tmpfs /tmp tmpfs size=300M 0 0
308 # generate /etc/fstab {{{
310 # set up /etc/fstab if file is not present (cdebootstrap)
311 if [ ! -f /etc/fstab ] ; then
315 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
316 if grep -q UNCONFIGURED /etc/fstab ; then
322 # set up hostname {{{
324 if [ -n "$HOSTNAME" ] ; then
325 echo "Setting hostname to ${HOSTNAME}."
326 echo "$HOSTNAME" > /etc/hostname
331 # generate initrd/initramfs {{{
333 # assume the first available kernel as our main kernel
334 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
335 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
338 if [ -n "$INITRD" ] ; then
339 if [ "$RELEASE" = 'sarge' ] ; then
340 echo "Release sarge detected, will not create an initrd."
342 echo "Generating initrd."
343 update-initramfs -c -t -k $KERNELVER
344 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
345 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
346 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
353 # grub configuration/installation {{{
355 if [ -z "$GROOT" ] ; then
356 echo "Warning: \$GROOT is not defined, will not adjust grub configuration therefore."
358 echo "Adjusting grub configuration for use on ${GROOT}."
360 # copy stage-files to /boot/grub/
361 [ -d /boot/grub/ ] || mkdir /boot/grub
363 [ -d /usr/lib/grub/i386-pc ] && cp /usr/lib/grub/i386-pc/* /boot/grub/
365 [ -d /usr/lib/grub/x86_64-pc ] && cp /usr/lib/grub/x86_64-pc/* /boot/grub/
366 # sarge ships grub files in another directory
367 [ "$RELEASE" = 'sarge' ] && cp /lib/grub/i386-pc/* /boot/grub/
369 # finally install grub
370 if [ -x /usr/sbin/update-grub ] ; then
371 UPDATEGRUB='/usr/sbin/update-grub'
373 UPDATEGRUB='/sbin/update-grub'
376 if [ -f /boot/grub/menu.lst ] ; then
377 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
378 if [ -n "$TARGET_UUID" ] ; then
379 sed -i "s|^# kopt=root=.*|# kopt=root=UUID=${TARGET_UUID} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
381 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro ${BOOT_APPEND}|g" /boot/grub/menu.lst
383 # not sure why savedefault does not work for me; any ideas?
384 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
391 # make sure we don't have any running processes left {{{
393 for service in ssh mdadm mdadm-raid ; do
394 if [ -x /etc/init.d/"$service" ] ; then
395 /etc/init.d/"$service" stop || /bin/true
401 # unmount all filesystems in chroot, make sure nothing is left {{{
403 # make sure we don't leave any sensible data
404 rm -f /etc/debootstrap/variables
405 [ -n "$POLICYRCD" ] && rm -f /usr/sbin/policy-rc.d
406 umount -a 1>/dev/null 2>/dev/null || true
407 umount /proc 1>/dev/null 2>/dev/null || true
408 umount /proc 1>/dev/null 2>/dev/null || true
409 umount -a 1>/dev/null 2>/dev/null || true
413 # execute the functions {{{
414 for i in chrootmirror grmlrepos kernelimg_conf makedev install_policy_rcd \
415 packages extrapackages mkinitrd kernel reconfigure hosts interfaces \
416 timezone fstab hostname initrd grub passwords services finalize ; do
418 $i && stage $i done || exit 1
423 # finally exit the chroot {{{
424 echo "Finished chroot installation, exiting."
428 ## END OF FILE #################################################################
429 # vim: ai tw=80 expandtab foldmethod=marker