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: Sam Nov 18 10:32:33 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 [ -n "$GRMLREPOS" ] ; then
21 echo 'deb http://grml.org/repos/ ./' >> /etc/apt/sources.list
24 if ! [ -r /etc/kernel-img.conf ] ; then
25 echo "Setting up /etc/kernel-img.conf"
26 cat > /etc/kernel-img.conf << EOF
27 # Kernel Image management overrides
28 # See kernel-img.conf(5) for details
34 # create default devices
35 if ! [ -r /dev/hda20 ] ; then
36 echo "Creating generic devices in /dev - this might take a while..."
37 cd /dev && MAKEDEV generic
40 # install additional packages
41 if [ "$PACKAGES" = 'yes' ] ; then
42 if ! [ -r /etc/debootstrap/packages ] ; then
43 echo "Error: /etc/debootstrap/packages not found, exiting."
47 apt-get --force-yes -y install $(cat /etc/debootstrap/packages) $GRMLPACKAGES
51 # sarge specific stuff
52 if [ "$RELEASE" = 'sarge' ] ; then
53 sed -i "s#ROOT=probe#ROOT=$TARGET#" /etc/mkinitrd/mkinitrd.conf
56 if [ -n "$KERNEL" ] ; then
58 if [ "$RELEASE" = 'sarge' ] ; then
59 KERNELPACKAGES="kernel-image-$KERNEL kernel-headers-$KERNEL"
61 KERNELPACKAGES="linux-image-$KERNEL linux-headers-$KERNEL"
63 apt-get --force-yes -y install $KERNELPACKAGES
66 if [ -n "$RECONFIGURE" ] ; then
67 for package in $RECONFIGURE ; do
68 dpkg --list $package 1>/dev/null 2>/dev/null && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
72 # set password of user root
73 echo "Activating shadow passwords."
75 echo "Setting password for user root:"
76 set +e # do not exit if passwd returns error due to missmatching passwords
79 set -e # restore default behaviour again
81 if ! [ -f /etc/hosts ] ; then
82 echo "Setting up /etc/hosts"
83 echo "127.0.0.1 localhost $HOSTNAME" > /etc/hosts
86 if ! [ -f /etc/network/interfaces ] ; then
87 echo "Setting up /etc/network/interfaces"
88 cat >> /etc/network/interfaces << EOF
89 iface lo inet loopback
97 if [ -n "$TIMEZONE" ] ; then
98 echo "Adjusting /etc/localtime"
99 ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
102 function createfstab(){
103 echo "Setting up /etc/fstab"
104 cat > /etc/fstab << EOF
105 $TARGET / auto defaults,errors=remount-ro 0 1
106 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
107 proc /proc proc defaults 0 0
108 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
109 # some other examples:
110 # /dev/sda2 none swap sw 0 0
111 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
112 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
113 # linux:/pub /beer nfs defaults 0 0
114 # tmpfs /tmp tmpfs size=300M 0 0
118 # set up /etc/fstab if file is not present (cdebootstrap)
119 if [ ! -f /etc/fstab ] ; then
123 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
124 if grep -q UNCONFIGURED /etc/fstab ; then
129 if [ -n "$HOSTNAME" ] ; then
130 echo "Setting hostname to ${HOSTNAME}."
131 echo "$HOSTNAME" > /etc/hostname
134 # assume the first available kernel as our main kernel
135 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
136 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
139 if [ -n "$INITRD" ] ; then
140 if [ "$RELEASE" = 'sarge' ] ; then
141 echo "Release sarge detected, will not create an initrd."
143 echo "Generating initrd."
144 update-initramfs -c -t -k $KERNELVER
145 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
146 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
147 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
152 if [ -z "$GROOT" ] ; then
153 echo "Warning: \$GROOT is not defined, can not adjust grub configuration therefor."
155 echo "Adjusting grub configuration for use on ${GROOT}."
157 # copy stage-files to /boot/grub/
158 [ -d /boot/grub/ ] || mkdir /boot/grub
159 if [ -d /usr/lib/grub/i386-pc/ ] ; then
160 cp /usr/lib/grub/i386-pc/* /boot/grub/
162 # sarge ships grub files in another directory
163 cp /lib/grub/i386-pc/* /boot/grub/
166 # finally install grub
168 sed -i "s/^# groot=.*/# groot=(${GROOT})/g" /boot/grub/menu.lst
169 sed -i "s|^# kopt=root=.*|# kopt=root=${TARGET} ro|g" /boot/grub/menu.lst
170 # not sure why savedefault does not work for me; any ideas?
171 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
175 # make sure we don't have any running processes left
176 for service in ssh mdadm mdadm-raid ; do
177 [ -x "/etc/init.d/$service" ] && "/etc/init.d/$service" stop
180 # unmount all filesystems in chroot, make sure nothing is left...
181 umount -a 1>/dev/null 2>/dev/null || true
182 umount /proc 1>/dev/null 2>/dev/null || true
183 umount /proc 1>/dev/null 2>/dev/null || true
184 umount -a 1>/dev/null 2>/dev/null || true
186 # finally exit the chroot
187 echo "Finished chroot installation, exiting."
190 ## END OF FILE #################################################################