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: Fre Nov 03 22:27:09 CET 2006 [mika]
8 ################################################################################
10 set -e # exit on any error
12 . /etc/debootstrap/config || exit 1
14 [ -r /proc/1 ] || mount -t proc none /proc
16 if [ -n "$CHROOTMIRROR" ] ; then
17 echo "$CHROOTMIRROR" > /etc/apt/sources.list
20 if ! [ -r /etc/kernel-img.conf ] ; then
21 echo "Setting up /etc/kernel-img.conf"
22 cat > /etc/kernel-img.conf << EOF
23 # Kernel Image management overrides
24 # See kernel-img.conf(5) for details
30 # install additional packages
31 if [ "$PACKAGES" = 'yes' ] ; then
32 if ! [ -r /etc/debootstrap/packages ] ; then
33 echo "Error: /etc/debootstrap/packages not found, exiting."
37 apt-get -y install $(cat /etc/debootstrap/packages)
41 if [ -n "$RECONFIGURE" ] ; then
42 for package in $RECONFIGURE ; do
43 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
47 # set password of user root
48 echo "Activating shadow passwords."
50 echo "Setting password for user root:"
54 if ! [ -f /etc/hosts ] ; then
55 echo "Setting up /etc/hosts"
56 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
59 if ! [ -f /etc/network/interfaces ] ; then
60 echo "Setting up /etc/network/interfaces"
61 cat >> /etc/network/interfaces << EOF
62 iface lo inet loopback
70 if [ -n "$TIMEZONE" ] ; then
71 echo "Adjusting /etc/localtime"
72 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
75 function createfstab(){
76 echo "Setting up /etc/fstab"
77 cat > /etc/fstab << EOF
78 $TARGET / auto defaults,errors=remount-ro 0 1
79 sysfs /sys sysfs auto 0 0
80 proc /proc proc defaults 0 0
81 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
82 # /dev/sda2 none swap sw 0 0
86 # set up /etc/fstab if file is not present (cdebootstrap)
87 if [ ! -f /etc/fstab ] ; then
91 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
92 if grep -q UNCONFIGURED /etc/fstab ; then
97 if [ -n "$HOSTNAME" ] ; then
98 echo "Setting hostname to ${HOSTNAME}."
99 echo "$HOSTNAME" > /etc/hostname
102 # create default devices
103 if ! [ -r /dev/hda20 ] ; then
104 echo "Creating generic devices in /dev - this might take a while..."
105 cd /dev && MAKEDEV generic
108 # assume the first available kernel as our main kernel
109 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
110 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
113 if [ -n "$INITRD" ] ; then
114 echo "Generating initrd."
115 update-initramfs -c -t -k $KERNELVER
116 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
117 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
118 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
122 if [ -n "$GROOT" ] ; then
123 echo "Installing grub"
125 # copy stage-files to /boot/grub/
126 [ -d /boot/grub/ ] || mkdir /boot/grub
127 cp /usr/lib/grub/i386-pc/* /boot/grub/
129 # finally install grub
131 sed -i "s/groot=.*/groot=(${GROOT})/g" /boot/grub/menu.lst
132 # not sure why savedefault does not work for me; any ideas?
133 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
136 if [ -z "$MBR" ] ; then
137 echo "Notice: \$MBR not set, will not install grub therefor."
139 cp /proc/mounts /etc/mtab
145 # make sure we don't have any running processes left
146 [ -x /etc/init.d/ssh ] && /etc/init.d/ssh stop
148 # unmount all filesystems in chroot, make sure nothing is left...
149 umount -a 1>/dev/null 2>/dev/null || true
150 umount /proc 1>/dev/null 2>/dev/null || true
151 umount /proc 1>/dev/null 2>/dev/null || true
152 umount -a 1>/dev/null 2>/dev/null || true
154 # finally exit the chroot
155 echo "Finished chroot installation, exiting."
158 ## END OF FILE #################################################################