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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1161 - (show annotations) (download)
Tue Apr 9 12:28:39 2002 UTC (11 years, 1 month ago) by lange
File size: 13159 byte(s)
set DEBIAN_FRONTEND to noninteractive
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="dhcp-client file rdate cfengine bootpc wget rsh-client less dump
33 ext2resize strace hdparm parted dnsutils grub ntpdate psmisc
34 dosfstools sysutils dialog"
35 # removed from distribution: hwtools
36
37 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
38
39 if [ "$UID" -ne 0 ]; then
40 echo "Run this program as root."
41 exit 9
42 fi
43
44 while getopts rv opt ; do
45 case "$opt" in
46 v) verbose=1 ;;
47 r) recover=1 ;;
48 esac
49 done
50
51 set -e
52 . /etc/fai/fai.conf
53
54 ROOTCMD="chroot $NFSROOT"
55
56 RUNDIR=/var/run/fai/make-nfs-root
57 [ ! -d $RUNDIR ] && mkdir -p $RUNDIR
58 [ ! "$recover" ] && rm -rf $RUNDIR/*
59
60 LIBFAI=/usr/lib/fai
61 SHAREFAI=/usr/share/fai
62 conffile=$NFSROOT/etc/rcS_fai.conf
63 export DEBIAN_FRONTEND=noninteractive
64
65 trap "umount_dirs" EXIT
66 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
67 die() {
68
69 echo "$@"
70 exit 99
71 }
72 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
73 call_with_stamp() {
74
75 local func=$1
76 local stamp=$RUNDIR/$func
77 # call subroutine
78 [ "$recover" -a -f $stamp ] && return 0
79 "$@"
80 > $stamp
81 }
82 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
83 call_verbose() {
84
85 if [ "$verbose" ]; then
86 "$@"
87 else
88 "$@" > /dev/null
89 fi
90 }
91 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92 install_kernel_nfsroot() {
93
94 rm -rf $NFSROOT/boot/*-$KERNELVERSION $NFSROOT/lib/modules/$KERNELVERSION
95 # since woody we can install the kernel using dpkg -i
96 echo "do_boot_enable=no" > $NFSROOT/etc/kernel-img.conf
97 dpkg -x $KERNELPACKAGE $NFSROOT
98 # if $NFROOT/proc/modules exists, then update-modules calls depmod -a without
99 # these special flags; so umount first
100 [ -e $NFSROOT/proc/modules ] && umount $NFSROOT/proc
101 chroot $NFSROOT update-modules
102 chroot $NFSROOT depmod -a -F /boot/System.map-$KERNELVERSION $KERNELVERSION
103 }
104 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
105 setup_ssh() {
106
107 # nothing to do if no ssh is available in nfsroot
108 [ -f $NFSROOT/var/lib/dpkg/info/ssh.list ] || return 0
109 mkdir -p -m 700 $NFSROOT/root/.ssh
110 [ -f /etc/ssh/ssh_known_hosts ] && cp /etc/ssh/ssh_known_hosts $NFSROOT/root/.ssh/known_hosts
111 if [ -n "$LOGUSER" ] ; then
112 loguserhome=`eval "cd ~$LOGUSER 2>/dev/null && pwd;true"`
113 [ -d $loguserhome/.ssh ] && cp -p $loguserhome/.ssh/identity* $NFSROOT/root/.ssh/
114 fi
115
116 # enable root login
117 perl -pi -e 's/PermitRootLogin no/PermitRootLogin yes/' $NFSROOT/etc/ssh/sshd_config
118 if [ -f "$SSH_IDENTITY" ]; then
119 cp -p $SSH_IDENTITY $NFSROOT/root/.ssh/authorized_keys
120 echo You can log into install clients without password using $SSH_IDENTITY
121 fi
122 }
123 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
124 copy_fai_files() {
125
126 # copy to nfsroot
127 perl -pi -e "s#^root::#root:${FAI_ROOTPW}:#" etc/passwd
128 mkdir -p $NFSROOT/$FAI/fai_config $NFSROOT/$SHAREFAI $NFSROOT/etc/fai
129 cd $NFSROOT
130 cp -p $LIBFAI/sbin/dhclient-script $SHAREFAI/etc/dhclient.conf etc/
131 cp -Rp /etc/fai etc/
132 [ -f /etc/fai/.cvspass ] && cp -p /etc/fai/.cvspass .cvspass
133 cp -p $LIBFAI/sbin/* sbin/
134 cp -p $SHAREFAI/etc/fai_modules_off etc/modutils/
135
136 cp -p $SHAREFAI/subroutines* usr/share/fai
137 cp -p $SHAREFAI/etc/apt.conf etc/apt
138 # potato / woody code
139 if [ -d usr/lib/perl5/Debian ]; then
140 cp -p /usr/lib/perl5/Debian/Fai.pm usr/lib/perl5/Debian/
141 else
142 cp -p /usr/share/perl5/Debian/Fai.pm usr/share/perl5/Debian/
143 fi
144 echo $NFSROOT_ETC_HOSTS >> etc/hosts
145 }
146 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
147 call_debootstrap() {
148
149 echo "Creating nfsroot for $1 using debootstrap"
150 [ "$verbose" ] && echo "calling debootstrap $1 $NFSROOT $2"
151 yes '' | debootstrap $FAI_DEBOOTSTRAP_OPTS $1 $NFSROOT $2 || true
152 }
153 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
154 create_base() {
155
156 if [ "$FAI_DEBOOTSTRAP" ]; then
157 call_verbose call_with_stamp call_debootstrap $FAI_DEBOOTSTRAP
158 $ROOTCMD apt-get clean
159 echo "Creating base.tgz"
160 tar -C $NFSROOT -cf - . | gzip > $NFSROOT/../base.tgz
161 mv $NFSROOT/../base.tgz $NFSROOT/var/tmp/base.tgz
162 else
163 # old method for potato
164 call_with_stamp get_basetgz
165 echo "Unpacking base2_2.tgz"
166 zcat /tmp/base2_2.tgz | tar -C $NFSROOT -xpf -
167 cp -p /tmp/base2_2.tgz $NFSROOT/var/tmp/base.tgz
168 fi
169 }
170 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
171 create_nfsroot() {
172
173 mkdir -p $NFSROOT/$FAI
174 cd $NFSROOT || die "Error: Can't cd to $NFSROOT"
175
176 call_with_stamp create_base
177
178 [ ! -c dev/boot255 ] && mknod dev/boot255 c 0 255
179
180 if [ "$FAI_DEBMIRROR" ]; then
181 mkdir -p $NFSROOT/$MNTPOINT
182 mount -o ro,rsize=8192 $FAI_DEBMIRROR $NFSROOT/$MNTPOINT || \
183 die "Can't mount $FAI_DEBMIRROR"
184 fi
185
186 # hoaks some packages
187 # liloconfig, dump and raidtool2 needs these files
188 echo "# UNCONFIGURED FSTAB FOR BASE SYSTEM" > etc/fstab
189 > etc/raidtab
190 mkdir -p lib/modules/$KERNELVERSION # dirty trick to hoax lvm
191 > lib/modules/$KERNELVERSION/modules.dep # dirty trick to hoax lvm
192 mkdir -p etc/ssh
193 echo 'NTPSERVERS=""' > etc/default/ntp-servers
194
195 # potato only
196 > etc/ssh/NOSERVER
197 # woody uses debconf
198
199 if [ "$FAI_SOURCES_LIST" ]; then
200 echo "$FAI_SOURCES_LIST" > etc/apt/sources.list
201 else
202 cp /etc/apt/sources.list etc/apt/sources.list
203 fi
204 [ -f /etc/apt/preferences ] && cp /etc/apt/preferences etc/apt
205 echo "Upgrading $NFSROOT"
206 call_verbose call_with_stamp upgrade_nfsroot
207 echo "Adding additional packages to $NFSROOT:"
208 echo "$packages"
209 call_verbose call_with_stamp add_packages_nfsroot
210 call_with_stamp copy_fai_files
211
212 # set timezone
213 rm -f etc/localtime
214 cp -d /etc/localtime /etc/timezone etc
215
216 # make little changes to nfsroot, because nfsroot is
217 # read only for the install clients
218 rm -rf etc/mtab var/run etc/sysconfig
219 mv etc/init.d/rcS etc/init.d/rcS.orig
220 ln -s /proc/mounts etc/mtab
221 ln -s /tmp/var/run var/run
222 ln -sf /tmp/etc/resolv.conf etc/resolv.conf
223 ln -sf /tmp etc/sysconfig
224 ln -s /sbin/rcS_fai etc/init.d/rcS
225 ln -s /dev/null etc/network/ifstate
226 # for nis
227 [ -d var/yp ] && ln -s /tmp/binding var/yp/binding
228
229 # turn off logging of loading kernel modules
230 [ -d var/log/ksymoops/ ] && rmdir var/log/ksymoops/
231 ln -s /dev/null var/log/ksymoops
232
233 # definition for loopback device
234 echo "iface lo inet loopback" > etc/network/interfaces
235
236 echo "*.* /tmp/syslog.log" > etc/syslog.conf
237 echo ". $SHAREFAI/subroutines" >> root/.profile
238 echo ". $SHAREFAI/subroutines-$OSTYPE" >> root/.profile
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 get_basetgz() {
280
281 [ -f /tmp/base2_2.tgz ] && return
282 [ "$FAI_BASETGZ" ] || die "No /tmp/base2_2.tgz found and FAI_BASETGZ not defined."
283 case $FAI_BASETGZ in
284 ftp:*|http:*)
285 echo "Fetching $FAI_BASETGZ via wget. This may take some time."
286 TMPBDIR=`mktemp /tmp/FAI-wget-XXXXXX` || exit 1
287 rm $TMPBDIR; mkdir $TMPBDIR || exit
288 wget -P$TMPBDIR $FAI_BASETGZ
289 mv $TMPBDIR/base2_2.tgz /tmp
290 rm -rf $TMPBDIR
291 ;;
292 /*/base2_2.tgz)
293 rm -f /tmp/base2_2.tgz
294 test -r $FAI_BASETGZ || die "Can't read $FAI_BASETGZ. Check FAI_BASETGZ in fai.conf."
295 ln -s $FAI_BASETGZ /tmp
296 ;;
297 *)
298 die "FAI_BASETGZ in fai.conf is $FAI_BASETGZ and looks very strange."
299 ;;
300 esac
301 }
302 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303 umount_dirs() {
304
305 cd /
306 sleep 2
307 umount $NFSROOT/proc 1>/dev/null 2>&1 || true
308 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 ||true
309 if [ "$FAI_DEBMIRROR" ]; then
310 test -d $NFSROOT/$MNTPOINT && umount $NFSROOT/$MNTPOINT || true
311 fi
312 # show directories still mounted on nfsroot
313 mount | grep " on $NFSROOT " || true
314 }
315 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
316 get_kernel_version() {
317
318 local package=$1
319 KERNELVERSION=`dpkg --info $1 | grep "Package: kernel-image" | sed -e 's/.*kernel-image-'//`
320 }
321 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
322 setup_bootp(){
323
324 mknbi-linux --verbose $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installimage
325 # imggen is free software from 3com
326 # it converts netboot image to images, that are bootable by 3com network cards
327 imggen=`which imggen || true`
328 if [ -x "$imggen" ]; then
329 imggen -a /boot/fai/installimage /boot/fai/installimage_3com
330 fi
331 echo "BOOTP environment prepared."
332 }
333
334 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
335 setup_dhcp(){
336
337 # pxe and dhcp environment
338 cp -p $NFSROOT/boot/vmlinuz-$KERNELVERSION /boot/fai/installkernel
339 rdev /boot/fai/installkernel $NFSROOT/dev/boot255
340 [ -f /usr/lib/syslinux/pxelinux.bin ] && cp /usr/lib/syslinux/pxelinux.bin /boot/fai
341 [ -d /boot/fai/pxelinux.cfg ] || mkdir /boot/fai/pxelinux.cfg || true
342 cp -p /usr/share/fai/etc/pxelinux.cfg /boot/fai/pxelinux.cfg/default
343 echo "DHCP environment prepared. Now enable dhcpd and the special tftp daemon"
344 }
345 # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
346 # main routine
347
348 # Kill the directory if not in recover mode
349 if [ -d $NFSROOT/$FAI -a ! "$recover" ]
350 then
351 echo $NFSROOT already exists. Removing $NFSROOT
352 umount $NFSROOT/dev/pts 1>/dev/null 2>&1 || true
353 rm -rf $NFSROOT/.??* $NFSROOT/*
354 # also remove files $NFSROOT/.? but not . and ..
355 find $NFSROOT ! -type d -xdev -maxdepth 1 | xargs -r rm -f
356 fi
357
358 # Create a new nfsroot
359 call_with_stamp create_nfsroot
360
361 # Install the kernel package
362 if [ -f $KERNELPACKAGE ]; then
363 # determine kernel version
364 get_kernel_version $KERNELPACKAGE
365
366 # create tftp boot images
367 call_with_stamp install_kernel_nfsroot
368
369 grep -q _dhcp_ $NFSROOT/boot/System.map-$KERNELVERSION && TYPE=DHCP
370 # only BOOTP need a netboot image, DHCP can do with raw kernels
371 if [ "$TYPE" = DHCP ]; then
372 call_with_stamp setup_dhcp
373 else
374 call_with_stamp setup_bootp
375 fi
376 else
377 echo "Kernel package $KERNELPACKAGE not found."
378 echo "No install kernel installed in /boot/fai."
379 echo "No kernel modules available in nfsroot."
380 fi
381
382 echo make-fai-nfsroot finished.
383 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