initial checkin
[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 01:19:41 CET 2006 [mika]
8 ################################################################################
9
10 set -e
11
12 . /etc/debootstrap/config || exit 1
13
14 mount -t proc   none /proc
15
16 if [ -n "$RECONFIGURE" ] ; then
17    for package in $RECONFIGURE ; do
18        dpkg-reconfigure $package
19    done
20 fi
21
22 # set password of user root
23 passwd
24
25 if ! [ -f /etc/hosts ] ; then
26    echo "127.0.0.1       localhost  $HOSTNAME" > $MNTPOINT/etc/hosts
27 fi
28
29 if ! [ -f /etc/network/interfaces ] ; then
30    cat >> /etc/network/interfaces << EOF
31 iface lo inet loopback 
32 iface eth0 inet dhcp
33 auto lo
34 auto eth0
35 EOF
36 fi
37
38 # adjust timezone
39 if [ -n "$TIMEZONE" ] ; then
40    ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
41 fi
42
43 if ! [ -f /etc/fstab ] ; then
44 cat >> /etc/fstab << EOF
45 sysfs          /sys         sysfs   auto                       0   0
46 proc           /proc        proc    defaults                   0   0
47 $TARGET      /            auto    defaults,errors=remount-ro 0   1
48 # /dev/sda2      none         swap    sw                         0   0 
49 /dev/cdrom     /mnt/cdrom0  iso9660 ro,user,noauto             0   0
50 EOF
51 fi
52
53 # create default devices
54 cd /dev && MAKEDEV generic
55
56 # generate initrd
57 if [ -n "$INITRD" ] ; then
58    update-initramfs -c -t -k $KERNEL
59    if [ -f "/boot/initrd.img-$KERNELVER" ] ; then
60       GRUBINITRD="initrd          /boot/initrd.img-$KERNELVER"
61       LILOINITRD="        initrd=/boot/initrd.img-$KERNELVER"
62    fi
63 fi
64
65 # assume the first available kernel as our main kernel
66 KERNELIMG=$(ls -1 /boot/vmlinuz-* | head -1)
67 KERNELVER=${KERNELIMG#/boot/vmlinuz-}
68
69 if [ "$BOOTMGR" = 'grub' ] ; then
70    if ! [ -f /boot/grub/menu.lst ] ; then
71       # setup grub
72       mkdir /boot/grub
73       cat >> /boot/grub/menu.lst << EOF
74 # Boot automatically after 30 secs.
75 timeout 30
76
77 # By default, boot the first entry.
78 default 0
79
80 # Fallback to the second entry.
81 fallback 1
82
83 title           Debian Etch, kernel $KERNELVER (on $ARGET)
84 root            (hd0,0)
85 kernel          $KERNELIMG root=$TARGET ro
86 $GRUBINITRD
87
88 # For booting Windows
89 # title Windows
90 # rootnoverify (hd0,0)
91 # makeactive
92 # chainloader  +1
93 EOF
94    fi
95
96    # copy stage-files to /boot/grub/
97    cp -i /usr/lib/grub/i386-pc/* /boot/grub/
98
99    # finally install grub
100    grub-install $BOOT
101 fi
102
103 if [ "$BOOTMGR" = 'lilo' ] ; then
104 # /usr/share/doc/lilo/examples/conf.sample
105 cat > /etc/lilo.conf << EOF
106 # This allows booting from any partition on disks with more than 1024 cylinders.
107 lba32
108
109 # Specifies the boot device
110 boot=$BOOT
111
112 # Specifies the device that should be mounted as root.
113 root=$TARGET
114
115 # use Debian on software raid:
116 # raid-extra-boot=mbr-only
117
118 install=text
119 # prompt
120 timeout=1
121 map=/boot/map
122 vga=normal
123
124 image=/boot/vmlinuz-2.6.17-grml
125         label="$KERNELVER"
126         #append="...."
127         read-only
128         $LILOINITRD
129 EOF
130 fi
131
132 # unmount all filesystems in chroot
133 umount -a
134
135 # finally exit the chroot
136 exit 0
137
138 ## END OF FILE #################################################################