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 /sys /sys sysfs rw,nosuid,nodev,noexec 0 0
80 proc /proc proc defaults 0 0
81 /dev/cdrom /mnt/cdrom0 iso9660 ro,user,noauto 0 0
82 # some other examples:
83 # /dev/sda2 none swap sw 0 0
84 # /dev/hda1 /Grml ext3 dev,suid,user,noauto 0 2
85 # //1.2.3.4/pub /smb/pub smbfs defaults,user,noauto,uid=grml,gid=grml 0 0
86 # linux:/pub /beer nfs defaults 0 0
87 # tmpfs /tmp tmpfs size=300M 0 0
91 # set up /etc/fstab if file is not present (cdebootstrap)
92 if [ ! -f /etc/fstab ] ; then
96 # set up /etc/fstab if file is UNCONFIGURED (debootstrap)
97 if grep -q UNCONFIGURED /etc/fstab ; then
102 if [ -n "$HOSTNAME" ] ; then
103 echo "Setting hostname to ${HOSTNAME}."
104 echo "$HOSTNAME" > /etc/hostname
107 # create default devices
108 if ! [ -r /dev/hda20 ] ; then
109 echo "Creating generic devices in /dev - this might take a while..."
110 cd /dev && MAKEDEV generic
113 # assume the first available kernel as our main kernel
114 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
115 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
118 if [ -n "$INITRD" ] ; then
119 echo "Generating initrd."
120 update-initramfs -c -t -k $KERNELVER
121 if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
122 GRUBINITRD="initrd /boot/initrd.img-$KERNELVER"
123 LILOINITRD=" initrd=/boot/initrd.img-$KERNELVER"
127 if [ -n "$GROOT" ] ; then
128 echo "Installing grub"
130 # copy stage-files to /boot/grub/
131 [ -d /boot/grub/ ] || mkdir /boot/grub
132 cp /usr/lib/grub/i386-pc/* /boot/grub/
134 # finally install grub
136 sed -i "s/groot=.*/groot=(${GROOT})/g" /boot/grub/menu.lst
137 # not sure why savedefault does not work for me; any ideas?
138 sed -i "s/^savedefault.*/# &/g" /boot/grub/menu.lst
141 if [ -z "$MBR" ] ; then
142 echo "Notice: \$MBR not set, will not install grub therefor."
144 cp /proc/mounts /etc/mtab
150 # make sure we don't have any running processes left
151 [ -x /etc/init.d/ssh ] && /etc/init.d/ssh stop
153 # unmount all filesystems in chroot, make sure nothing is left...
154 umount -a 1>/dev/null 2>/dev/null || true
155 umount /proc 1>/dev/null 2>/dev/null || true
156 umount /proc 1>/dev/null 2>/dev/null || true
157 umount -a 1>/dev/null 2>/dev/null || true
159 # finally exit the chroot
160 echo "Finished chroot installation, exiting."
163 ## END OF FILE #################################################################