Subversion Repositories livecd

Rev

Rev 159 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 beyerle@PS 1
#!/bin/ash
2
#
3
# Functions library :: for Linux Live scripts 5.x.y
4
# Author: Tomas M. <http://www.linux-live.org>
5
#
6
# modified by Urs Beyerle, PSI
7
# - to allow LiveCD mounted over nfs
8
# - add scsi_mod, sd_mod for usb-storage module
9
# - only with boot option "automount", all devices in fstab are rw automounted
10
# - remove detect of CD and Floppy (done by fstab-sync)
11
# - add sr_mod (USB CDROM support)
12
# - add SATA to modprobe_usb_modules -> modprobe_usb_sata_modules
13
# - add fscache (for SL5) 
14
# - add ide-cd, sr_mod, cdrom (for SL5 cdrom support)
37 beyerle@PS 15
# - add aufs (unionfs replacement)
16
# - to allow LiveCD mounted over NFS (for diskless client)
48 beyerle@PS 17
# - add functions get_dhcp_lease() and load_network_modules()
85 beyerle@PS 18
# - add ata_piix to modprobe_usb_sata_modules
100 beyerle@PS 19
# - works with unionfs 2.x
20
# - better detection of network card in case of diskless client
126 beyerle@PS 21
# - add sg, sata_nv module
160 beyerle@PS 22
# - to allow LiveCD mounted over CIFS (for diskless client)
1 beyerle@PS 23
#
24
 
25
# ===========================================================
26
# user interface functions
27
# ===========================================================
28
 
29
# echolog
30
# $1 = text to show and to write to /var/log/messages
31
#
32
echolog()
33
{
34
   echo "LIVECD:" "$@" >>/var/log/livedbg
35
   echo "$@"
36
}
37
 
38
# debug
39
# commands executed when debug boot parameter is present
40
#
41
debug()
42
{
43
   echo
44
   echo "====="
45
   echo ": Debugging started. Here is the root shell for you."
46
   echo ": Type your desired command or hit Ctrl+D to continue booting."
47
   echo
48
   ash
49
}
50
 
51
# header
52
# $1 = text to show
53
#
54
header()
55
{
56
   echolog "$1"
57
}
58
 
59
fatal()
60
{
61
   header "Fatal error occured - $1"
62
   echolog "Something went wrong and we can't continue booting :("
63
   echolog "You may explore the system by using simple commands like ls, lsmod, mount, etc."
64
   echolog "You may also try to hit Ctrl+D. Booting will continue. Use at your own risk."
65
   echolog "To be safe, hit Ctrl+Alt+Delete to reboot."
66
   echolog
67
   ash
68
}
69
 
70
# ===========================================================
71
# text processing functions
72
# ===========================================================
73
 
74
# egrep_o is a replacement for "egrep -o". It prints only the last
75
# matching text
76
# $1 = regular expression
77
#
78
egrep_o()
79
{
80
   cat | egrep "$1" | sed -r "s/.*($1).*/\\1/"
81
}
82
 
83
# look into cmdline and echo $1 back if $1 is set
84
# $1 = value name, case sensitive, for example livecd_subdir
85
# $2 = file to use instead /proc/cmdline, optional
86
#
87
cmdline_parameter()
88
{
89
   CMDLINE=/proc/cmdline
90
   if [ "$2" != "" ]; then CMDLINE="$2"; fi
91
   cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1(\$|=|[[:space:]]+)" | egrep_o "$1"
92
}
93
 
94
# look into cmdline and echo value of $1 option
95
# $1 = value name, case sensitive, for example livecd_subdir
96
# $2 = file to use instead /proc/cmdline, optional
97
#
98
cmdline_value()
99
{
100
   CMDLINE=/proc/cmdline
101
   if [ "$2" != "" ]; then CMDLINE="$2"; fi
102
   cat "$CMDLINE" | egrep_o "(^|[[:space:]]+)$1=([^[:space:]]+)" | egrep_o "=.*" | cut -b 2- | tail -n 1
103
}
104
 
105
# ===========================================================
106
# system functions
107
# ===========================================================
108
 
109
# modprobe module $1, including all dependencies, suppress all messages
110
# (own function because modprobe in busybox doesn't work with gzipped modules)
111
# $1 = module name, eg. ehci-hcd
112
# $2 = optional argument
113
#
114
modprobe_module()
115
{
116
  if [ "$1" = "" ]; then return 1; fi
117
  PRINTK=`cat /proc/sys/kernel/printk`
118
  echo "0" >/proc/sys/kernel/printk
119
 
120
  KERNEL="`uname -r`"; LSMOD=/tmp/lsmod
121
  MODULEDEPS="`cat /lib/modules/$KERNEL/modules.dep | egrep \"$1\\.ko(\\.gz)?:\"`"
122
 
123
  for MODULE in `echo $MODULEDEPS | cut -d ":" -f 2-` `echo $MODULEDEPS | cut -d ":" -f 1`; do
124
     MODULE=${MODULE%%:};   # remove : at the end, a bug 
125
     TMPMOD="/tmp/`basename $MODULE .gz`";
126
     # if the module is not loaded already
127
     if [ "`cat $LSMOD 2>/dev/null | egrep \"^$TMPMOD\\\$\"`" = "" ]; then
128
        gunzip -c $MODULE 2>/dev/null >$TMPMOD
100 beyerle@PS 129
        if [ $? -ne 0 ]; then cp $MODULE $TMPMOD; fi # can't gunzip? copy
1 beyerle@PS 130
        insmod $TMPMOD $2; err=$?
131
        ### insmod $TMPMOD $2 >/dev/null 2>/dev/null; err=$?
132
        if [ "$err" -eq 0 ]; then echo $TMPMOD >>$LSMOD; fi # module log
133
        rm $TMPMOD
134
     fi
135
  done
136
 
137
  echo "$PRINTK" >/proc/sys/kernel/printk
138
  if [ "$err" -ne 0 ]; then echolog "error inserting module $1 ($err)"; fi
139
  return $err
140
}
141
 
142
# Mount device $1 to $2
143
# $1 = /dev device to mount, eg. /dev/hda1
144
# $2 = mountpoint, eg. /mnt/hda1
145
# $3 = mount options, for example "loop", "ro", or "remount,rw"
146
#
147
mount_device()
148
{
149
  mkdir -p $2
150
  if [ "$3" != "" ]; then OPTIONS="-o $3"; else OPTIONS=""; fi
151
 
152
  PRINTK=`cat /proc/sys/kernel/printk`
153
  echo "0" >/proc/sys/kernel/printk
154
 
155
  mount -t auto $1 $2 $OPTIONS >/dev/null 2>/dev/null
156
  err=$?
157
 
158
  if [ "$err" -ne 0 ]; then rmdir $2 2>/dev/null; fi
159
  echo "$PRINTK" >/proc/sys/kernel/printk
160
  return $err
161
}
162
 
163
# ===========================================================
164
# live module functions
165
# ===========================================================
166
 
167
# Create module
168
# call mksquashfs with apropriate arguments
169
# $1 = directory which will be compressed to squashfs module
170
# $2 = output .mo file
171
# $3 = optional -keep-as-directory argument
172
#
173
create_module()
174
{
175
   mksquashfs $1 $2 $3 >/dev/null
176
   if [ $? -ne 0 ]; then return 1; fi
177
   chmod oga-x $2 # remove execute attrib
178
}
179
 
180
# Mount .mo module to destination directory
181
# $1 = path to .mo livecd compressed module
182
# $2 = destination folder
183
#
184
mount_module()
185
{
186
   mount -t squashfs -o loop,ro $1 $2
187
}
188
 
189
# Insert a directory tree $2 to an union specified by $1
190
# Top-level read-write branch is specified by it's index 0
191
# $1 = union absolute path (starting with /)
192
# $2 = path to data directory
193
#
194
union_insert_dir()
195
{
100 beyerle@PS 196
   which unionctl >/dev/null 2>&1
197
   if [ $? -eq 0 ]; then
198
       # unionfs 1.x or aufs
199
       unionctl "$1" --add --after 0 --mode ro "$2"
200
   else
201
       # unionfs 2.x
202
       mount -t unionfs -o remount,add=:${2}=ro none "$1"
203
   fi
1 beyerle@PS 204
}
205
 
206
# List all modules in all directories (base, modules, optional)
207
# and filter out unneeded optional modules (not specified by load= kernel parameter)
208
# $1 = root directory of mounted DATAdir
209
#
210
list_modules()
211
{
212
   LOAD="`cmdline_value load`"
213
   ls -A1d $1/*.mo $1/*/*.mo 2>/dev/null | while read LINE; do
214
      MODNAME="`basename $LINE .mo`"
215
      if [ "$LOAD" != "*" -a "`echo $LINE | grep optional`" != "" -a "`echo $LOAD | egrep \"(^|,)$MODNAME(\\\$|,)\"`" = "" ]; then continue
216
        else echo $LINE; fi
217
   done
218
}
219
 
220
# Insert one single .mo module to the union
221
# $1 = union absolute path (starting with /)
222
# $2 = module.mo full path
223
# $3 = destination folder, where images will be mounted to
224
#
225
union_insert_module()
226
{
227
   TARGET="$3/`basename $2`"
228
   while [ -e $TARGET ]; do TARGET=$TARGET.X; done
229
   mkdir -p $TARGET
230
   mount_module $2 $TARGET
231
   if [ $? -ne 0 ]; then echo "can't read module data"; return 1; fi
232
   union_insert_dir $1 $TARGET; 
233
}
234
 
235
# Insert all .mo modules, in $2 directory and subdirectories, to the union
236
# $1 = union absolute path (starting with /)
237
# $2 = LiveCD data dir (with directories /base, /modules, etc.)
238
# $3 = destination folder, where images will be mounted to
239
#
240
union_insert_modules()
241
{
38 beyerle@PS 242
   PRINTK=`cat /proc/sys/kernel/printk`
243
   echo "0" >/proc/sys/kernel/printk
244
 
1 beyerle@PS 245
   list_modules $2 | while read MODULE; do
246
      echo " -> `basename $MODULE`"
247
      union_insert_module $1 $MODULE $3
248
   done
38 beyerle@PS 249
 
250
   echo "$PRINTK" >/proc/sys/kernel/printk
1 beyerle@PS 251
}
252
 
253
# Copy modules to RAM directory
254
# $1 = data directory
255
# $2 = target directory in RAM
256
#
257
copy_to_ram()
258
{
259
   cp -R $1/* $2
100 beyerle@PS 260
   if [ $? -ne 0 ]; then fatal "can't copy to RAM, not enough memory?"; fi
1 beyerle@PS 261
}
262
 
263
# Copy content of "rootcopy" directory on the CD to $2 (union, usually)
264
# $1 = source
265
# $2 = destination
266
#
267
copy_rootchanges()
268
{
269
   cp -a $1/rootcopy/* $2 2>/dev/null # could be empty
270
}
271
 
272
# ===========================================================
273
# discovery functions
274
# ===========================================================
275
 
276
# List all CD-ROMs
277
# by using /proc entries
278
#
279
list_cdrom_devices()
280
{
281
   if [ "`cmdline_parameter nocd`" != "" ]; then return 1; fi
282
   for CDDEVICE in `cat /proc/sys/dev/cdrom/info | head -n 3 | tail -n 1 | cut -d ":" -f 2`; do
283
      echo "/dev/$CDDEVICE"
284
   done
285
}
286
 
287
# List all partition devices
288
# take list of all partitions and output unique disks.
289
# Return empty result when nohd parameter was given.
290
#
291
list_partition_devices()
292
{
293
   if [ "`cmdline_parameter nohd`" != "" ]; then return 1; fi
294
   cat /proc/partitions | grep -v loop | sed -r "s/^[0-9[:space:]]+/\/dev\//" | grep /dev/
295
}
296
 
297
# List all disk devices
298
#
299
list_disk_devices()
300
{
301
   list_partition_devices | egrep -v "[0-9]"
302
}
303
 
304
# List all block devices
305
#
306
list_block_devices()
307
{
308
   list_cdrom_devices
309
   list_partition_devices
310
}
311
 
312
# Try to mount all disks, partitions and cdroms and Find where the LiveCD is.
313
# If LiveCD found in the device, echo dirname of it's directory,
314
# and leave the device mounted. Mounting is not ro, but without any argument.
315
# $1 = directory where devices will be mounted
316
# added: mount $NFSROOT to /$1/nfs if NFSROOT is set. and search there for LiveCD
317
#
318
find_live_data_dir()
319
{
320
   if [ "$NFSROOT" != "" ]; then 
321
      DIR="/$1/nfs"
322
      mkdir -p $DIR
108 beyerle@PS 323
 
324
      # disable kernel warnings
325
      PRINTK=`cat /proc/sys/kernel/printk`
326
      echo "0" >/proc/sys/kernel/printk
327
      # try to mount nfs dir
1 beyerle@PS 328
      mount -t nfs -o nolock,ro,rsize=8192,wsize=8192,hard,intr $NFSROOT $DIR
108 beyerle@PS 329
      # enable kernel warnings
330
      echo "$PRINTK" >/proc/sys/kernel/printk
331
 
159 beyerle@PS 332
      # FOUND=`ls -A1d $DIR/livecd.sgn $DIR/*/livecd.sgn 2>/dev/null | head -n 1`
333
      FOUND=`find $DIR -name livecd.sgn -type f | head -n 1`
1 beyerle@PS 334
      if [ "$FOUND" != "" ]; then 
335
         dirname "$FOUND"
336
      fi
160 beyerle@PS 337
 
338
   elif [ "CIFSROOT" != "" ] ; then
339
      DIR="/$1/cifs"
340
      mkdir -p $DIR
341
 
342
      # disable kernel warnings
343
      PRINTK=`cat /proc/sys/kernel/printk`
344
      echo "0" >/proc/sys/kernel/printk
345
      # try to mount cifs dir
346
      mount -t cifs $CIFSROOT $DIR -o ro,$CIFS_OPTS
347
      # enable kernel warnings
348
      echo "$PRINTK" >/proc/sys/kernel/printk
349
 
350
      FOUND=`ls -A1d $DIR/livecd.sgn $DIR/*/livecd.sgn 2>/dev/null | head -n 1`
351
      if [ "$FOUND" != "" ]; then
352
         dirname "$FOUND"
353
      fi
354
 
1 beyerle@PS 355
   else
356
      list_block_devices | while read DEVICE; do
357
         DIR="/$1/`basename $DEVICE`"
358
         mount_device $DEVICE $DIR
359
         if [ $? -ne 0 ]; then continue; fi
360
         FOUND=`ls -A1d $DIR/livecd.sgn $DIR/*/livecd.sgn 2>/dev/null | head -n 1`
361
         if [ "$FOUND" = "" ]; then umount $DIR 2>/dev/null; rmdir $DIR 2>/dev/null
362
         else dirname "$FOUND"; return 1; fi
363
      done
364
   fi
365
}
366
 
367
# ===========================================================
368
# hardware preparation functions
369
# ===========================================================
370
 
371
# Create block devices to /dev described by /sys entries
372
#
373
create_block_devices()
374
{
375
   echolog "creating /dev entries for block devices"
376
   ls -A1d /sys/block/*/dev /sys/block/*/*/dev 2>/dev/null | grep -v loop | while read BLOCK; do
377
      DEVICE="/dev/`basename \`dirname $BLOCK\``"
378
      if [ ! -b $DEVICE ]; then
379
         MINORMAJOR="`head -n 1 $BLOCK | tr ':' ' '`"
380
         mknod $DEVICE b $MINORMAJOR
381
      fi
382
   done
383
}
384
 
385
# modprobe kernel modules needed for the LiveCD
386
#
387
modprobe_essential_modules()
388
{
389
   echolog "starting loop device support"
109 beyerle@PS 390
   modprobe_module loop max_loop=32
1 beyerle@PS 391
   echolog "starting cdrom support"
392
   modprobe_module ide_cd
393
   modprobe_module ide-cd
394
   modprobe_module sr_mod
395
   modprobe_module cdrom
396
   echolog "starting cdrom filesystem support"
397
   modprobe_module isofs
398
   echolog "starting squashfs support"
399
   modprobe_module squashfs
37 beyerle@PS 400
   echolog "starting unionfs/aufs support"
1 beyerle@PS 401
   modprobe_module unionfs
37 beyerle@PS 402
   modprobe_module aufs
1 beyerle@PS 403
   echolog "starting vfat support"
120 beyerle@PS 404
   # modprobe_module nls_cp437
405
   # modprobe_module nls_iso8859-1
406
   # modprobe_module nls_iso8859-2
1 beyerle@PS 407
   modprobe_module vfat
408
   echolog "starting ntfs support"
409
   modprobe_module ntfs
410
   create_block_devices
411
}
412
 
413
 
414
# modprobe kernel modules needed for USB masstorage devices
415
#
416
modprobe_usb_sata_modules()
417
{
418
   echolog "starting USB and SATA support"
419
   modprobe_module ehci-hcd
420
   modprobe_module ohci-hcd
421
   modprobe_module uhci-hcd
422
   modprobe_module scsi_mod
423
 
424
   modprobe_module libata
85 beyerle@PS 425
   modprobe_module ata_piix
1 beyerle@PS 426
   modprobe_module ahci
126 beyerle@PS 427
   modprobe_module sata_nv
116 beyerle@PS 428
   modprobe_module sg
1 beyerle@PS 429
 
430
   modprobe_module sd_mod
431
   modprobe_module sr_mod
432
   modprobe_module usb-storage
433
   echolog "waiting for USB devices, max 9 seconds"
434
   sleep 9
435
   create_block_devices
436
}
437
 
438
# modprobe nfs kernel modules
439
#
440
modprobe_nfs_modules()
441
{
442
   echolog "starting nfs support"
443
   modprobe_module lockd
444
   modprobe_module fscache
445
   modprobe_module nfs_acl
446
   modprobe_module nfs
447
}
448
 
160 beyerle@PS 449
# modprobe cifs kernel module
450
#
451
modprobe_cifs_modules()
452
{
453
  echolog "starting cifs support"
454
  modprobe_module cifs
455
}
456
 
1 beyerle@PS 457
# enable/disable CD autoejecting when unmounted
458
# $1 = 1|0 ... enable|disable
459
#
460
cd_autoeject()
461
{
462
   echo $1 >/proc/sys/dev/cdrom/autoeject
463
}
464
 
465
# Disable DMA if nodma boot parameter is present
466
#
467
setup_dma()
468
{
469
   if [ ! "`cmdline_parameter nodma`" = "" ]; then
470
      for DEVICE in `list_cdrom_devices` `list_disk_devices`; do
471
         echolog "setting DMA support off for $DEVICE"
472
         hdparm -d 0 $DEVICE
473
      done
474
   fi
475
}
476
 
477
# create correct fstab file in $1/etc/fstab and create apropriate
478
# mount directories in $1
479
# $1 = root directory (union)
480
#
481
activate_fstab()
482
{
483
   mkdir -p $1/etc
484
   FSTAB="$1/etc/fstab"
485
   echo "tmpfs            /                tmpfs       defaults         0   0" >$FSTAB
486
   echo "devpts           /dev/pts         devpts      gid=5,mode=620   0   0" >>$FSTAB
487
   echo "proc             /proc            proc        defaults         0   0" >>$FSTAB
488
 
48 beyerle@PS 489
   # all the rest will be done by runlast or by fstab-sync
490
   # search for SWAP done later in /etc/rc.sysinit
491
}
1 beyerle@PS 492
 
493
 
48 beyerle@PS 494
# ===========================================================
495
# functions used for LiveCD on NFS 
496
# ===========================================================
1 beyerle@PS 497
 
37 beyerle@PS 498
# load network modules, if NFSROOT is set
499
# Urs Beyerle, PSI
48 beyerle@PS 500
#
100 beyerle@PS 501
 
147 beyerle@PS 502
# network devices found ?
503
#
504
found_nic()
505
{
506
    found="1"
507
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
508
	# nic already found ?
509
	echo $FOUND_IFACE | grep -q $iface 
510
	if [ $? -ne 0 ]; then
511
	    ifconfig $iface > /dev/null 2>&1
512
	    if [ $? -eq 0 ]; then 
513
		FOUND_IFACE="$FOUND_IFACE $iface"
514
		found="0"
515
	    fi
516
	fi
517
    done
518
    return $found
519
}
520
 
104 beyerle@PS 521
# 1. load network driver defined by kernel parameter nic
522
#
523
load_network_module_nic()
37 beyerle@PS 524
{
147 beyerle@PS 525
    NIC="`cmdline_value nic`"
526
    if [ -n "$NIC" ]; then
100 beyerle@PS 527
	echolog "load module $NIC"
104 beyerle@PS 528
	modprobe_module $NIC
100 beyerle@PS 529
    fi
104 beyerle@PS 530
}
100 beyerle@PS 531
 
532
 
147 beyerle@PS 533
# 2. auto probe for network card drivers
104 beyerle@PS 534
#
535
load_network_module_auto()
536
{
537
    echolog "auto-detection of network driver ..."
147 beyerle@PS 538
    FOUND_NICS=""
104 beyerle@PS 539
    KERNEL="`uname -r`"
540
    NETDRIVERS="`find /lib/modules/$KERNEL/kernel/drivers/net | grep -v mii | grep .ko | cut -d"/" -f8 | cut -d"." -f1 | uniq`"
541
    for driver in $NETDRIVERS; do
148 beyerle@PS 542
       	modprobe_module $driver > /dev/null 2>&1
147 beyerle@PS 543
	found_nic
544
	if [ $? -eq 0 ]; then
545
	    echolog "found network card $driver"
546
	    echolog "load module $driver"
547
	    FOUND_NICS="$FOUND_NICS $driver"
548
	else
549
	    rmmod $driver > /dev/null 2>&1
550
	fi
104 beyerle@PS 551
    done
552
 
553
    # clean up: remove unused modules until driver "mii"
147 beyerle@PS 554
    LOADED_DRIVERS="`lsmod | grep -v Module | cut -d" " -f1`"
104 beyerle@PS 555
    for driver in $LOADED_DRIVERS; do
556
	[ "$driver" = "mii" ]  && break
557
	[ "$driver" = "ntfs" ] && break
558
	[ "$driver" = "vfat" ] && break
147 beyerle@PS 559
	do_not_remove=""
560
	for nic in $FOUND_NICS; do
561
	    echo $driver | grep -q $nic 
562
	    [ $? -eq 0 ] && do_not_remove="$driver"
563
	done
148 beyerle@PS 564
	[ ! $do_not_remove ] && rmmod $driver > /dev/null 2>&1
104 beyerle@PS 565
    done
37 beyerle@PS 566
}
567
 
147 beyerle@PS 568
# 3. detecting network card from pcitable list
569
#
570
load_network_module_pcitable()
571
{
572
    PCITABLE=/bin/pcitable
573
    NICS=`lspci -n | awk '/Class 0200/ {print $4}' | tr ':' ' ' \
574
	| while read x y ; do grep "0x$x.*0x$y" $PCITABLE \
575
	| awk '$3 !~ /"unknown"/ {print $3}' | tr -d '"' ; done`
576
 
577
    if [ -n "$NICS" ]; then
578
	echolog "found network card(s): $NICS"
579
	for driver in $NICS; do
580
	    echolog "load module $driver"
581
	    modprobe_module $driver
582
	done
583
    fi
584
}
585
 
104 beyerle@PS 586
# 4. ask the user for a network driver
587
#
588
load_network_module_ask()
589
{
590
    echo "ERROR: No network card detected!"
591
    echo "Type in your network card driver (e.g. tg3, e1000). "
592
    echo "Or ask your system administrator for help."
593
    echo -n "Network card driver: "
594
    read driver
148 beyerle@PS 595
    echo "load module $driver"
104 beyerle@PS 596
    modprobe_module $driver
597
}
598
 
599
# Try to find a network driver
600
#
601
load_network_modules()
602
{
147 beyerle@PS 603
    # mii maybe need by NIC driver
104 beyerle@PS 604
    modprobe_module mii
605
 
147 beyerle@PS 606
    FOUND_IFACE=""
104 beyerle@PS 607
    load_network_module_nic
149 beyerle@PS 608
    found_nic          || load_network_module_auto
148 beyerle@PS 609
    [ "$FOUND_IFACE" ] || load_network_module_pcitable
610
    [ "$FOUND_IFACE" ] || load_network_module_ask
104 beyerle@PS 611
 
612
    # remove mii, if not needed
613
    rmmod mii > /dev/null 2>&1
614
}
615
 
147 beyerle@PS 616
 
37 beyerle@PS 617
# get DHCP lease
618
# Urs Beyerle, PSI
48 beyerle@PS 619
#
37 beyerle@PS 620
get_dhcp_lease()
621
{
622
    # create /dev/urandom (needed by udhcpc)
623
    mknod /dev/urandom c 1 9
147 beyerle@PS 624
 
625
    for iface in eth0 eth1 eth2 eth3 eth4 eth5; do
626
	# interface up ?
627
	ifconfig $iface > /dev/null 2>&1
628
	if [ $? -eq 0 ]; then
148 beyerle@PS 629
	    # get dhcp lease
630
	    echolog "try to get DHCP lease on $iface"
631
	    udhcpc --now --quit --interface=$iface --script=/bin/udhcpc.script
632
	    [ $? -eq 0 ] && return
633
	    echo "ERROR: couldn't get DHCP lease on $iface."
147 beyerle@PS 634
	fi
102 beyerle@PS 635
    done
37 beyerle@PS 636
}