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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1316 - (show annotations) (download)
Wed Nov 27 15:52:24 2002 UTC (10 years, 5 months ago) by lange
Original Path: trunk/scripts/make-fai-nfsroot
File size: 12209 byte(s)
remove packages that are already included
do not call rdev, do not make boot255 device
new options for mknbi-linux
always do setup for dhcp and bootp
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-2002 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 Additional packages are
31 # defined with $NFSROOT_PACKAGES in fai.conf
32 packages="portmap file rdate cfengine bootpc wget rsh-client less dump
33 ext2resize strace hdparm parted dnsutils grub ntpdate
34 dosfstools sysutils dialog libdetect0 discover mdetect read-edid kudzu hwtools"
35
36 PATH=/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin
37
38 if [ `id -u` -ne 0 ]; then
39 echo "Run this program as root."
40 exit 9
41 fi
42
43 while getopts rv opt ; do
44 case "$opt" in
45 v) verbose=1 ;;
46 r) recover=1 ;;
47 esac
48 done
49
50 set -e
51 . /etc/fai/fai.conf
52
53 ROOTCMD="chroot $NFSROOT"
54
55 RUNDIR=/var/run/fai/make-nfs-root
56 [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
57 [ ! "$recover" ] && rm -rf $RUNDIR/*
58
59 LIBFAI=/usr/lib/fai
60 SHAREFAI=/usr/share/fai
61 conffile=$NFSROOT/etc/rcS_fai.conf
62 export DEBIAN_FRONTEND=noninteractive
63
64 trap "umount_dirs" EXIT
65 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66 die() {
67
68 echo "$@"
69 exit 99
70 }
71 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
72 call_with_stamp() {
73
74 local func=$1
75 local stamp=$RUNDIR/$func
76 # call subroutine
77 [ "$recover" -a -f $stamp ] && return 0
78 "$@"
79 > $stamp
80 }
81 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82 call_verbose() {
83
84 if [ "$verbose" ]; then
85 "$@"
86 else
87 "$@" > /dev/null
88 fi
89 }
90 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
91 install_kernel_nfsroot() {
92
93 rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
94 # since woody we can install the kernel using dpkg -i
95 echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
96 dpkg -x $KERNELPACKAGE $NFSROOT
97 # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
98 # these special flags; so umount first
99 [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc
100 chroot $NFSROOT update-modules
101 chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
102 }
103 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
104 setup_ssh() {
105
106 # nothing to do if no ssh is available in nfsroot
107 [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
108 mkdir -p -m 700 $NFSROOT/root/.ssh
109 [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts
110 if [ -n "$LOGUSER" ] ; then
111 loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
112 # is copying of *.pub important?
113 [ -d $loguserhome/.ssh ] && {
114 [ -f $loguserhome/.ssh/id_dsa ] &&
115 cp -p $loguserhome/.ssh/id_dsa* $NFSROOT/root/.ssh/
116 [ -f $loguserhome/.ssh/id_rsa ] &&
117 cp -p $loguserhome/.ssh/id_rsa* $NFSROOT/root/.ssh/
118 cp -p $loguserhome/.ssh/*.pub $NFSROOT/root/.ssh/
119 }
120 fi
121
122 # enable root login
123 perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
124 if [ -f "$SSH_IDENTITY" ]; then
125 cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
126 echo You can log into install clients without password using $SSH_IDENTITY
127 fi
128 }
129 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130 copy_fai_files() {
131
132 # copy to nfsroot
133 perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd
134 mkdir -p $NFSROOT/$FAI/fai_config $NFSROOT/$SHAREFAI $NFSROOT/$LIBFAI $NFSROOT/etc/fai
135 cd $NFSROOT
136 cp -p $SHAREFAI/etc/dhclient.conf etc/
137 ln -fs ../sbin/dhclient-script etc/dhclient-script
138 cp -Rp /etc/fai etc/
139 [ -f /etc/fai/.cvspass ] && cp -p /etc/fai/.cvspass .cvspass
140 cp -p $LIBFAI/sbin/* sbin/
141 cp -p $LIBFAI/* usr/lib/fai 2>/dev/null || true # cp will complain about directories
142 cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/
143
144 cp -p $SHAREFAI/subroutines* usr/share/fai
145 cp -p $SHAREFAI/etc/apt.conf etc/apt
146 cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/
147 echo $NFSROOT_ETC_HOSTS >> etc/hosts
148 }
149 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
150 call_debootstrap() {
151
152 echo "Creating nfsroot for $1 using debootstrap"
153 [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"
154 yes '' | debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true
155 }
156 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
157 create_base() {
158
159 if [ "$FAI_DEBOOTSTRAP" ]; then
160 call_verbose call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
161 $ROOTCMD apt-get clean
162 echo "Creating base.tgz"
163 tar -l -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz
164 mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz
165 else
166 die "\$FAI_DEBOOTSTRAP not defined."
167 fi
168 }
169 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
170 create_nfsroot() {
171
172 mkdir -p $NFSROOT/$FAI
173 cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
174
175 call_with_stamp create_base
176
177 if [ "$FAI_DEBMIRROR" ]; then
178 mkdir -p $NFSROOT/$MNTPOINT
179 mount -o ro,noatime,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
180 die "Can't mount $FAI_DEBMIRROR"
181 fi
182
183 # hoaks some packages
184 # liloconfig, dump and raidtool2 needs these files
185 echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
186 > etc/raidtab
187 mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
188 > lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
189
190 echo 'NTPSERVERS=""' > etc/default/ntp-servers
191
192 # woody uses debconf
193
194 if [ "$FAI_SOURCES_LIST" ]; then
195 echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
196 else
197 cp /etc/apt/sources.list etc/apt/sources.list
198 fi
199 [ -f /etc/apt/preferences ] && cp /etc/apt/preferences etc/apt
200 echo "Upgrading $NFSROOT"
201 call_verbose call_with_stamp upgrade_nfsroot
202 echo "Adding additional packages to $NFSROOT:"
203 echo "$packages"
204 call_verbose call_with_stamp add_packages_nfsroot
205 call_with_stamp copy_fai_files
206
207 # set timezone
208 rm -f etc/localtime
209 cp -d /etc/localtime /etc/timezone etc
210
211 # make little changes to nfsroot, because nfsroot is
212 # read only for the install clients
213 rm -rf etc/mtab var/run etc/sysconfig
214 mv etc/init.d/rcS etc/init.d/rcS.orig
215 ln -s /proc/mounts etc/mtab
216 ln -s /tmp/var/run var/run
217 ln -sf /tmp/etc/resolv.conf etc/resolv.conf
218 ln -sf /tmp etc/sysconfig
219 ln -s ../../sbin/rcS_fai etc/init.d/rcS
220 ln -s /dev/null etc/network/ifstate
221 # for nis
222 [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
223
224 # turn off logging of loading kernel modules
225 [ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/
226 ln -s /dev/null var/log/ksymoops
227
228 # definition for loopback device
229 echo "iface lo inet loopback" > etc/network/interfaces
230
231 echo "*.* /tmp/syslog.log" > etc/syslog.conf
232 cat >> root/.profile <<-EOF
233 . $SHAREFAI/subroutines
234 . $SHAREFAI/subroutines-$OS_TYPE
235 set -a
236 . /etc/fai/fai.conf
237 . /tmp/rcsfai.var
238 EOF
239
240 call_verbose call_with_stamp setup_ssh
241
242 cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
243 #!/bin/sh
244 echo FAI: installation aborted.
245 echo reboot with: faireboot
246 echo or after a logout
247 sh
248 cd /
249 umount -ar
250 reboot -dfi
251 EOF
252 chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
253 }
254 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
255 upgrade_nfsroot() {
256
257 cp /etc/resolv.conf $NFSROOT/etc
258 $ROOTCMD apt-get update
259 $ROOTCMD apt-get check
260 rm -rf $NFSROOT/etc/apm
261 mount -t proc /proc $NFSROOT/proc
262 $ROOTCMD apt-get --purge -y install debconf </dev/null
263
264 # fake start-stop-dameon
265 $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
266 cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
267 $ROOTCMD apt-get -y upgrade
268 }
269 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
270 add_packages_nfsroot() {
271
272 $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
273 if [ -n "$NFSROOT_PACKAGES" ] ; then
274 $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null
275 fi
276 $ROOTCMD apt-get clean
277 }
278 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
279 umount_dirs() {
280
281 cd /
282 sleep 2
283 umount $NFSROOT/proc 1>/dev/null 2>&1 || true
284 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
285 if [ "$FAI_DEBMIRROR" ]; then
286 test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
287 fi
288 # show directories still mounted on nfsroot
289 mount | grep " on $NFSROOT " || true
290 }
291 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
292 get_kernel_version() {
293
294 local package=$1
295 KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
296 }
297 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
298 setup_bootp(){
299
300 if [ -x "`which mknbi-linux`" ]; then
301 mknbi-linux --verbose -d /dev/nfs -i rom \
302 $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
303 else
304 die "Command mknbi-linux not found. Please install the package netboot"
305 fi
306
307 # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
308 # it converts netboot images to images which are bootable by 3com network cards
309 if [ -x "`which imggen`" ]; then
310 imggen -a /boot/fai/installimage /boot/fai/installimage_3com
311 fi
312 echo "BOOTP environment prepared."
313 }
314
315 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 setup_dhcp(){
317
318 # pxe and dhcp environment
319 local pxebin=/usr/lib/syslinux/pxelinux.0
320 cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel
321 [ -f $pxebin ] && cp $pxebin /boot/fai
322 [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true
323 cp -p /usr/share/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default
324 echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"
325 }
326 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
327 # main routine
328
329 # Kill the directory if not in recover mode
330 if [ -d $NFSROOT/$FAI -a ! "$recover" ]
331 then
332 echo $NFSROOT already exists. Removing $NFSROOT
333 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
334 rm -rf $NFSROOT/.??* $NFSROOT/*
335 # also remove files $NFSROOT/.? but not . and ..
336 find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
337 fi
338
339 # Create a new nfsroot
340 call_with_stamp create_nfsroot
341
342 # Install the kernel package
343 if [ -f $KERNELPACKAGE ]; then
344 # determine kernel version
345 get_kernel_version $KERNELPACKAGE
346
347 # create tftp boot images
348 call_with_stamp install_kernel_nfsroot
349
350 # setup for both DHCP and BOOTP
351 call_with_stamp setup_dhcp
352 call_with_stamp setup_bootp
353 else
354 echo "Kernel package $KERNELPACKAGE not found."
355 echo "No install kernel installed in /boot/fai."
356 echo "No kernel modules available in nfsroot."
357 fi
358
359 echo make-fai-nfsroot finished.
360 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