/[fai]/trunk/scripts/make-fai-nfsroot
ViewVC logotype

Contents of /trunk/scripts/make-fai-nfsroot

Parent Directory Parent Directory | Revision Log Revision Log


Revision 632 - (show annotations) (download)
Mon May 14 12:49:10 2001 UTC (12 years ago) by lange
File size: 8753 byte(s)
mv templates to new dir
1 #! /bin/sh
2
3 # $Id$
4 #*********************************************************************
5 #
6 # make-fai-nfsroot -- create nfsroot directory and add additional packages
7 #
8 # This script is part of FAI (Fully Automatic Installation)
9 # (c) 2000-2001 by Thomas Lange, lange@informatik.uni-koeln.de
10 # Universitaet zu Koeln
11 #
12 #*********************************************************************
13 # This program is free software; you can redistribute it and/or modify
14 # it under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2 of the License, or
16 # (at your option) any later version.
17 #
18 # This program is distributed in the hope that it will be useful, but
19 # WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 # General Public License for more details.
22 #
23 # A copy of the GNU General Public License is available as
24 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
25 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
26 # can also obtain it by writing to the Free Software Foundation, Inc.,
27 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #*********************************************************************
29
30 # Packages that are install to nfsroot by default
31 # Additional packages are defined with $NFSROOT_PACKAGES in fai.conf
32 packages="perl-5.005 dhcp-client file rdate cfengine bootpc wget rsh-client less dump ext2resize raidtools2 strace expect5.31 hdparm parted dnsutils grub"
33
34 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
35
36 if [ "$UID" -ne 0 ]; then
37 echo "Run this program as root."
38 exit 9
39 fi
40
41 while getopts v opt ; do
42 case "$opt" in
43 v) verbose=1 ;;
44 esac
45 done
46
47 set -e
48 . /etc/fai.conf
49 packages="$packages $NFSROOT_PACKAGES"
50 ROOTCMD="chroot $NFSROOT"
51
52 conffile=$NFSROOT/etc/rcS_fai.conf
53 export DEBIAN_FRONTEND=Noninteractive
54
55 if [ "$verbose" ]; then
56 devnull=/dev/tty
57 else
58 devnull=/dev/null
59 fi
60
61 trap "umount_dirs" EXIT
62 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 die() {
64
65 echo $*
66 exit 99
67 }
68 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69 install_kernel_nfsroot() {
70
71 rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
72 dpkg -x $KERNELPACKAGE $NFSROOT
73 # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
74 # these special flags; so umount first
75 umount $NFSROOT/proc
76 chroot $NFSROOT update-modules
77 chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
78 }
79 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80 setup_ssh() {
81
82 # nothing to do if no ssh is available in nfsroot
83 [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
84 mkdir -p -m 700 $NFSROOT/root/.ssh
85 [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts
86 loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
87 [ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/
88
89 # enable root login
90 perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
91 if [ -f "$SSH_IDENTITY" ]; then
92 cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
93 echo You can log into install clients without password using $SSH_IDENTITY
94 fi
95 }
96 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
97 copy_fai_files() {
98
99 # copy to nfsroot
100 perl -pi -e "s/^root::/root:${FAI_ROOTPW}:/" etc/passwd
101 mkdir -p $NFSROOT/fai/fai_config $NFSROOT/usr/share/fai
102 cd $NFSROOT
103 cp -p $LIBFAI/sbin/dhclient-script $LIBFAI/etc/dhclient.conf /etc/fai.conf etc
104 cp -p $LIBFAI/sbin/* sbin
105 cp -p $LIBFAI/etc/fai_modules_off etc/modutils
106
107 cp -p /usr/share/fai/subroutines usr/share/fai
108 cp -p $LIBFAI/etc/apt.conf etc/apt
109 cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
110 cp -p /tmp/base?_?.tgz var/tmp
111 echo $NFSROOT_ETC_HOSTS >> etc/hosts
112 }
113 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114 create_nfsroot() {
115
116 mkdir -p $NFSROOT/fai
117 cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
118 get_basetgz
119 echo -n "Unpacking " ; ls /tmp/base?_?.tgz
120 tar -C $NFSROOT -zxpf /tmp/base?_?.tgz
121 mknod dev/boot255 c 0 255
122
123 if [ "$FAI_DEBMIRROR" ]; then
124 mkdir -p $NFSROOT/$MNTPOINT
125 mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || die "Can't mount $FAI_DEBMIRROR"
126 fi
127
128 # hoaks some packages
129 touch etc/fstab etc/raidtab # dump and raidtool2 needs these files
130 mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
131 touch lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
132 mkdir -p etc/ssh
133 touch etc/ssh/NOSERVER
134
135 echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
136 upgrade_nfsroot
137 copy_fai_files
138
139 # set timezone
140 rm -f etc/localtime
141 cp -d /etc/localtime /etc/timezone etc
142
143 # make little changes to nfsroot, because nfsroot is
144 # read only for the install clients
145 rm -rf etc/mtab var/run
146 mv etc/init.d/rcS etc/init.d/rcS.orig
147 ln -s /proc/mounts etc/mtab
148 ln -s /tmp/var/run var/run
149 ln -sf /tmp/etc/resolv.conf etc/resolv.conf
150 ln -s /sbin/rcS_fai etc/init.d/rcS
151
152 # turn off logging of loading kernel modules
153 rmdir var/log/ksymoops/
154 ln -s /dev/null var/log/ksymoops
155
156 # definition for loopback device
157 echo "iface lo inet loopback" > etc/network/interfaces
158
159 echo "*.* /tmp/syslog.log" > etc/syslog.conf
160 echo ". /usr/share/fai/subroutines" >> root/.profile
161
162 setup_ssh
163
164 cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
165 #!/bin/sh
166 echo FAI: installation aborted.
167 echo reboot with: faireboot
168 echo or after a logout
169 sh
170 cd /
171 umount -ar
172 reboot -dfi
173 EOF
174 chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
175 }
176 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
177 upgrade_nfsroot() {
178
179 echo "Upgrading $NFSROOT"
180 {
181 cp /etc/resolv.conf $NFSROOT/etc
182 $ROOTCMD apt-get update
183 $ROOTCMD apt-get check
184 rm -rf $NFSROOT/etc/pcmcia $NFSROOT/etc/apm
185 mount -t proc /proc $NFSROOT/proc
186 $ROOTCMD apt-get -y remove pcmcia-cs </dev/null
187
188 # fake start-stop-dameon
189 $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
190 cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
191 $ROOTCMD apt-get -y upgrade
192 } > $devnull
193 echo "Adding additional packages to $NFSROOT:"
194 echo "$packages"
195 {
196 $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
197 $ROOTCMD apt-get clean
198 } > $devnull
199 }
200 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
201 get_basetgz() {
202
203 [ -f /tmp/base?_?.tgz ] && return
204 [ "$FAI_BASETGZ" ] || die "No /tmp/base?_?.tgz found and FAI_BASETGZ not defined."
205 case $FAI_BASETGZ in
206 ftp:*|http:*)
207 echo "Fetching $FAI_BASETGZ via wget. This may take some time."
208 TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
209 rm $TMPBDIR; mkdir $TMPBDIR || exit
210 wget -P$TMPBDIR $FAI_BASETGZ
211 mv $TMPBDIR/base?_?.tgz /tmp
212 rm -rf $TMPBDIR
213 ;;
214 /*/base?_?.tgz)
215 rm -f /tmp/base?_?.tgz
216 test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
217 ln -s $FAI_BASETGZ /tmp
218 ;;
219 *)
220 die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strong."
221 ;;
222 esac
223 }
224 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
225 umount_dirs() {
226
227 cd /
228 sleep 2
229 umount $NFSROOT/proc 1>/dev/null 2>&1 || true
230 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
231 if [ "$FAI_DEBMIRROR" ]; then
232 test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
233 fi
234 # show directories still mounted on nfsroot
235 mount | grep " on $NFSROOT " || true
236 }
237 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
238 # main routine
239
240 if [ -d $NFSROOT/fai ]; then
241 echo $NFSROOT already exists. Removing $NFSROOT
242 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
243 rm -rf $NFSROOT
244 fi
245
246 create_nfsroot
247
248 if [ -f $KERNELPACKAGE ]; then
249 # create tftp boot images
250 install_kernel_nfsroot
251 mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
252 # imggen is free software from 3com
253 # it converts netboot image to images, that are bootable by 3com network cards
254 imggen=`which imggen || true`
255 if [ -x $imggen ]; then
256 imggen -a /boot/fai/installimage /boot/fai/installimage_3com
257 fi
258 else
259 echo "Kernel package $KERNELPACKAGE not found."
260 echo "No install kernel installed in /boot/fai."
261 echo "No kernel modules available in nfsroot."
262 fi
263
264 echo make-fai-nfsroot finished.
265 exit 0

Properties

Name Value
svn:eol-style native
svn:executable *
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.5