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

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

Parent Directory Parent Directory | Revision Log Revision Log


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