some more grub updates + fixes
[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 14:19:42 CET 2006 [mika]
8 ################################################################################
9
10 set -e # exit on any error
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 1>/dev/null 2>/dev/null && 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 # set up /etc/fstab if file is UNCONFIGURED
66 if grep -q UNCONFIGURED /etc/fstab ; then
67    echo "Setting up /etc/fstab"
68 cat > /etc/fstab << EOF
69 $TARGET      /            auto    defaults,errors=remount-ro 0   1
70 sysfs          /sys         sysfs   auto                       0   0
71 proc           /proc        proc    defaults                   0   0
72 # /dev/sda2    none         swap    sw                         0   0
73 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
74 EOF
75 fi
76
77 # create default devices
78 if ! [ -r /dev/hda20 ] ; then
79    echo "Creating generic devices in /dev - this might take a while..."
80    cd /dev && MAKEDEV generic
81 fi
82
83 # assume the first available kernel as our main kernel
84 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
85 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
86
87 # generate initrd
88 if [ -n "$INITRD" ] ; then
89    echo "Generating initrd."
90    update-initramfs -c -t -k $KERNELVER
91    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
92       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
93       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
94    fi
95 fi
96
97 if [ "$BOOTMGR" = 'grub' ] ; then
98    echo "Installing grub"
99 #   if ! [ -f /boot/grub/menu.lst ] ; then
100 #      # setup grub
101 #      mkdir /boot/grub
102 #      cat >> /boot/grub/menu.lst << EOF
103 ## Boot automatically after 30 secs.
104 #timeout 30
105 #
106 ## By default, boot the first entry.
107 #default 0
108 #
109 ## Fallback to the second entry.
110 #fallback 1
111 #
112 #title           Debian Etch, kernel $KERNELVER (on $ARGET)
113 #root            (hd0,0)
114 #kernel          $KERNELIMG root=$TARGET ro
115 #$GRUBINITRD
116 #
117 ## For booting Windows
118 ## title Windows
119 ## rootnoverify (hd0,0)
120 ## makeactive
121 ## chainloader  +1
122 #EOF
123 #   fi
124
125    # copy stage-files to /boot/grub/
126    [ -d /boot/grub/ ] || mkdir /boot/grub
127    cp -i /usr/lib/grub/i386-pc/* /boot/grub/
128
129    # otherwise grub fails with 'Could not find device for /boot/boot: not found or not a block device'
130    cp /etc/mtab /etc/mtab.old
131    cp /proc/mounts /etc/mtab
132
133    # finally install grub
134    # grub-install $BOOT
135    update-grub -y
136    [ -n "$GROOT" ] && sed -i "s/^# groot=(hd.*/groot=(${GROOT})" /boot/grub/menu.lst
137    update-grub -y
138
139    # restore mtab again
140    mv /etc/mtab.old /etc/mtab
141 fi
142
143 if [ "$BOOTMGR" = 'lilo' ] ; then
144    echo "Installing lilo"
145 # /usr/share/doc/lilo/examples/conf.sample
146 cat > /etc/lilo.conf << EOF
147 # This allows booting from any partition on disks with more than 1024 cylinders.
148 lba32
149
150 # Specifies the boot device
151 boot=$BOOT
152
153 # Specifies the device that should be mounted as root.
154 root=$TARGET
155
156 # use Debian on software raid:
157 # raid-extra-boot=mbr-only
158
159 install=text
160 # prompt
161 timeout=1
162 map=/boot/map
163 vga=normal
164
165 image=/boot/vmlinuz-2.6.17-grml
166         label="$KERNELVER"
167         #append="...."
168         read-only
169         $LILOINITRD
170 EOF
171 fi
172
173 # unmount all filesystems in chroot, make sure nothing is left...
174 umount -a     || true
175 umount /proc  || true
176 umount /proc  || true
177 umount -a     || true
178
179 # finally exit the chroot
180 echo "Finished chroot installation, exiting."
181 exit 0
182
183 ## END OF FILE #################################################################