· 8 years ago · May 18, 2018, 06:06 PM
1#!/bin/sh
2#
3# "SystemImager"
4#
5# $Id: autoinstallscript.template 4315 2007-10-30 21:10:44Z arighi $
6# vi:set filetype=sh:
7#
8# Copyright (C) 1999-2006 Brian Elliott Finley
9#
10# 28.07.2005 Erich Focht : SCSI device detection and generation of
11# /a/etc/systemconfig/hardware.lst
12#
13# David N. Lombard : Disks enumeration and disk editing
14#
15
16# This master autoinstall script was created with SystemImager v4.0.2
17
18# Pull in variables left behind by the linuxrc script.
19# This information is passed from the linuxrc script on the autoinstall media
20# via /tmp/variables.txt. Apparently the shell we use in BOEL is not
21# intelligent enough to take a "set -a" parameter.
22#
23. /tmp/variables.txt
24
25# Load functions and other variables
26. /etc/init.d/functions
27
28get_arch
29
30NO_LISTING=yes
31if [ -z $NO_LISTING ]; then
32 VERBOSE_OPT="v"
33else
34 VERBOSE_OPT=""
35fi
36
37[ -z $IMAGENAME ] && IMAGENAME=vps-base-i386
38[ -z $OVERRIDES ] && OVERRIDES="vps-base-i386 $GROUP_OVERRIDES $HOSTNAME "
39
40### BEGIN Check to be sure this not run from a working machine ###
41# Test for mounted SCSI or IDE disks
42mount | grep [hs]d[a-z][1-9] > /dev/null 2>&1
43[ $? -eq 0 ] && logmsg Sorry. Must not run on a working machine... && shellout
44
45# Test for mounted software RAID devices
46mount | grep md[0-9] > /dev/null 2>&1
47[ $? -eq 0 ] && logmsg Sorry. Must not run on a working machine... && shellout
48
49# Test for mounted hardware RAID disks
50mount | grep c[0-9]+d[0-9]+p > /dev/null 2>&1
51[ $? -eq 0 ] && logmsg Sorry. Must not run on a working machine... && shellout
52### END Check to be sure this not run from a working machine ###
53
54
55################################################################################
56#
57# Stop RAID devices before partitioning begins
58#
59# Q1) Why did they get started in the first place?
60# A1) So we can pull a local.cfg file off a root mounted software RAID system.
61# They may not be started on your system -- they would only be started if
62# you did the stuff in Q3 below.
63#
64# Q2) Why didn't my local.cfg on my root mounted software RAID work for me
65# with the standard kernel flavour?
66# A2) The standard kernel flavour uses modules for the software RAID drivers --
67# therefore, software RAID is not available at the point in the boot process
68# where BOEL needs to read the local.cfg file. They are only pulled over
69# when this script is run, which is, of course, only runnable if it was
70# pulled over the network using the settings that you would have wanted it
71# to get from the local.cfg file, which it couldn't. Right?
72#
73# Q3) Whatever. So how do I make it work with a local.cfg file on my root
74# mounted software RAID?
75# A3) Compile an autoinstall kernel with software RAID, and any other drivers
76# you might need built in (filesystem, SCSI drivers, etc.).
77#
78if [ -f /proc/mdstat ]; then
79 RAID_DEVICES=` cat /proc/mdstat | grep ^md | sed 's/ .*$//g' `
80
81 # Turn dem pesky raid devices off!
82 for RAID_DEVICE in ${RAID_DEVICES}
83 do
84 DEV="/dev/${RAID_DEVICE}"
85 logmsg "mdadm --manage ${DEV} --stop"
86 mdadm --manage ${DEV} --stop
87 done
88fi
89#
90################################################################################
91# BEGIN disk enumeration
92#
93# Note the kludgey way to get /dev/sd* and /dev/*/c*d* to sort properly...
94#
95# Parse the correct file depending by the kernel release -AR-
96kernel=`uname -r | sed "s/^\(2\.[64]\).*/\1/"`
97if [ $kernel = "2.4" ]; then
98 diskfile=/proc/partitions
99else
100 diskfile=/proc/diskstats
101fi
102
103DISKORDER=
104
105[ -z $DISKORDER ] || {
106 logmsg enumerate_disks
107 order=`echo "$DISKORDER" | sed 's/ /,/g' | sed s/,,*/,/g | sed s/^,//`
108 DISKS=0
109 cdroms=`cat /proc/sys/dev/cdrom/info 2>/dev/null | sed -ne "s/^drive name:[[:space:]]*//p"`
110 while : ; do
111 [ -z $order ] && break
112 type=`expr $order : '\([^,]*\),' \| $order`
113 case $type in
114 cciss | ida | rd )
115 for dev in `cat $diskfile | sed -ne "s/.*\($type\\/c[0-9]d[0-9]\).*/\1/p" | sort -u` ; do
116 logmsg " $dev"
117 eval DISK$DISKS=/dev/${dev}
118 DISKS=`expr $DISKS + 1`
119 done
120 ;;
121 hd | sd )
122 for dev in `cat $diskfile | sed -ne "s/.*\($type[a-z]\+\).*/\1/p" | sort -u` ; do
123 skip=0
124 for cdrom in $cdroms; do
125 if [ "$dev" = "$cdrom" ]; then
126 skip=1
127 break
128 fi
129 done
130 if [ $skip -eq 0 ]; then
131 logmsg " $dev"
132 eval DISK$DISKS=/dev/${dev}
133 DISKS=`expr $DISKS + 1`
134 fi
135 done
136 ;;
137 * )
138 logmsg "type='$type'"
139 shellout
140 ;;
141 esac
142 order=`expr $order : '[^,]*,\(.*\)'`
143 done
144 logmsg DISKS=$DISKS
145 [ $DISKS -eq 0 ] && {
146 beep
147 beep
148 logmsg ""
149 logmsg "NO DISK DEVICE FILES WERE FOUND. THIS USUALLY MEANS THE KERNEL DID NOT"
150 logmsg "RECOGNIZE ANY OF THE ATTACHED DISKS."
151 logmsg ""
152 logmsg "The kernel boot messages, which preceded this, may indicate why."
153 logmsg ""
154 logmsg "Reverting to disk configuration specified by image master script."
155 DISKORDER=
156 logmsg ""
157 }
158 echo
159 beep
160}
161#
162# END disk enumeration
163################################################################################
164
165if [ -z $DISKORDER ] ; then
166 DISK0=/dev/sda
167elif [ -z $DISK0 ] ; then
168 echo "Undefined: DISK0"
169 shellout
170fi
171### BEGIN partition $DISK0 ###
172logmsg "Partitioning $DISK0..."
173logmsg "Old partition table for $DISK0:"
174parted -s -- $DISK0 print
175
176# Wipe the MBR (Master Boot Record) clean.
177logmsg "dd if=/dev/zero of=$DISK0 bs=512 count=1 || shellout"
178dd if=/dev/zero of=$DISK0 bs=512 count=1 || shellout
179
180# Re-read the disk label.
181logmsg "blockdev --rereadpt $DISK0"
182blockdev --rereadpt $DISK0
183
184# Create disk label. This ensures that all remnants of the old label, whatever
185# type it was, are removed and that we're starting with a clean label.
186logmsg "parted -s -- $DISK0 mklabel msdos || shellout"
187parted -s -- $DISK0 mklabel msdos || shellout
188
189# Get the size of the destination disk so that we can make the partitions fit properly.
190DISK_SIZE=`parted -s $DISK0 unit MB print | grep 'Disk geometry for' | sed 's/^.*-//g' | sed 's/\..*$//' | sed 's/MB//' `
191[ -z $DISK_SIZE ] && shellout
192if [ "$ARCH" = "alpha" ]; then
193 END_OF_LAST_PRIMARY=1
194else
195 END_OF_LAST_PRIMARY=0
196fi
197
198
199logmsg "Creating partition ${DISK0}1."
200START_MB=$END_OF_LAST_PRIMARY
201END_MB=$(echo "scale=3; ($START_MB + 101)" | bc)
202logmsg "parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout"
203parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout
204END_OF_LAST_PRIMARY=$END_MB
205logmsg parted -s -- $DISK0 set 1 boot on || shellout
206parted -s -- $DISK0 set 1 boot on || shellout
207
208logmsg "Creating partition ${DISK0}2."
209START_MB=$END_OF_LAST_PRIMARY
210END_MB=$(echo "scale=3; ($START_MB + 16003)" | bc)
211logmsg "parted -s -- $DISK0 mkpart primary linux-swap $START_MB $END_MB || shellout"
212parted -s -- $DISK0 mkpart primary linux-swap $START_MB $END_MB || shellout
213END_OF_LAST_PRIMARY=$END_MB
214
215logmsg "Creating partition ${DISK0}3."
216START_MB=$END_OF_LAST_PRIMARY
217END_MB=$(echo "scale=3; ($START_MB + 10001)" | bc)
218logmsg "parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout"
219parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout
220END_OF_LAST_PRIMARY=$END_MB
221
222logmsg "Creating partition ${DISK0}4."
223START_MB=$END_OF_LAST_PRIMARY
224END_MB=$(( $DISK_SIZE - 0 ))
225logmsg "parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout"
226parted -s -- $DISK0 mkpart primary $START_MB $END_MB || shellout
227END_OF_LAST_PRIMARY=$END_MB
228
229logmsg "New partition table for $DISK0:"
230logmsg "parted -s -- $DISK0 print"
231parted -s -- $DISK0 print
232### END partition $DISK0 ###
233
234
235
236### BEGIN software-RAID initialization commands -AR- ###
237logmsg "Load software RAID modules."
238modprobe linear
239modprobe raid0
240modprobe raid1
241modprobe raid5
242modprobe raid6
243modprobe raid10
244### END software-RAID initialization commands ###
245
246logmsg "Load device mapper driver (for LVM)."
247modprobe dm-mod
248
249### BEGIN LVM initialization commands -AR- ###
250### END LVM initialization commands ###
251
252### BEGIN LVM groups creation commands -AR- ###
253### END LVM groups creation commands ###
254
255### BEGIN LVM volumes creation commands -AR- ###
256### END LVM volumes creation commands ###
257
258logmsg "Load additional filesystem drivers."
259modprobe ext2
260modprobe ext3
261modprobe fat
262modprobe jfs
263modprobe reiserfs
264modprobe vfat
265modprobe xfs
266
267### BEGIN swap and filesystem creation commands ###
268logmsg "mkswap -v1 ${DISK0}2 -L SWAP-sda2 || shellout"
269mkswap -v1 ${DISK0}2 -L SWAP-sda2 || shellout
270logmsg "swapon ${DISK0}2 || shellout"
271swapon ${DISK0}2 || shellout
272
273logmsg "mke2fs -q -j ${DISK0}3 || shellout"
274mke2fs -q -j ${DISK0}3 || shellout
275logmsg "tune2fs -L / ${DISK0}3"
276tune2fs -L / ${DISK0}3
277logmsg "mkdir -p /a/ || shellout"
278mkdir -p /a/ || shellout
279logmsg "mount ${DISK0}3 /a/ -t ext3 -o defaults || shellout"
280mount ${DISK0}3 /a/ -t ext3 -o defaults || shellout
281
282logmsg "mke2fs -q -j ${DISK0}4 || shellout"
283mke2fs -q -j ${DISK0}4 || shellout
284logmsg "tune2fs -L /vz ${DISK0}4"
285tune2fs -L /vz ${DISK0}4
286logmsg "mkdir -p /a/vz || shellout"
287mkdir -p /a/vz || shellout
288logmsg "mount ${DISK0}4 /a/vz -t ext3 -o defaults || shellout"
289mount ${DISK0}4 /a/vz -t ext3 -o defaults || shellout
290
291logmsg "mke2fs -q -j ${DISK0}1 || shellout"
292mke2fs -q -j ${DISK0}1 || shellout
293logmsg "tune2fs -L /boot ${DISK0}1"
294tune2fs -L /boot ${DISK0}1
295logmsg "mkdir -p /a/boot || shellout"
296mkdir -p /a/boot || shellout
297logmsg "mount ${DISK0}1 /a/boot -t ext3 -o defaults || shellout"
298mount ${DISK0}1 /a/boot -t ext3 -o defaults || shellout
299
300### END swap and filesystem creation commands ###
301
302### BEGIN mount proc in image for tools like System Configurator ###
303logmsg "mkdir -p /a/proc || shellout"
304mkdir -p /a/proc || shellout
305logmsg "mount proc /a/proc -t proc -o defaults || shellout"
306mount proc /a/proc -t proc -o defaults || shellout
307### END mount proc in image for tools like System Configurator ###
308
309if [ ! $kernel = "2.4" ]; then
310### BEGIN mount sysfs in image for tools that might be run during chroot ###
311logmsg "mkdir -p /a/sys || shellout"
312mkdir -p /a/sys || shellout
313logmsg "mount sysfs /a/sys -t sysfs -o defaults || shellout"
314mount sysfs /a/sys -t sysfs -o defaults || shellout
315### END mount sysfs in image for tools that might be run during chroot ###
316fi
317
318################################################################################
319#
320# Lay the image down on the freshly formatted disk(s)
321#
322if [ ! -z $MONITOR_SERVER ]; then
323 start_report_task
324fi
325
326if [ ! -z $FLAMETHROWER_DIRECTORY_PORTBASE ]; then
327
328 # Use multicast
329 MODULE_NAME="${IMAGENAME}"
330 DIR=/a
331 RETRY=7
332 FLAMETHROWER_TARPIPE=y
333 flamethrower_client
334 if [ ! -z $MONITOR_SERVER ]; then
335 stop_report_task 101
336 fi
337elif [ "x$BITTORRENT" = "xy" ]; then
338 # Use BitTorrent
339 if [ -f "${TORRENTS_DIR}/image-${IMAGENAME}.tar.gz.torrent" ]; then
340 bittorrent_tarball="image-${IMAGENAME}.tar.gz"
341 compress='z'
342 elif [ -f "${TORRENTS_DIR}/image-${IMAGENAME}.tar.torrent" ]; then
343 bittorrent_tarball="image-${IMAGENAME}.tar"
344 compress=''
345 else
346 logmsg "error: cannot find a valid torrent file for the image ${IMAGENAME}"
347 shellout
348 fi
349 # Evaluate the staging directory
350 if [ -z $BITTORRENT_STAGING ]; then
351 logmsg bittorrent_autodetect_staging_dir
352 BITTORRENT_STAGING=`bittorrent_autodetect_staging_dir ${TORRENTS_DIR}/${bittorrent_tarball}.torrent`
353 if [ -z $BITTORRENT_STAGING ]; then
354 logmsg ""
355 logmsg "error: cannot find a staging directory to save file: $bittorrent_tarball"
356 logmsg "Try to increase the size of a partition (like /tmp) in your patitioning schema"
357 logmsg "to fit the image into a staging directory."
358 logmsg ""
359 shellout
360 fi
361 logmsg "--> staging in: $BITTORRENT_STAGING"
362 fi
363 # Download image from peers
364 logmsg "Start downloading image using torrent ${bittorrent_tarball}.torrent"
365 logmsg ""
366 logmsg "--> INFO: remember to start /etc/init.d/systemimager-server-bittorrent on the image server!"
367 logmsg ""
368 bittorrent_get_file ${TORRENTS_DIR}/${bittorrent_tarball}.torrent ${BITTORRENT_STAGING}
369 if [ ! -z $MONITOR_SERVER ]; then
370 stop_report_task 101
371 fi
372 # Extract image.
373 logmsg "Extracting image from ${bittorrent_tarball} ..."
374 (cd /a/ && tar -x${VERBOSE_OPT}${compress}Spf ${BITTORRENT_STAGING}/${bittorrent_tarball} > /dev/console) || shellout
375
376 # Stop BitTorrent client.
377 bittorrent_stop
378 rm -f ${BITTORRENT_STAGING}/${bittorrent_tarball}
379 unset bittorrent_tarball
380else
381 # Use rsync
382 if [ $NO_LISTING ]; then
383 logmsg "Quietly installing image... "
384 start_spinner
385 fi
386 if [ "${TMPFS_STAGING}" = "yes" ]; then
387
388 # Deposit image into tmpfs
389 DIR=/tmp/tmpfs_staging
390 logmsg
391 logmsg "TMPFS_STAGING=${TMPFS_STAGING} -- Staging in ${DIR}"
392 mkdir -p ${DIR}
393
394 logmsg "rsync -aHS${VERBOSE_OPT} --exclude=lost+found/ --numeric-ids ${IMAGESERVER}::${IMAGENAME}/ ${DIR}/"
395 rsync -aHS${VERBOSE_OPT} --exclude=lost+found/ --exclude=/proc/* --numeric-ids \
396 ${IMAGESERVER}::${IMAGENAME}/ ${DIR}/ > /dev/console || shellout
397
398 if [ ! -z $MONITOR_SERVER ]; then
399 stop_report_task 101
400 fi
401
402 # Move from staging in tmpfs to disk
403 rsync -aHS${VERBOSE_OPT} --exclude=lost+found/ --numeric-ids ${DIR}/ /a/ > /dev/console || shellout
404 else
405 logmsg "rsync -aHS${VERBOSE_OPT} --exclude=lost+found/ --exclude=/proc/* --numeric-ids ${IMAGESERVER}::${IMAGENAME}/ /a/"
406 rsync -aHS${VERBOSE_OPT} --exclude=lost+found/ --exclude=/proc/* --numeric-ids ${IMAGESERVER}::${IMAGENAME}/ /a/ > /dev/console || shellout
407 if [ ! -z $MONITOR_SERVER ]; then
408 stop_report_task 101
409 fi
410 fi
411fi
412
413beep
414
415#
416################################################################################
417
418
419if [ $NO_LISTING ]; then
420 stop_spinner
421fi
422
423# Leave notice of which image is installed on the client
424echo $IMAGENAME > /a/etc/systemimager/IMAGE_LAST_SYNCED_TO || shellout
425
426### BEGIN generate new fstab file from autoinstallscript.conf ###
427cat <<'EOF' > /a/etc/fstab
428# HEADER: This file was autogenerated at Wed Jun 11 11:51:16 -0400 2008
429# HEADER: by puppet. While it can still be managed manually, it
430# HEADER: is definitely not recommended.
431LABEL=/ / ext3 defaults 1 1 # /dev/sda3
432LABEL=/vz /vz ext3 defaults 1 2 # /dev/sda4
433LABEL=/boot /boot ext3 defaults 1 2 # /dev/sda1
434tmpfs /dev/shm tmpfs defaults 0 0
435devpts /dev/pts devpts gid=5,mode=620 0 0
436sysfs /sys sysfs defaults 0 0
437proc /proc proc defaults 0 0
438LABEL=SWAP-sda2 swap swap defaults 0 0 # /dev/sda2
439vpuppet01.eigvps.net:/var/logins /home/logins nfs nfsvers=3,rsize=32768,wsize=32768,noatime,exec,dev,nosuid,rw,bg,hard,intr 0 0
440vpuppet01.eigvps.net:/var/tools /tools nfs nfsvers=3,rsize=32768,wsize=32768,noatime,exec,dev,nosuid,ro,bg,hard,intr 0 0
441EOF
442### END generate new fstab file from autoinstallscript.conf ###
443
444################################################################################
445#
446# Process override directories
447#
448for OVERRIDE in $OVERRIDES
449do
450 if [ ! -z $FLAMETHROWER_DIRECTORY_PORTBASE ]; then
451 # Use multicast
452 MODULE_NAME="override_${OVERRIDE}"
453 DIR=/a
454 RETRY=7
455 FLAMETHROWER_TARPIPE=y
456 flamethrower_client
457 elif [ "x$BITTORRENT" = "xy" ]; then
458 # Use BitTorrent
459 if [ -f "${TORRENTS_DIR}/override-${OVERRIDE}.tar.gz.torrent" ]; then
460 bittorrent_tarball="override-${OVERRIDE}.tar.gz"
461 compress='z'
462 elif [ -f "${TORRENTS_DIR}/override-${OVERRIDE}.tar.torrent" ]; then
463 bittorrent_tarball="override-${OVERRIDE}.tar"
464 compress=''
465 else
466 bittorrent_tarball=""
467 logmsg "warning: cannot find a valid torrent file for override ${OVERRIDE}"
468 fi
469 # Evaluate the staging directory
470 if [ ! -z $bittorrent_tarball ] && [ -z $BITTORRENT_STAGING ]; then
471 logmsg bittorrent_autodetect_staging_dir
472 BITTORRENT_STAGING=`bittorrent_autodetect_staging_dir ${TORRENTS_DIR}/${bittorrent_tarball}.torrent`
473 if [ -z $BITTORRENT_STAGING ]; then
474 logmsg "warning: cannot find a staging directory to save file: $bittorrent_tarball"
475 bittorrent_tarball=""
476 fi
477 logmsg "--> staging in: $BITTORRENT_STAGING"
478 fi
479 if [ ! -z $bittorrent_tarball ]; then
480 # Start downloading
481 logmsg "Start downloading override using torrent ${bittorrent_tarball}.torrent"
482 logmsg ""
483 logmsg "--> INFO: remember to start /etc/init.d/systemimager-server-bittorrent on the image server!"
484 logmsg ""
485 # Download override from peers
486 bittorrent_get_file ${TORRENTS_DIR}/${bittorrent_tarball}.torrent ${BITTORRENT_STAGING}
487 # Extract override.
488 logmsg "Extracting override from ${bittorrent_tarball} ..."
489 (cd /a/ && tar -x${VERBOSE_OPT}${compress}Spf ${BITTORRENT_STAGING}/${bittorrent_tarball} > /dev/console) || shellout
490 # Stop BitTorrent client.
491 bittorrent_stop
492 rm -f ${BITTORRENT_STAGING}/${bittorrent_tarball}
493 else
494 # Use rsync
495 logmsg "trying to download override ${OVERRIDE} with rsync..."
496 logmsg "rsync -aIv --numeric-ids $IMAGESERVER::overrides/$OVERRIDE/ /a/"
497 rsync -av --numeric-ids $IMAGESERVER::overrides/$OVERRIDE/ /a/ > /dev/console || logmsg "Override directory $OVERRIDE doesn't seem to exist, but that may be OK."
498 fi
499 unset bittorrent_tarball
500 else
501 # Use rsync
502 logmsg "rsync -av --numeric-ids $IMAGESERVER::overrides/$OVERRIDE/ /a/"
503 rsync -av --numeric-ids $IMAGESERVER::overrides/$OVERRIDE/ /a/ > /dev/console || logmsg "Override directory $OVERRIDE doesn't seem to exist, but that may be OK."
504 fi
505done
506
507beep
508
509#
510################################################################################
511
512################################################################################
513# BEGIN disk edits
514#
515[ -z $DISKORDER ] || {
516 echo "Editing files for actual disk configuration..."
517 echo " /dev/sda -> $DISK0"
518 for file in /etc/fstab /etc/systemconfig/systemconfig.conf /boot/grub/menu.lst /etc/lilo.conf /etc/grub.conf; do
519 [ -f /a/$file ] || continue
520 echo " $file"
521 cp /a/$file /a/$file.image
522 cat /a/$file.image |
523 sed s:/dev/sda:%DISK0%:g |
524 sed s:%DISK0%:$DISK0:g |
525 cat > /a/$file
526 done
527 echo
528 beep
529}
530#
531# END disk edits
532################################################################################
533
534
535##################################################################
536#
537# Uncomment the line below to leave your hostname blank.
538# Certain distributions use this as an indication to take on the
539# hostname provided by a DHCP server. The default is to have
540# SystemConfigurator assign your clients the hostname that
541# corresponds to the IP address the use during the install.
542# (If you used to use the static_dhcp option, this is your man.)
543#
544#HOSTNAME=""
545
546
547################################################################################
548#
549# mount /dev /a/dev -o bind if needed
550#
551logmsg "mount /dev /a/dev -o bind || shellout"
552mount /dev /a/dev -o bind || shellout
553#
554################################################################################
555
556
557################################################################################
558#
559# Detect scsi hardware and include the device IDs into the hardware.lst
560# file used by systemconfigurator. Do nothing if the hardware.lst file
561# already exists (which is a sign that it has been already prepared).
562# Use pci-automod for 2.6 kernels, discover for 2.4 kernels.
563#
564if [ ! -f /a/etc/systemconfig/hardware.lst ]; then
565 [ ! -d /a/etc/systemconfig ] && mkdir -p /a/etc/systemconfig
566 if [ -e /tmp/hardware.lst ]; then
567 cat /tmp/hardware.lst >> /a/etc/systemconfig/hardware.lst
568 else
569 SCSI_MODS=`discover -f "%m\n" scsi | grep -v ide-scsi | uniq`
570 for MOD in $SCSI_MODS; do
571 DEVID=`grep $MOD /proc/bus/pci/devices | cut -f 2 | sort | uniq`
572 for MYDEV in $DEVID; do
573 VENDOR=`echo $MYDEV | cut -b 1-4`
574 MODEL=`echo $MYDEV | cut -b 5-8`
575 echo "$VENDOR $MODEL scsi $MOD" >> /a/etc/systemconfig/hardware.lst
576 echo "Added SCSI device $VENDOR:$MODEL using module $MOD to hardware.lst"
577 done
578 done
579 fi
580fi
581#
582################################################################################
583
584################################################################################
585#
586# System Configurator
587#
588# Configure the client's hardware, network interface, and boot loader.
589#
590
591# Create an /etc/mtab file with appropriate entries
592cat /etc/mtab | grep -v '/dev/ram' | grep -v -E '^\/dev\s+\/a\/dev\s' | sed 's,/a/*,/,g' | sort -u > /a/etc/mtab
593
594# Save original boot-loader configurations before running systemconfigurator
595for file in /boot/grub/menu.lst /etc/lilo.conf /etc/grub.conf; do
596 if [ -e ${file} ]; then
597 if [ ! -e ${file}.pre-systemimager ]; then
598 cp -f ${file} ${file}.pre-systemimager
599 fi
600 fi
601done
602
603export PATH=/usr/local/sbin:/usr/local/bin:$PATH
604logmsg "Detecting systemconfigurator:"
605logmsg "---"
606chroot /a/ systemconfigurator --version || \
607 logmsg "WARNING: systemconfigurator was not found in the image $IMAGENAME"
608logmsg "---"
609
610# Fix device names in boot-loader configuration.
611if [ -e /a/etc/systemconfig/systemconfig.conf ]; then
612 sed -i 's:[[:space:]]*BOOTDEV[[:space:]]*=.*:BOOTDEV = LABEL=/boot:g' /a/etc/systemconfig/systemconfig.conf
613 sed -i 's:[[:space:]]*ROOTDEV[[:space:]]*=.*:ROOTDEV = LABEL=/:g' /a/etc/systemconfig/systemconfig.conf
614 sed -i 's:[[:space:]]*root=[^ \t]*: root=LABEL=/ :g' /a/etc/systemconfig/systemconfig.conf
615 sed -i "s:DEFAULTBOOT = systemimager:DEFAULTBOOT = $IMAGENAME:g" /a/etc/systemconfig/systemconfig.conf
616 sed -i "s:LABEL = systemimager:LABEL = $IMAGENAME:g" /a/etc/systemconfig/systemconfig.conf
617fi
618
619# Configure the network interface used during the auto-installation.
620[ -z $DEVICE ] && DEVICE=eth0
621
622# Run systemconfigurator.
623if grep -q PS3 /proc/cpuinfo; then
624 sc_options="--confignet"
625else
626 sc_options="--confighw --confignet --configboot --runboot"
627fi
628chroot /a/ systemconfigurator --verbose --excludesto=/etc/systemimager/systemconfig.local.exclude ${sc_options} --stdin << EOL || shellout
629[NETWORK]
630HOSTNAME = $HOSTNAME
631DOMAINNAME = $DOMAINNAME
632GATEWAY = $GATEWAY
633
634[INTERFACE0]
635DEVICE = $DEVICE
636TYPE = static
637IPADDR = $IPADDR
638NETMASK = $NETMASK
639EOL
640#
641################################################################################
642
643
644################################################################################
645#
646# Post Install Scripts
647#
648run_post_install_scripts
649#
650################################################################################
651
652################################################################################
653#
654# Save virtual console session in the imaged client
655#
656if [ ! -z $MONITOR_SERVER ]; then
657 if [ "x$MONITOR_CONSOLE" = "xy" ]; then
658 MONITOR_CONSOLE=yes
659 fi
660 if [ "x$MONITOR_CONSOLE" = "xyes" ]; then
661 [ ! -d /a/root ] && mkdir -p /a/root
662 cp -f /tmp/si_monitor.log /a/root/si_monitor.log
663 fi
664fi
665
666#
667################################################################################
668
669
670################################################################################
671#
672# Setup kexec if necessary
673#
674# Not needed for this post-install action
675#
676################################################################################
677
678
679################################################################################
680#
681# Unmount filesystems
682#
683logmsg "umount /a/vz || mount -no remount,ro /a//vz || shellout"
684umount /a/vz || mount -no remount,ro /a//vz || shellout
685
686if [ ! $kernel = "2.4" ]; then
687logmsg "umount /a/sys || mount -no remount,ro /a//sys || shellout"
688umount /a/sys || mount -no remount,ro /a//sys || shellout
689fi
690
691logmsg "umount /a/proc || mount -no remount,ro /a//proc || shellout"
692umount /a/proc || mount -no remount,ro /a//proc || shellout
693
694logmsg "umount /a/dev || mount -no remount,ro /a//dev || shellout"
695umount /a/dev || mount -no remount,ro /a//dev || shellout
696
697logmsg "umount /a/boot || mount -no remount,ro /a//boot || shellout"
698umount /a/boot || mount -no remount,ro /a//boot || shellout
699
700logmsg "umount /a/ || mount -no remount,ro /a// || shellout"
701umount /a/ || mount -no remount,ro /a// || shellout
702
703#
704################################################################################
705
706
707################################################################################
708#
709# Tell the image server we are done
710#
711rsync $IMAGESERVER::scripts/imaging_complete > /dev/null 2>&1
712logmsg "Imaging completed"
713#
714################################################################################
715
716if [ ! -z $MONITOR_SERVER ]; then
717 # Report the 'imaged' state to the monitor server.
718 send_monitor_msg "status=100:speed=0"
719 if [ "x$MONITOR_CONSOLE" = "xy" ]; then
720 MONITOR_CONSOLE=yes
721 fi
722 if [ "x$MONITOR_CONSOLE" = "xyes" ]; then
723 # Print some empty lines and sleep some seconds to give time to
724 # the virtual console to get last messages.
725 # XXX: this is a dirty solution, we should find a better way to
726 # sync last messages... -AR-
727 logmsg ""
728 logmsg ""
729 logmsg ""
730 sleep 10
731 fi
732 # Report the post-install action.
733 send_monitor_msg "status=104:speed=0"
734fi
735
736# Explicitly kill sleep processes.
737# This is needed to close the SSH tunnel on the image server when the
738# SSH transport is used).
739killall sleep >/dev/null 2>&1
740
741# Take network interface down
742[ -z $DEVICE ] && DEVICE=eth0
743ifconfig $DEVICE down || shellout
744
745# Announce completion (even for non beep-incessantly --post-install options)
746beep 3
747
748# reboot the autoinstall client
749shutdown -r now