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