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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1327 - (show annotations) (download)
Thu Nov 28 12:47:32 2002 UTC (10 years, 5 months ago) by lange
File size: 12315 byte(s)
correct location for syslog.conf
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/fai/syslog.log" > etc/syslog.conf
232 cat >> root/.profile <<-EOF
233 PATH=/usr/local/sbin:/usr/local/bin:/usr/lib/fai:/bin:/sbin:/usr/bin:/usr/sbin:
234 export PATH
235 . $SHAREFAI/subroutines
236 . $SHAREFAI/subroutines-$OS_TYPE
237 set -a
238 . /etc/fai/fai.conf
239 . /tmp/rcsfai.var
240 EOF
241
242 call_verbose call_with_stamp setup_ssh
243
244 cat >$NFSROOT/etc/rc2.d/S01fai_abort <<-EOF
245 #!/bin/sh
246 echo FAI: installation aborted.
247 echo reboot with: faireboot
248 echo or after a logout
249 sh
250 cd /
251 umount -ar
252 reboot -dfi
253 EOF
254 chmod a+rx $NFSROOT/etc/rc2.d/S01fai_abort
255 }
256 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
257 upgrade_nfsroot() {
258
259 cp /etc/resolv.conf $NFSROOT/etc
260 $ROOTCMD apt-get update
261 $ROOTCMD apt-get check
262 rm -rf $NFSROOT/etc/apm
263 mount -t proc /proc $NFSROOT/proc
264 $ROOTCMD apt-get --purge -y install debconf </dev/null
265
266 # fake start-stop-dameon
267 $ROOTCMD dpkg-divert --quiet --package fai --add --rename /sbin/start-stop-daemon
268 cp $LIBFAI/sbin/start-stop-daemon $NFSROOT/sbin
269 $ROOTCMD apt-get -y upgrade
270 }
271 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
272 add_packages_nfsroot() {
273
274 $ROOTCMD apt-get -y --fix-missing install $packages </dev/null
275 if [ -n "$NFSROOT_PACKAGES" ] ; then
276 $ROOTCMD apt-get -y --fix-missing install $NFSROOT_PACKAGES </dev/null
277 fi
278 $ROOTCMD apt-get clean
279 }
280 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
281 umount_dirs() {
282
283 cd /
284 sleep 2
285 umount $NFSROOT/proc 1>/dev/null 2>&1 || true
286 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
287 if [ "$FAI_DEBMIRROR" ]; then
288 test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
289 fi
290 # show directories still mounted on nfsroot
291 mount | grep " on $NFSROOT " || true
292 }
293 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
294 get_kernel_version() {
295
296 local package=$1
297 KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
298 }
299 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
300 setup_bootp(){
301
302 if [ -x "`which mknbi-linux`" ]; then
303 mknbi-linux --verbose -a "ip=both" \
304 $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
305 else
306 die "Command mknbi-linux not found. Please install the package netboot"
307 fi
308
309 # imggen is free software from 3com - use ver1.00: 1.01 produces "Image too Big" errors.
310 # it converts netboot images to images which are bootable by 3com network cards
311 if [ -x "`which imggen`" ]; then
312 imggen -a /boot/fai/installimage /boot/fai/installimage_3com
313 fi
314 echo "BOOTP environment prepared."
315 }
316
317 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
318 setup_dhcp(){
319
320 # pxe and dhcp environment
321 local pxebin=/usr/lib/syslinux/pxelinux.0
322 cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel
323 [ -f $pxebin ] && cp $pxebin /boot/fai
324 [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true
325 cp -p /usr/share/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default
326 echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"
327 }
328 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
329 # main routine
330
331 # Kill the directory if not in recover mode
332 if [ -d $NFSROOT/$FAI -a ! "$recover" ]
333 then
334 echo $NFSROOT already exists. Removing $NFSROOT
335 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
336 rm -rf $NFSROOT/.??* $NFSROOT/*
337 # also remove files $NFSROOT/.? but not . and ..
338 find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
339 fi
340
341 # Create a new nfsroot
342 call_with_stamp create_nfsroot
343
344 # Install the kernel package
345 if [ -f $KERNELPACKAGE ]; then
346 # determine kernel version
347 get_kernel_version $KERNELPACKAGE
348
349 # create tftp boot images
350 call_with_stamp install_kernel_nfsroot
351
352 # setup for both DHCP and BOOTP
353 call_with_stamp setup_dhcp
354 call_with_stamp setup_bootp
355 else
356 echo "Kernel package $KERNELPACKAGE not found."
357 echo "No install kernel installed in /boot/fai."
358 echo "No kernel modules available in nfsroot."
359 fi
360
361 echo make-fai-nfsroot finished.
362 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