use
[grml-debootstrap.git] / chroot-script
1 #!/bin/sh
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 12:27:20 CET 2006 [mika]
8 ################################################################################
9
10 set -e
11
12 . /etc/debootstrap/config || exit 1
13
14 [ -r /proc/1 ] || mount -t proc   none /proc
15
16 if [ -n "$CHROOTMIRROR" ] ; then
17    echo "$CHROOTMIRROR" > /etc/apt/sources.list
18 fi
19
20 # install additional packages
21 if [ "$PACKAGES" = 'yes' ] ; then
22    if ! [ -r /etc/debootstrap/packages ] ; then
23      echo "Error: /etc/debootstrap/packages not found, exiting."
24      exit 1
25    else
26      apt-get update
27      apt-get -y install $(cat /etc/debootstrap/packages)
28    fi
29 fi
30
31 if [ -n "$RECONFIGURE" ] ; then
32    for package in $RECONFIGURE ; do
33        dpkg --list $package && dpkg-reconfigure $package || echo "Warning: $package does not exist, can not reconfigure it."
34    done
35 fi
36
37 # set password of user root
38 echo "Activating shadow passwords."
39 shadowconfig on
40 echo "Setting password for user root:"
41 passwd
42 echo ""
43
44 if ! [ -f /etc/hosts ] ; then
45    echo "Setting up /etc/hosts"
46    echo "127.0.0.1       localhost  $HOSTNAME" > /etc/hosts
47 fi
48
49 if ! [ -f /etc/network/interfaces ] ; then
50    echo "Setting up /etc/network/interfaces"
51    cat >> /etc/network/interfaces << EOF
52 iface lo inet loopback
53 iface eth0 inet dhcp
54 auto lo
55 auto eth0
56 EOF
57 fi
58
59 # adjust timezone
60 if [ -n "$TIMEZONE" ] ; then
61    echo "Adjusting /etc/localtime"
62    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
63 fi
64
65 if ! [ -f /etc/fstab ] ; then
66    echo "Setting up /etc/fstab"
67 cat >> /etc/fstab << EOF
68 sysfs          /sys         sysfs   auto                       0   0
69 proc           /proc        proc    defaults                   0   0
70 $TARGET      /            auto    defaults,errors=remount-ro 0   1
71 # /dev/sda2      none         swap    sw                         0   0
72 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
73 EOF
74 fi
75
76 # create default devices
77 if ! [ -r /dev/hda20 ] ; then
78    echo "Creating generic devices in /dev - this might take a while..."
79    cd /dev && MAKEDEV generic
80 fi
81
82 # assume the first available kernel as our main kernel
83 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
84 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
85
86 # generate initrd
87 if [ -n "$INITRD" ] ; then
88    echo "Generating initrd."
89    update-initramfs -c -t -k $KERNELVER
90    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
91       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
92       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
93    fi
94 fi
95
96 if [ "$BOOTMGR" = 'grub' ] ; then
97    echo "Installing grub"
98    if ! [ -f /boot/grub/menu.lst ] ; then
99       # setup grub
100       mkdir /boot/grub
101       cat >> /boot/grub/menu.lst << EOF
102 # Boot automatically after 30 secs.
103 timeout 30
104
105 # By default, boot the first entry.
106 default 0
107
108 # Fallback to the second entry.
109 fallback 1
110
111 title           Debian Etch, kernel $KERNELVER (on $ARGET)
112 root            (hd0,0)
113 kernel          $KERNELIMG root=$TARGET ro
114 $GRUBINITRD
115
116 # For booting Windows
117 # title Windows
118 # rootnoverify (hd0,0)
119 # makeactive
120 # chainloader  +1
121 EOF
122    fi
123
124    # copy stage-files to /boot/grub/
125    cp -i /usr/lib/grub/i386-pc/* /boot/grub/
126
127    # otherwise grub fails with 'Could not find device for /boot/boot: not found or not a block device'
128    cp /etc/mtab /etc/mtab.old
129    cp /proc/mounts /etc/mtab
130
131    # finally install grub
132    grub-install $BOOT
133
134    # restore mtab again
135    mv /etc/mtab.old /etc/mtab
136 fi
137
138 if [ "$BOOTMGR" = 'lilo' ] ; then
139    echo "Installing lilo"
140 # /usr/share/doc/lilo/examples/conf.sample
141 cat > /etc/lilo.conf << EOF
142 # This allows booting from any partition on disks with more than 1024 cylinders.
143 lba32
144
145 # Specifies the boot device
146 boot=$BOOT
147
148 # Specifies the device that should be mounted as root.
149 root=$TARGET
150
151 # use Debian on software raid:
152 # raid-extra-boot=mbr-only
153
154 install=text
155 # prompt
156 timeout=1
157 map=/boot/map
158 vga=normal
159
160 image=/boot/vmlinuz-2.6.17-grml
161         label="$KERNELVER"
162         #append="...."
163         read-only
164         $LILOINITRD
165 EOF
166 fi
167
168 # unmount all filesystems in chroot, make sure nothing is left...
169 umount -a
170 umount /proc
171 umount /proc
172 umount -a
173
174 # finally exit the chroot
175 echo "Finished chroot installation, exiting."
176 exit 0
177
178 ## END OF FILE #################################################################