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 23:42:36 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 "deb $CHROOTMIRROR $RELEASE main contrib non-free" > /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 # create default devices
31 if ! [ -r /dev/hda20 ] ; then
32 echo "Creating generic devices in /dev - this might take a while..."
33 cd /dev && MAKEDEV generic
36 # install additional packages
37 if [ "$PACKAGES" = 'yes' ] ; then
38 if ! [ -r /etc/debootstrap/packages ] ; then
39 echo "Error: /etc/debootstrap/packages not found, exiting."
43 apt-get --force-yes -y install $(cat /etc/debootstrap/packages)
47 # sarge specific stuff
48 if [ "$RELEASE" = 'sarge' ] ; then
49 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
52 if [ -n "$KERNEL" ] ; then
54 if [ "$RELEASE" = 'sarge' ] ; then
55 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
57 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
59 apt-get --force-yes -y install $KERNELPACKAGES
62 if [ -n "$RECONFIGURE" ] ; then
63 for package in $RECONFIGURE ; do
64 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
68 # set password of user root
69 echo "Activating shadow passwords."
71 echo "Setting password for user root:"
72 # TODO: typing the wrong password will exit chroot script
76 if ! [ -f /etc/hosts ] ; then
77 echo "Setting up /etc/hosts"
78 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
81 if ! [ -f /etc/network/interfaces ] ; then
82 echo "Setting up /etc/network/interfaces"
83 cat >> /etc/network/interfaces << EOF
84 iface lo inet loopback
92 if [ -n "$TIMEZONE" ] ; then
93 echo "Adjusting /etc/localtime"
94 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
97 function createfstab(){
98 echo "Setting up /etc/fstab"
99 cat > /etc/fstab << EOF
100 $TARGET / auto defaults,errors=remount-ro 0 1
101 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
102 proc /proc proc defaults 0 0
103 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
104 # some other examples:
105 # /dev/sda2 none swap sw 0 0
106 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
107 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
108 # linux:/pub /beer nfs defaults 0 0
109 # tmpfs /tmp tmpfs size=300M 0 0
113 # set up /etc/fstab if file is not present (cdebootstrap)
114 if [ ! -f /etc/fstab ] ; then
118 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
119 if grep -q UNCONFIGURED /etc/fstab ; then
124 if [ -n "$HOSTNAME" ] ; then
125 echo "Setting hostname to ${HOSTNAME}."
126 echo "$HOSTNAME" > /etc/hostname
129 # assume the first available kernel as our main kernel
130 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
131 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
134 if [ -n "$INITRD" ] ; then
135 if [ "$RELEASE" = 'sarge' ] ; then
136 echo "Release sarge detected, will not create an initrd."
138 echo "Generating initrd."
139 update-initramfs -c -t -k $KERNELVER
140 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
141 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
142 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
147 if [ -n "$GROOT" ] ; then
148 echo "Installing grub"
150 # copy stage-files to /boot/grub/
151 [ -d /boot/grub/ ] || mkdir /boot/grub
152 if [ -d /usr/lib/grub/i386-pc/ ] ; then
153 cp /usr/lib/grub/i386-pc/* /boot/grub/
155 # sarge ships grub files in another directory
156 cp /lib/grub/i386-pc/* /boot/grub/
159 # finally install grub
161 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
162 # not sure why savedefault does not work for me; any ideas?
163 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
166 if [ -z "$MBR" ] ; then
167 echo "Notice: \$MBR not set, will not install grub therefor."
169 cp /proc/mounts /etc/mtab
175 # make sure we don't have any running processes left
176 [ -x /etc/init.d/ssh ] && /etc/init.d/ssh stop
178 # unmount all filesystems in chroot, make sure nothing is left...
179 umount -a 1>/dev/null 2>/dev/null || true
180 umount /proc 1>/dev/null 2>/dev/null || true
181 umount /proc 1>/dev/null 2>/dev/null || true
182 umount -a 1>/dev/null 2>/dev/null || true
184 # finally exit the chroot
185 echo "Finished chroot installation, exiting."
188 ## END OF FILE #################################################################