Subversion Repositories livecd

Rev

Rev 1 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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