rev |
line source |
slaxemulator@0
|
1 #!/bin/bash
|
slaxemulator@0
|
2
|
slaxemulator@0
|
3 # Functions library :: for Linux Live scripts 6
|
slaxemulator@0
|
4 # Author: Tomas M. <http://www.linux-live.org>
|
slaxemulator@0
|
5 #
|
slaxemulator@0
|
6
|
slaxemulator@0
|
7 # ===========================================================
|
slaxemulator@0
|
8 # GLOBAL variables
|
slaxemulator@0
|
9 # ===========================================================
|
slaxemulator@0
|
10
|
slaxemulator@0
|
11 # linux live flag to fstab, if fstab line doesn't contain it,
|
slaxemulator@0
|
12 # never remove it from fstab automatically (user added it)
|
slaxemulator@0
|
13 FSTABLLFLAG="# AutoUpdate"
|
slaxemulator@0
|
14
|
slaxemulator@0
|
15 # We have to set these variables very carefully
|
slaxemulator@0
|
16 UNION=union
|
slaxemulator@0
|
17 MEMORY=memory
|
slaxemulator@0
|
18 MOUNTDIR=mnt
|
slaxemulator@0
|
19 CHANGES=$MEMORY/changes
|
slaxemulator@0
|
20 XINO=$MEMORY/xino
|
slaxemulator@0
|
21 COPY2RAM=$MEMORY/copy2ram
|
slaxemulator@0
|
22 IMAGES=$MEMORY/images
|
slaxemulator@0
|
23 INITRAMDISK=$MOUNTDIR/live
|
slaxemulator@0
|
24 LOOPMOUNT=$MOUNTDIR/tmp
|
slaxemulator@0
|
25 FINDISOMNT=$MOUNTDIR/findiso
|
slaxemulator@34
|
26 #MIRROR
|
slaxemulator@0
|
27
|
slaxemulator@0
|
28 # this will be replaced by build script, so never change the following line!
|
slaxemulator@0
|
29 LIVECDNAME="slitaz"
|
slaxemulator@0
|
30
|
slaxemulator@0
|
31 # =================================================================
|
slaxemulator@0
|
32 # debug and output functions
|
slaxemulator@0
|
33 # =================================================================
|
slaxemulator@0
|
34
|
slaxemulator@0
|
35 # global variable
|
slaxemulator@0
|
36 DEBUG_IS_ENABLED=$(cat /proc/cmdline 2>/dev/null | grep debug)
|
slaxemulator@0
|
37
|
slaxemulator@0
|
38 debug_log()
|
slaxemulator@0
|
39 {
|
slaxemulator@0
|
40 if [ "$DEBUG_IS_ENABLED" ]; then
|
slaxemulator@0
|
41 echo "- debug: $*" >&2
|
slaxemulator@0
|
42 log "- debug: $*"
|
slaxemulator@0
|
43 fi
|
slaxemulator@0
|
44 }
|
slaxemulator@0
|
45
|
slaxemulator@0
|
46 # echogreen will echo $@ in green color
|
slaxemulator@0
|
47 # $1 = text
|
slaxemulator@0
|
48 #
|
slaxemulator@0
|
49 echogreen()
|
slaxemulator@0
|
50 {
|
slaxemulator@0
|
51 echo -ne " [1;34m""$@""[0;39m"
|
slaxemulator@0
|
52 }
|
slaxemulator@0
|
53
|
slaxemulator@0
|
54 # echolog
|
slaxemulator@0
|
55 # $1 = text to show and to write to /var/log/messages
|
slaxemulator@0
|
56 #
|
slaxemulator@0
|
57 echolog()
|
slaxemulator@0
|
58 {
|
slaxemulator@0
|
59 if [ "$1" != "" ]; then
|
slaxemulator@0
|
60 echogreen "* "
|
slaxemulator@0
|
61 log "LIVECD:" "$@"
|
slaxemulator@0
|
62 echo "$@"
|
slaxemulator@0
|
63 fi
|
slaxemulator@0
|
64 }
|
slaxemulator@0
|
65
|
slaxemulator@0
|
66 # log
|
slaxemulator@0
|
67 # store given text in /var/log/livedbg
|
slaxemulator@0
|
68 log()
|
slaxemulator@0
|
69 {
|
slaxemulator@0
|
70 echo "$@" 2>/dev/null >>/var/log/livedbg
|
slaxemulator@0
|
71 }
|
slaxemulator@0
|
72
|
slaxemulator@0
|
73 # show information about the debug shell
|
slaxemulator@0
|
74 show_debug_banner()
|
slaxemulator@0
|
75 {
|
slaxemulator@0
|
76 echo
|
slaxemulator@0
|
77 echo "====="
|
slaxemulator@0
|
78 echo ": Debugging started. Here is the root shell for you."
|
slaxemulator@0
|
79 echo ": Type your desired commands or hit Ctrl+D to continue booting."
|
slaxemulator@0
|
80 echo
|
slaxemulator@0
|
81 }
|
slaxemulator@0
|
82
|
slaxemulator@0
|
83 # debug_shell
|
slaxemulator@0
|
84 # executed when debug boot parameter is present
|
slaxemulator@0
|
85 #
|
slaxemulator@0
|
86 debug_shell()
|
slaxemulator@0
|
87 {
|
slaxemulator@0
|
88 if [ "$DEBUG_IS_ENABLED" ]; then
|
slaxemulator@0
|
89 show_debug_banner
|
slaxemulator@0
|
90 ash < /dev/console
|
slaxemulator@0
|
91 echo
|
slaxemulator@0
|
92 fi
|
slaxemulator@0
|
93 }
|
slaxemulator@0
|
94
|
slaxemulator@0
|
95 # header
|
slaxemulator@0
|
96 # $1 = text to show
|
slaxemulator@0
|
97 #
|
slaxemulator@0
|
98 header()
|
slaxemulator@0
|
99 {
|
slaxemulator@0
|
100 echo "[0;1m""$@""[0;0m"
|
slaxemulator@0
|
101 }
|
slaxemulator@0
|
102
|
slaxemulator@0
|
103 fatal()
|
slaxemulator@0
|
104 {
|
slaxemulator@0
|
105 echolog
|
slaxemulator@0
|
106 header "Fatal error occured - $1"
|
slaxemulator@0
|
107 echolog "Something went wrong and we can't continue. This should never happen."
|
slaxemulator@0
|
108 echolog "Please reboot your computer with Ctrl+Alt+Delete ..."
|
slaxemulator@0
|
109 echolog
|
slaxemulator@0
|
110 ash < /dev/console
|
slaxemulator@0
|
111 }
|
slaxemulator@0
|
112
|
slaxemulator@0
|
113 allow_only_root()
|
slaxemulator@0
|
114 {
|
slaxemulator@0
|
115 # test if the script is started by root user. If not, exit
|
slaxemulator@0
|
116 if [ "0$UID" -ne 0 ]; then
|
slaxemulator@0
|
117 echo "Only root can run $(basename $0)"; exit 1
|
slaxemulator@0
|
118 fi
|
slaxemulator@0
|
119 }
|
slaxemulator@0
|
120
|
slaxemulator@0
|
121 # ===========================================================
|
slaxemulator@0
|
122 # text processing functions
|
slaxemulator@0
|
123 # ===========================================================
|
slaxemulator@0
|
124
|
slaxemulator@0
|
125 # look into cmdline and echo $1 back if $1 is set
|
slaxemulator@0
|
126 # $1 = value name, case sensitive, for example 'debug'
|
slaxemulator@0
|
127 #
|
slaxemulator@0
|
128 cmdline_parameter()
|
slaxemulator@0
|
129 {
|
slaxemulator@0
|
130 debug_log "cmdline_parameter" "$*"
|
slaxemulator@0
|
131 log "searching for bootparam: $1"
|
slaxemulator@0
|
132 egrep -o "(^|[[:space:]])$1([[:space:]]|\$)" /proc/cmdline | tr -d " " | tail -n 1
|
slaxemulator@0
|
133 }
|
slaxemulator@0
|
134
|
slaxemulator@0
|
135 # look into cmdline and echo value of $1 option
|
slaxemulator@0
|
136 # $1 = value name, case sensitive, for example 'changes'
|
slaxemulator@0
|
137 #
|
slaxemulator@0
|
138 cmdline_value()
|
slaxemulator@0
|
139 {
|
slaxemulator@0
|
140 debug_log "cmdline_value" "$*"
|
slaxemulator@0
|
141 log "searching for bootparam value: $1"
|
slaxemulator@0
|
142 egrep -o "(^|[[:space:]])$1=[^[:space:]]+" /proc/cmdline | cut -d "=" -f 2- | tail -n 1
|
slaxemulator@0
|
143 }
|
slaxemulator@0
|
144
|
slaxemulator@0
|
145 # Make sure the part of a script after 'mutex_lock' call is atomic,
|
slaxemulator@0
|
146 # that means the 'locked' part of the script can never be execuetd
|
slaxemulator@0
|
147 # from several processes at the same time, in parallel.
|
slaxemulator@0
|
148 # Every script waits until it gathers the lock.
|
slaxemulator@0
|
149 # The lock directory is saved in /dev instead of /tmp, because /tmp may be
|
slaxemulator@0
|
150 # readonly at the time when the lock is needed (eg. when udev is starting)
|
slaxemulator@0
|
151 # $1 = name of the lock
|
slaxemulator@0
|
152 #
|
slaxemulator@0
|
153 mutex_lock()
|
slaxemulator@0
|
154 {
|
slaxemulator@0
|
155 debug_log "mutex_lock" "$*"
|
slaxemulator@0
|
156 while ! mkdir "/dev/ll-mutex-lock-$1" 2>/dev/null; do
|
slaxemulator@0
|
157 usleep 100000;
|
slaxemulator@0
|
158 done
|
slaxemulator@0
|
159 }
|
slaxemulator@0
|
160
|
slaxemulator@0
|
161 # Unlock the lock so another waiting process can reusse it and continue
|
slaxemulator@0
|
162 # $1 = name of the lock
|
slaxemulator@0
|
163 #
|
slaxemulator@0
|
164 mutex_unlock()
|
slaxemulator@0
|
165 {
|
slaxemulator@0
|
166 debug_log "mutex_unlock" "$*"
|
slaxemulator@0
|
167 rmdir "/dev/ll-mutex-lock-$1" 2>/dev/null
|
slaxemulator@0
|
168 }
|
slaxemulator@0
|
169
|
slaxemulator@0
|
170 # ===========================================================
|
slaxemulator@0
|
171 # system functions
|
slaxemulator@0
|
172 # ===========================================================
|
slaxemulator@0
|
173
|
slaxemulator@0
|
174 # setup /usr from /usr.lzm inside initrd
|
slaxemulator@0
|
175 mount_initrd_loops()
|
slaxemulator@0
|
176 {
|
slaxemulator@0
|
177 debug_log "mount_initrd_loops" "$*"
|
slaxemulator@0
|
178 if [ -e /usr.lzm ]; then
|
slaxemulator@0
|
179 mount_device /usr.lzm /usr loop,ro squashfs
|
slaxemulator@0
|
180 fi
|
slaxemulator@0
|
181 if [ -e /drivers.lzm ]; then
|
slaxemulator@0
|
182 mount_device /drivers.lzm /lib/modules/*/kernel/drivers loop,ro squashfs
|
slaxemulator@0
|
183 fi
|
slaxemulator@0
|
184 }
|
slaxemulator@0
|
185
|
slaxemulator@0
|
186 # modprobe module $1, including all dependencies, suppress all messages
|
slaxemulator@0
|
187 # This was own function, because modprobe in busybox didn't support
|
slaxemulator@0
|
188 # neither gzipped modules nor dependencies. Seems to be fixed now, though.
|
slaxemulator@0
|
189 # $1 = module name, eg. ehci-hcd
|
slaxemulator@0
|
190 # $* = optional arguments
|
slaxemulator@0
|
191 #
|
slaxemulator@0
|
192 modprobe_module()
|
slaxemulator@0
|
193 {
|
slaxemulator@0
|
194 debug_log "modprobe_module" "$*"
|
slaxemulator@0
|
195 local MODULE
|
slaxemulator@0
|
196
|
slaxemulator@0
|
197 MODULE="$1"
|
slaxemulator@0
|
198 shift
|
slaxemulator@0
|
199
|
slaxemulator@0
|
200 if [ ! "$MODULE" ]; then return 1; fi
|
slaxemulator@0
|
201 modprobe "$MODULE" $* 2>/dev/null
|
slaxemulator@0
|
202 }
|
slaxemulator@0
|
203
|
slaxemulator@0
|
204 cdname()
|
slaxemulator@0
|
205 {
|
slaxemulator@0
|
206 if [ "$(cmdline_value cdname)" != "" ]; then
|
slaxemulator@0
|
207 LIVECDNAME="$(cmdline_value cdname)"
|
slaxemulator@0
|
208 else
|
slaxemulator@0
|
209 LIVECDNAME="${LIVECDNAME}"
|
slaxemulator@0
|
210 fi
|
slaxemulator@0
|
211 }
|
slaxemulator@0
|
212
|
slaxemulator@0
|
213 cdname
|
slaxemulator@0
|
214
|
slaxemulator@0
|
215 # mknod next loop device
|
slaxemulator@0
|
216 # - find biggest loop device in /dev/loop/, assume it to be used
|
slaxemulator@0
|
217 # - preallocate (mknod) 20 more loop devices in one round
|
slaxemulator@0
|
218 mknod_next_loop_dev()
|
slaxemulator@0
|
219 {
|
slaxemulator@0
|
220 debug_log "mknod_next_loop_dev" "$*"
|
slaxemulator@0
|
221 local i NR END PFX
|
slaxemulator@0
|
222
|
slaxemulator@0
|
223 mutex_lock mknod_next_loop_dev
|
slaxemulator@0
|
224
|
slaxemulator@0
|
225 if [ -d /dev/loop ]; then
|
slaxemulator@0
|
226 NR=$(find /dev/loop/ -maxdepth 1 | sed -r 's/[^0-9]+//' | sort -n | tail -n 1)
|
slaxemulator@0
|
227 PFX="/"
|
slaxemulator@0
|
228 else
|
slaxemulator@0
|
229 NR=$(find /dev/ -maxdepth 1 | grep loop | sed -r 's/[^0-9]+//' | sort -n | tail -n 1)
|
slaxemulator@0
|
230 PFX=""
|
slaxemulator@0
|
231 fi
|
slaxemulator@0
|
232 NR=$(expr 0$NR + 1)
|
slaxemulator@0
|
233 END=$(expr 0$NR + 20)
|
slaxemulator@0
|
234 for i in $(seq $NR $END); do
|
slaxemulator@0
|
235 mknod /dev/loop$PFX$i b 7 $i 2>/dev/null
|
slaxemulator@0
|
236 done
|
slaxemulator@0
|
237 echo /dev/loop$PFX$NR
|
slaxemulator@0
|
238
|
slaxemulator@0
|
239 mutex_unlock mknod_next_loop_dev
|
slaxemulator@0
|
240 }
|
slaxemulator@0
|
241
|
slaxemulator@0
|
242 # ===========================================================
|
slaxemulator@0
|
243 # Filesystem functions
|
slaxemulator@0
|
244 # ===========================================================
|
slaxemulator@0
|
245
|
slaxemulator@0
|
246 # Find out what locale is requested
|
slaxemulator@0
|
247 # If no locale is given, use the firts one available (if any)
|
slaxemulator@0
|
248 # $1 = locale (optional argument, if exists, no autodetection is made)
|
slaxemulator@0
|
249 locale_id()
|
slaxemulator@0
|
250 {
|
slaxemulator@0
|
251 debug_log "locale_id" "$*"
|
slaxemulator@0
|
252 local LOCALE i
|
slaxemulator@0
|
253
|
slaxemulator@0
|
254 # first try to find out locale from boot parameters
|
slaxemulator@0
|
255 LOCALE="$1"
|
slaxemulator@0
|
256 if [ "$LOCALE" = "" ]; then LOCALE=$(cmdline_value locale); fi
|
slaxemulator@0
|
257 if [ "$LOCALE" = "" ]; then LOCALE=$(cmdline_value language); fi
|
slaxemulator@0
|
258 if [ "$LOCALE" = "" ]; then LOCALE=$(cmdline_value lang); fi
|
slaxemulator@0
|
259
|
slaxemulator@0
|
260 # if not found, set it to locale from usr/lib/locale,
|
slaxemulator@0
|
261 # but only if there is just ONE directory, nothing more
|
slaxemulator@0
|
262 # (so we are sure which one to use)
|
slaxemulator@0
|
263 if [ "$LOCALE" = "" ]; then
|
slaxemulator@0
|
264 for LOCALE in $(ls -A1p /usr/lib/locale 2>/dev/null | grep / | sed -r "s:[/]|[.].*::"); do
|
slaxemulator@0
|
265 i="1$i"
|
slaxemulator@0
|
266 done
|
slaxemulator@0
|
267 if [ "$i" != "1" ]; then LOCALE=""; fi
|
slaxemulator@0
|
268 fi
|
slaxemulator@0
|
269
|
slaxemulator@0
|
270 if [ "$LOCALE" != "" -a -e /usr/share ]; then
|
slaxemulator@0
|
271 cat /usr/share/locale/locale.alias | sed -r "s/#.*//" | egrep "$LOCALE|$LOCALE""_" | tail -n 1 | tr -s "[[:space:]]" " " | cut -d " " -f 2- | tr -d " "
|
slaxemulator@0
|
272 fi
|
slaxemulator@0
|
273 }
|
slaxemulator@0
|
274
|
slaxemulator@0
|
275 # Find out what iocharset to use
|
slaxemulator@0
|
276 iocharset()
|
slaxemulator@0
|
277 {
|
slaxemulator@0
|
278 debug_log "iocharset" "$*"
|
slaxemulator@0
|
279 local CHARSET IOCHARSET
|
slaxemulator@0
|
280
|
slaxemulator@0
|
281 # if iocharset is explicitly set at the boot prompt,
|
slaxemulator@0
|
282 # return it regardless the locale settings
|
slaxemulator@0
|
283 IOCHARSET=$(cmdline_value iocharset)
|
slaxemulator@0
|
284 if [ "$IOCHARSET" != "" ]; then
|
slaxemulator@0
|
285 echo $IOCHARSET
|
slaxemulator@0
|
286 return 0;
|
slaxemulator@0
|
287 fi
|
slaxemulator@0
|
288
|
slaxemulator@0
|
289 # else find out the iocharset from locale_id output, it should match
|
slaxemulator@0
|
290 # some kernel module (after stripping out few of the dashes)
|
slaxemulator@0
|
291 IOCHARSET=$(locale_id | cut -d . -f 2- | tr "[[:upper:]]" "[[:lower:]]" | tr -d -)
|
slaxemulator@0
|
292 if [ "$IOCHARSET" = "" ]; then return 0; fi
|
slaxemulator@0
|
293
|
slaxemulator@0
|
294 find /lib/modules -name "nls_*" | sed -r 's:^.*/|[.]ko$::g' | cut -b 5- | while read CHARSET; do
|
slaxemulator@0
|
295 if [ "$(echo $CHARSET | tr "[[:upper:]]" "[[:lower:]]" | tr -d -)" = "$IOCHARSET" ]; then
|
slaxemulator@0
|
296 echo "$CHARSET"
|
slaxemulator@0
|
297 return 0
|
slaxemulator@0
|
298 fi
|
slaxemulator@0
|
299 done
|
slaxemulator@0
|
300 return 1
|
slaxemulator@0
|
301 }
|
slaxemulator@0
|
302
|
slaxemulator@0
|
303 # Get filesystem options
|
slaxemulator@0
|
304 # $1 = filesystem
|
slaxemulator@0
|
305 # $2 = 'fstab' or 'mount' ... 'auto'/'noauto' string is enabled (fstab) or disabled (mount)
|
slaxemulator@0
|
306 #
|
slaxemulator@0
|
307
|
slaxemulator@0
|
308 fs_options()
|
slaxemulator@0
|
309 {
|
slaxemulator@0
|
310 debug_log "fs_options" "$*"
|
slaxemulator@0
|
311 local NOAUTO IOCHARSET
|
slaxemulator@0
|
312
|
slaxemulator@0
|
313 NOAUTO=$(cmdline_parameter noauto)
|
slaxemulator@0
|
314 if [ "$NOAUTO" = "" ]; then NOAUTO="auto"; fi
|
slaxemulator@0
|
315 if [ "$2" = "fstab" ]; then echo -n "$NOAUTO," ; fi
|
slaxemulator@0
|
316 if [ "$1" = "swap" ]; then echo "defaults,pri=1"; return 0; fi
|
slaxemulator@0
|
317 echo -n "noatime,users,suid,dev,exec"
|
slaxemulator@0
|
318
|
slaxemulator@0
|
319 IOCHARSET=$(iocharset)
|
slaxemulator@0
|
320
|
slaxemulator@0
|
321 if [ "$1" = "vfat" ]; then
|
slaxemulator@0
|
322 echo -n ",quiet,umask=0,check=s,shortname=mixed"
|
slaxemulator@0
|
323 if [ "$IOCHARSET" ]; then
|
slaxemulator@0
|
324 echo ",iocharset=$IOCHARSET"
|
slaxemulator@0
|
325 fi
|
slaxemulator@0
|
326 fi
|
slaxemulator@0
|
327
|
slaxemulator@0
|
328 if [ "$1" = "iso9660" -o "$1" = "iso9660,udf" ]; then
|
slaxemulator@0
|
329 echo -n ",ro"
|
slaxemulator@0
|
330 if [ "$IOCHARSET" ]; then
|
slaxemulator@0
|
331 echo ",iocharset=$IOCHARSET"
|
slaxemulator@0
|
332 fi
|
slaxemulator@0
|
333 fi
|
slaxemulator@0
|
334
|
slaxemulator@0
|
335 if [ "$1" = "ntfs" ]; then
|
slaxemulator@0
|
336 echo -n ",ro"
|
slaxemulator@0
|
337 if [ "$IOCHARSET" ]; then
|
slaxemulator@0
|
338 echo ",nls=$IOCHARSET"
|
slaxemulator@0
|
339 fi
|
slaxemulator@0
|
340 fi
|
slaxemulator@0
|
341
|
slaxemulator@0
|
342 if [ "$1" = "ntfs-3g" ]; then
|
slaxemulator@0
|
343 echo ",locale=$(locale_id)"
|
slaxemulator@0
|
344 fi
|
slaxemulator@0
|
345
|
slaxemulator@0
|
346 if [ "$1" = "ext3" -o "$1" = "ext4" ]; then
|
slaxemulator@0
|
347 echo ",barrier=1,data=ordered"
|
slaxemulator@0
|
348 fi
|
slaxemulator@0
|
349
|
slaxemulator@0
|
350 }
|
slaxemulator@0
|
351
|
slaxemulator@0
|
352 # discover filesystem used on the given device
|
slaxemulator@0
|
353 # Use vfat for msdos filesystem. Use ntfs-3g for ntfs if ntfs-3g exists.
|
slaxemulator@0
|
354 # $1 = device, eg. /dev/hda1
|
slaxemulator@0
|
355 #
|
slaxemulator@0
|
356 device_filesystem()
|
slaxemulator@0
|
357 {
|
slaxemulator@0
|
358 debug_log "device_filesystem" "$*"
|
slaxemulator@0
|
359 local NTFS
|
slaxemulator@0
|
360
|
slaxemulator@0
|
361 if [ -e /bin/ntfs-3g ]; then NTFS="ntfs-3g"; else NTFS="ntfs"; fi
|
slaxemulator@0
|
362 blkid -s TYPE "$1" -o value | sed "s/msdos/vfat/" | sed "s/ntfs/$NTFS/"
|
slaxemulator@0
|
363 }
|
slaxemulator@0
|
364
|
slaxemulator@0
|
365 # tell us if the given filesystem is supported
|
slaxemulator@0
|
366 # (eg. it's in /proc/filesystems or we know it)
|
slaxemulator@0
|
367 # $1 = filesystem name
|
slaxemulator@0
|
368 #
|
slaxemulator@0
|
369 is_supported_filesystem()
|
slaxemulator@0
|
370 {
|
slaxemulator@0
|
371 debug_log "is_supported_filesystem" "$*"
|
slaxemulator@0
|
372
|
slaxemulator@0
|
373 if [ -e /bin/ntfs-3g -a "$1" = "ntfs-3g" ]; then
|
slaxemulator@0
|
374 return 0
|
slaxemulator@0
|
375 fi
|
slaxemulator@0
|
376
|
slaxemulator@0
|
377 # the following command will set the return value
|
slaxemulator@0
|
378 egrep -q "[[:space:]]$1\$" /proc/filesystems
|
slaxemulator@0
|
379 }
|
slaxemulator@0
|
380
|
slaxemulator@0
|
381 # Mount device $1 to $2
|
slaxemulator@0
|
382 # If the device is using vfat or ntfs filesystem, use iocharset as a mount option
|
slaxemulator@0
|
383 # $1 = /dev device to mount, eg. /dev/hda1, or loop file, or directory
|
slaxemulator@0
|
384 # $2 = mountpoint, eg. /mnt/hda1
|
slaxemulator@0
|
385 # $3 = optional mount options, for example "ro", or "remount,rw"
|
slaxemulator@0
|
386 # $4 = optional filesystem name, in order to skip autodetection
|
slaxemulator@0
|
387 #
|
slaxemulator@0
|
388 mount_device()
|
slaxemulator@0
|
389 {
|
slaxemulator@0
|
390 debug_log "mount_device" "$*"
|
slaxemulator@0
|
391 local FS DEV LOOPDEV OPTIONS FILESYSTEM ERR
|
slaxemulator@0
|
392
|
slaxemulator@0
|
393 # make sure we have enough arguments
|
slaxemulator@0
|
394 if [ "$2" = "" ]; then return 1; fi
|
slaxemulator@0
|
395 if [ "$1" = "" ]; then rmdir "$2" 2>/dev/null; return 1; fi
|
slaxemulator@0
|
396 mkdir -p "$2"
|
slaxemulator@0
|
397
|
slaxemulator@0
|
398 DEV="$1"
|
slaxemulator@0
|
399 if [ "$4" != "" ]; then FS="$4"; else FS=$(device_filesystem "$1"); fi
|
slaxemulator@0
|
400 if [ "$FS" ]; then OPTIONS=$(fs_options $FS mount); FS="-t $FS"; fi
|
slaxemulator@0
|
401 if [ "$OPTIONS" ]; then OPTIONS="$OPTIONS"; else OPTIONS=""; fi
|
slaxemulator@0
|
402 if [ -f "$DEV" ]; then OPTIONS="$OPTIONS,loop"; fi
|
slaxemulator@0
|
403 if [ -d "$DEV" ]; then OPTIONS="$OPTIONS,rbind"; fi
|
slaxemulator@0
|
404 if [ "$3" ]; then OPTIONS="$OPTIONS,$3"; fi
|
slaxemulator@0
|
405 OPTIONS=$(echo "$OPTIONS" | sed -r "s/^,+//")
|
slaxemulator@0
|
406
|
slaxemulator@0
|
407 if [ "$FS" = "-t ntfs-3g" ]; then
|
slaxemulator@0
|
408 ntfs-3g "$DEV" "$2" -o $OPTIONS >/dev/null 2>&1
|
slaxemulator@0
|
409 ERR=$?
|
slaxemulator@0
|
410 else
|
slaxemulator@0
|
411 mount -n -o $OPTIONS $FS "$DEV" "$2" >/dev/null 2>&1
|
slaxemulator@0
|
412 ERR=$?
|
slaxemulator@0
|
413 fi
|
slaxemulator@0
|
414
|
slaxemulator@0
|
415 # not enough loop devices? try to create one.
|
slaxemulator@0
|
416 if [ $ERR -eq 2 ]; then
|
slaxemulator@0
|
417 LOOPDEV=$(mknod_next_loop_dev)
|
slaxemulator@0
|
418 OPTIONS=$(echo "$OPTIONS" | sed -r "s/,loop//g")
|
slaxemulator@0
|
419 losetup "$LOOPDEV" "$DEV" 2>/dev/null # busybox's losetup doesn't support -r
|
slaxemulator@0
|
420 if [ $? -ne 0 ]; then
|
slaxemulator@0
|
421 losetup -r "$LOOPDEV" "$DEV" 2>/dev/null # force read-only in case of error
|
slaxemulator@0
|
422 fi
|
slaxemulator@0
|
423 mount -n -o $OPTIONS $FS "$LOOPDEV" "$2" >/dev/null 2>&1
|
slaxemulator@0
|
424 ERR=$?
|
slaxemulator@0
|
425 fi
|
slaxemulator@0
|
426
|
slaxemulator@0
|
427 # if nothing works, try to force read-only mount
|
slaxemulator@0
|
428 if [ $ERR -ne 0 ]; then
|
slaxemulator@0
|
429 mount -n -r -o $OPTIONS $FS "$DEV" "$2" >/dev/null 2>&1
|
slaxemulator@0
|
430 ERR=$?
|
slaxemulator@0
|
431 fi
|
slaxemulator@0
|
432
|
slaxemulator@0
|
433 if [ $ERR -ne 0 ]; then rmdir $2 2>/dev/null; fi
|
slaxemulator@0
|
434 return $ERR
|
slaxemulator@0
|
435 }
|
slaxemulator@0
|
436
|
slaxemulator@0
|
437 # unmount all parameters. If the parameter is not mountpoint but
|
slaxemulator@0
|
438 # it's a file or directory, umount the device where the file/dir is stored.
|
slaxemulator@0
|
439 #
|
slaxemulator@0
|
440 # First try normal umount, if that fails then remount read-only
|
slaxemulator@0
|
441 # If -l parameter is specified, do lazy-umount when normal umount fails
|
slaxemulator@0
|
442 # $1..$n = files/directories/devices to be unmounted
|
slaxemulator@0
|
443 #
|
slaxemulator@0
|
444 fumount()
|
slaxemulator@0
|
445 {
|
slaxemulator@0
|
446 debug_log "fumount" "$*"
|
slaxemulator@0
|
447 local TARGET LAZY
|
slaxemulator@0
|
448
|
slaxemulator@0
|
449 while [ "$1" ]; do
|
slaxemulator@0
|
450 if [ "$1" = "-l" ]; then LAZY="yes"; shift; fi
|
slaxemulator@0
|
451 TARGET=$(readlink -f "$1")
|
slaxemulator@0
|
452 if ! ismountpoint "$TARGET"; then
|
slaxemulator@0
|
453 if [ -f "$TARGET" -o -d "$TARGET" ]; then
|
slaxemulator@0
|
454 TARGET=$(df "$TARGET" | tail -n 1 | tr -s " " | cut -d " " -f 6)
|
slaxemulator@0
|
455 fi
|
slaxemulator@0
|
456 fi
|
slaxemulator@0
|
457
|
slaxemulator@0
|
458 if [ "$TARGET" != "" ]; then
|
slaxemulator@0
|
459 umount -n "$TARGET" >/dev/null 2>&1
|
slaxemulator@0
|
460 if [ $? -ne 0 ]; then
|
slaxemulator@0
|
461 mount -n -o remount,ro -t ignored ignored "$TARGET" >/dev/null 2>&1
|
slaxemulator@0
|
462 if [ "$LAZY" ]; then umount -n -l "$TARGET" >/dev/null 2>&1; fi
|
slaxemulator@0
|
463 fi
|
slaxemulator@0
|
464 fi
|
slaxemulator@0
|
465 shift
|
slaxemulator@0
|
466 done
|
slaxemulator@0
|
467 }
|
slaxemulator@0
|
468
|
slaxemulator@0
|
469 # ===========================================================
|
slaxemulator@0
|
470 # live module functions
|
slaxemulator@0
|
471 # ===========================================================
|
slaxemulator@0
|
472
|
slaxemulator@0
|
473 # Create module
|
slaxemulator@0
|
474 # call mksquashfs with apropriate arguments
|
slaxemulator@0
|
475 # $1 = directory which will be compressed to squashfs module
|
slaxemulator@0
|
476 # $2 = output filesystem module file
|
slaxemulator@0
|
477 # $3..$9 = optional arguments like -keep-as-directory or -b 123456789
|
slaxemulator@0
|
478 #
|
slaxemulator@0
|
479 create_module()
|
slaxemulator@0
|
480 {
|
slaxemulator@0
|
481 debug_log "create_module" "$*"
|
slaxemulator@0
|
482 rm -f "$2" # overwrite, never append to existing file
|
slaxemulator@59
|
483 mksquashfs "$1" "$2" -b 256K $3 $4 $5 $6 $7 $8 $9>/dev/null
|
slaxemulator@0
|
484 if [ $? -ne 0 ]; then return 1; fi
|
slaxemulator@0
|
485 chmod a-wx "$2" # remove execute and write attrib
|
slaxemulator@0
|
486 chmod a+r "$2" # add read for everyone
|
slaxemulator@0
|
487 }
|
slaxemulator@0
|
488
|
slaxemulator@0
|
489 # ismountpoint exits with 0 if $1 is mountpoint, else exits with 1
|
slaxemulator@0
|
490 # $1 = directory or loop_file
|
slaxemulator@0
|
491 #
|
slaxemulator@0
|
492 ismountpoint()
|
slaxemulator@0
|
493 {
|
slaxemulator@0
|
494 debug_log "ismountpoint" "$*"
|
slaxemulator@0
|
495 local MDIR
|
slaxemulator@0
|
496
|
slaxemulator@0
|
497 MDIR=$(readlink -f "$1")
|
slaxemulator@0
|
498 cat /proc/mounts | cut -d " " -f 2 | egrep "^$MDIR\$" >/dev/null 2>&1
|
slaxemulator@0
|
499 }
|
slaxemulator@0
|
500
|
slaxemulator@0
|
501 # Mount filesystem module to destination directory
|
slaxemulator@0
|
502 # $1 = path to the compressed module
|
slaxemulator@0
|
503 # $2 = destination folder
|
slaxemulator@0
|
504 #
|
slaxemulator@0
|
505 mount_module()
|
slaxemulator@0
|
506 {
|
slaxemulator@0
|
507 debug_log "mount_module" "$*"
|
slaxemulator@0
|
508 mount_device "$1" "$2" loop,ro squashfs
|
slaxemulator@0
|
509 }
|
slaxemulator@0
|
510
|
slaxemulator@0
|
511 # Insert a directory tree $2 to an union specified by $1
|
slaxemulator@0
|
512 # Top-level read-write branch is specified by it's index 0
|
slaxemulator@0
|
513 # Using =rr enables aufs to optimize real readonly branches
|
slaxemulator@0
|
514 # $1 = union absolute path (starting with /)
|
slaxemulator@0
|
515 # $2 = path to data directory
|
slaxemulator@0
|
516 #
|
slaxemulator@0
|
517 union_insert_dir()
|
slaxemulator@0
|
518 {
|
slaxemulator@0
|
519 debug_log "union_insert_dir" "$*"
|
slaxemulator@0
|
520 mount -n -o remount,add:1:$2=rr aufs $1
|
slaxemulator@0
|
521 }
|
slaxemulator@0
|
522
|
slaxemulator@0
|
523 # Find LZM modules in given dir
|
slaxemulator@0
|
524 # $1 = root directory of mounted DATAdir
|
slaxemulator@0
|
525 #
|
slaxemulator@0
|
526 find_modules()
|
slaxemulator@0
|
527 {
|
slaxemulator@0
|
528 debug_log "find_modules" "$*"
|
slaxemulator@0
|
529 if [ "$(cmdline_parameter baseonly)" ]; then
|
slaxemulator@0
|
530 find "$1/base" "$1/optional" -name "*.sqfs" 2>/dev/null | sort
|
slaxemulator@0
|
531 find "$1/base" "$1/optional" -name "*.lzm" 2>/dev/null | sort
|
slaxemulator@13
|
532 find "$1/base" "$1/optional" -name "*.xz" 2>/dev/null | sort
|
slaxemulator@0
|
533 else
|
slaxemulator@0
|
534 find "$1/base" "$1/modules" "$1/optional" "$1/tmp" -name "*.sqfs" 2>/dev/null | sort
|
slaxemulator@0
|
535 find "$1/base" "$1/modules" "$1/optional" "$1/tmp" -name "*.lzm" 2>/dev/null | sort
|
slaxemulator@13
|
536 find "$1/base" "$1/modules" "$1/optional" "$1/tmp" -name "*.xz" 2>/dev/null | sort
|
slaxemulator@0
|
537 fi
|
slaxemulator@0
|
538 }
|
slaxemulator@0
|
539
|
slaxemulator@0
|
540 # List all modules in all directories (base, modules, optional)
|
slaxemulator@0
|
541 # and filter out unneeded optional modules (not specified by load= kernel parameter)
|
slaxemulator@0
|
542 # separator for load and noload arguments is "," or ";"
|
slaxemulator@0
|
543 # $1 = root directory of mounted DATAdir
|
slaxemulator@0
|
544 #
|
slaxemulator@0
|
545 list_modules()
|
slaxemulator@0
|
546 {
|
slaxemulator@0
|
547 debug_log "list_modules" "$*"
|
slaxemulator@0
|
548 local LOAD NOLOAD
|
slaxemulator@0
|
549
|
slaxemulator@0
|
550 LOAD=$(cmdline_value load | sed -r 's/\*/.\*/g' | sed -r 's/,|;/|/g')
|
slaxemulator@0
|
551 NOLOAD=$(cmdline_value noload | sed -r 's/\*/.\*/g' | sed -r 's/,|;/|/g')
|
slaxemulator@0
|
552 find_modules "$1" | while read LINE; do
|
slaxemulator@0
|
553 MODNAME=$(echo $LINE | cut -b ${#1}- | cut -b 2-)
|
slaxemulator@0
|
554 if [ "$(echo $LINE | grep /optional/)" ]; then
|
slaxemulator@0
|
555 if [ ! "$LOAD" -o ! "$(echo $MODNAME | egrep -i "$LOAD")" ]; then continue; fi
|
slaxemulator@0
|
556 fi
|
slaxemulator@0
|
557 if [ "$NOLOAD" -a "$(echo $MODNAME | egrep -i "$NOLOAD")" ]; then continue; fi
|
slaxemulator@0
|
558 echo $LINE
|
slaxemulator@0
|
559 done
|
slaxemulator@0
|
560 }
|
slaxemulator@0
|
561
|
slaxemulator@0
|
562 # Insert one single filesystem module to the union
|
slaxemulator@0
|
563 # $1 = union absolute path
|
slaxemulator@0
|
564 # $2 = module full path
|
slaxemulator@0
|
565 # $3 = destination folder, where images will be mounted to
|
slaxemulator@0
|
566 # $4 = preffix length strip (number of characters)
|
slaxemulator@0
|
567 #
|
slaxemulator@0
|
568 union_insert_module()
|
slaxemulator@0
|
569 {
|
slaxemulator@0
|
570 debug_log "union_insert_module" "$*"
|
slaxemulator@0
|
571 local TARGET
|
slaxemulator@0
|
572
|
slaxemulator@0
|
573 TARGET="$3/$(basename $2)"
|
slaxemulator@0
|
574 if ismountpoint $TARGET; then return 1; fi # skip already used modules
|
slaxemulator@0
|
575 mkdir -p $TARGET
|
slaxemulator@0
|
576 mount_module $2 $TARGET
|
slaxemulator@0
|
577 if [ $? -ne 0 ]; then echo "Cannot read module data. corrupted download?" >&2; return 1; fi
|
slaxemulator@0
|
578 union_insert_dir $1 $TARGET
|
slaxemulator@0
|
579 if [ $? -ne 0 ]; then echo "can't insert module to union" >&2; return 2; fi
|
slaxemulator@0
|
580 echo "$2" | cut -b $(($4+1))-
|
slaxemulator@0
|
581 echolog "$2" >/dev/null
|
slaxemulator@0
|
582 return 0
|
slaxemulator@0
|
583 }
|
slaxemulator@0
|
584
|
slaxemulator@0
|
585 # Insert all filesystem modules from $2 directory and subdirectories, to the union
|
slaxemulator@0
|
586 # $1 = union absolute path (starting with /)
|
slaxemulator@0
|
587 # $2 = LiveCD data dir (with directories /base, /modules, etc.)
|
slaxemulator@0
|
588 # $3 = destination folder, where images will be mounted to
|
slaxemulator@0
|
589 #
|
slaxemulator@0
|
590 union_insert_modules()
|
slaxemulator@0
|
591 {
|
slaxemulator@0
|
592 debug_log "union_insert_modules" "$*"
|
slaxemulator@0
|
593 local INSERTED
|
slaxemulator@0
|
594
|
slaxemulator@0
|
595 list_modules $2 | while read MODULE; do
|
slaxemulator@0
|
596 INSERTED=$(union_insert_module $1 $MODULE $3 ${#2})
|
slaxemulator@0
|
597 if [ "$INSERTED" != "" ]; then echolog " -> $(echo $INSERTED | sed -r s:^/::)"; fi
|
slaxemulator@0
|
598 done
|
slaxemulator@0
|
599 }
|
slaxemulator@0
|
600
|
slaxemulator@0
|
601 # Copy LiveCD modules to RAM directory
|
slaxemulator@0
|
602 # will copy only /boot, and module files from $1
|
slaxemulator@0
|
603 # $1 = data directory
|
slaxemulator@0
|
604 # $2 = target directory in RAM
|
slaxemulator@0
|
605 #
|
slaxemulator@0
|
606 copy_to_ram()
|
slaxemulator@0
|
607 {
|
slaxemulator@0
|
608 debug_log "copy_to_ram" "$*"
|
slaxemulator@0
|
609 cp -a "$1/rootcopy" "$2" 2>/dev/null # could be empty
|
slaxemulator@0
|
610 list_modules "$1" | while read MODULE; do
|
slaxemulator@0
|
611 TARGET=$(dirname "$MODULE" | cut -b ${#1}- | cut -b 2-)
|
slaxemulator@0
|
612 mkdir -p "$2/$TARGET"
|
slaxemulator@0
|
613 cp "$MODULE" "$2/$TARGET"
|
slaxemulator@0
|
614 if [ $? -ne 0 ]; then fatal "Not enough memory. Using ramsize=$RAMSIZE"; fi
|
slaxemulator@0
|
615 done
|
slaxemulator@0
|
616 }
|
slaxemulator@0
|
617
|
slaxemulator@0
|
618 # ===========================================================
|
slaxemulator@0
|
619 # discovery functions
|
slaxemulator@0
|
620 # ===========================================================
|
slaxemulator@0
|
621
|
slaxemulator@0
|
622 # List all supported network drivers
|
slaxemulator@0
|
623 #
|
slaxemulator@0
|
624 list_network_drivers()
|
slaxemulator@0
|
625 {
|
slaxemulator@0
|
626 debug_log "list_network_drivers" "$*"
|
slaxemulator@0
|
627
|
slaxemulator@0
|
628 # these drivers are probed in Slackware's initrd
|
slaxemulator@0
|
629 # (see initrd.img/scripts/network.sh).
|
slaxemulator@0
|
630 # I don't have personal experiences with most of these drivers
|
slaxemulator@0
|
631 # so I'll be happy if you report any particular one to be not working
|
slaxemulator@0
|
632 # (eg. causing hangups) in order to remove it from this list.
|
slaxemulator@0
|
633
|
slaxemulator@0
|
634 echo 3c59x acenic atl1 de4x5 dgrs eepro100 e1000 epic100 hp100 ne2k-pci \
|
slaxemulator@0
|
635 olympic pcnet32 r8169 rcpci 8139too 8139cp sktr skge sky2 tulip via-rhine \
|
slaxemulator@0
|
636 yellowfin tg3 dl2k ns83820 depca ibmtr 3c501 3c503 3c505 3c507 3c509 3c515 \
|
slaxemulator@0
|
637 ac3200 acenic at1700 cosa cs89x0 de4x5 de600 de620 e2100 eepro eexpress \
|
slaxemulator@0
|
638 es3210 eth16i ewrk3 fmv18x forcedeth hostess_sv11 hp-plus hp lne390 ne3210 \
|
slaxemulator@0
|
639 ni5010 ni52 ni65 sb1000 sealevel smc-ultra sis900 smc-ultra32 smc9194 wd \
|
slaxemulator@0
|
640 | tr " " "\n"
|
slaxemulator@0
|
641 }
|
slaxemulator@0
|
642
|
slaxemulator@0
|
643 # List all CD-ROMs
|
slaxemulator@0
|
644 # by using /proc entries
|
slaxemulator@0
|
645 #
|
slaxemulator@0
|
646 list_cdrom_devices()
|
slaxemulator@0
|
647 {
|
slaxemulator@0
|
648 debug_log "list_cdrom_devices" "$*"
|
slaxemulator@0
|
649 local CDDEVICE
|
slaxemulator@0
|
650
|
slaxemulator@0
|
651 for CDDEVICE in $(cat /proc/sys/dev/cdrom/info 2>/dev/null | head -n 3 | tail -n 1 | cut -d ":" -f 2); do
|
slaxemulator@0
|
652 echo "/dev/$CDDEVICE"
|
slaxemulator@0
|
653 done
|
slaxemulator@0
|
654 }
|
slaxemulator@0
|
655
|
slaxemulator@0
|
656 # List all mounted directories
|
slaxemulator@0
|
657 #
|
slaxemulator@0
|
658 list_mounted_directories()
|
slaxemulator@0
|
659 {
|
slaxemulator@0
|
660 debug_log "list_mounted_directories" "$*"
|
slaxemulator@0
|
661 if [ "$MOUNTDIR" ]; then
|
slaxemulator@0
|
662 ls -1 $MOUNTDIR | while read DIR; do
|
slaxemulator@0
|
663 if ismountpoint $MOUNTDIR/$DIR; then echo $DIR; fi
|
slaxemulator@0
|
664 done
|
slaxemulator@0
|
665 fi
|
slaxemulator@0
|
666 }
|
slaxemulator@0
|
667
|
slaxemulator@0
|
668 # List all devices with filesystems
|
slaxemulator@0
|
669 # Return empty result when nohd parameter was given.
|
slaxemulator@0
|
670 #
|
slaxemulator@0
|
671 list_partition_devices()
|
slaxemulator@0
|
672 {
|
slaxemulator@0
|
673 debug_log "list_partition_devices" "$*"
|
slaxemulator@0
|
674 if [ "$(cmdline_parameter nohd)" != "" ]; then return 1; fi
|
slaxemulator@0
|
675 cat /proc/partitions | grep -v loop | grep -v major | grep -v '^$' | sed -r "s:^[0-9 ]+:/dev/:"
|
slaxemulator@0
|
676 if [ -e /dev/mapper/control ]; then # list LVM partitions if available
|
slaxemulator@0
|
677 ls -1 /dev/mapper/ | grep -v "^control\$" | sed -r "s:^:/dev/mapper/:"
|
slaxemulator@0
|
678 fi
|
slaxemulator@0
|
679 }
|
slaxemulator@0
|
680
|
slaxemulator@0
|
681 # List all disk devices
|
slaxemulator@0
|
682 #
|
slaxemulator@0
|
683 list_disk_devices()
|
slaxemulator@0
|
684 {
|
slaxemulator@0
|
685 debug_log "list_disk_devices" "$*"
|
slaxemulator@0
|
686 list_partition_devices | egrep -v "[0-9]"
|
slaxemulator@0
|
687 }
|
slaxemulator@0
|
688
|
slaxemulator@0
|
689 # List all partitions marked as Linux Swap
|
slaxemulator@0
|
690 #
|
slaxemulator@0
|
691 list_swap_devices()
|
slaxemulator@0
|
692 {
|
slaxemulator@0
|
693 debug_log "list_swap_devices" "$*"
|
slaxemulator@0
|
694 if [ "$(cmdline_parameter nohd)" != "" -o "$(cmdline_parameter noswap)" != "" ]; then return 1; fi
|
slaxemulator@0
|
695 blkid -t TYPE="swap" -o device
|
slaxemulator@0
|
696 }
|
slaxemulator@0
|
697
|
slaxemulator@0
|
698 # List all block devices
|
slaxemulator@0
|
699 #
|
slaxemulator@0
|
700 list_block_devices()
|
slaxemulator@0
|
701 {
|
slaxemulator@0
|
702 debug_log "list_block_devices" "$*"
|
slaxemulator@0
|
703 if [ "$(cmdline_parameter nocd)" = "" ]; then
|
slaxemulator@0
|
704 list_cdrom_devices
|
slaxemulator@0
|
705 fi
|
slaxemulator@0
|
706 list_partition_devices
|
slaxemulator@0
|
707 }
|
slaxemulator@0
|
708
|
slaxemulator@0
|
709 # Format mountdir for device. This function used to append _cdrom or _removable
|
slaxemulator@0
|
710 # suffix to the directory name so KDE was able to assign a nice icon for evey
|
slaxemulator@0
|
711 # device, but this should be done using HAL in KDE nowadays, so we do not
|
slaxemulator@0
|
712 # support these stupid suffixes anymore. Many people will be happy :)
|
slaxemulator@0
|
713 # $1 = device full path, eg. /dev/hda1
|
slaxemulator@0
|
714 #
|
slaxemulator@0
|
715 device_mountdir()
|
slaxemulator@0
|
716 {
|
slaxemulator@0
|
717 debug_log "device_mountdir" "$*"
|
slaxemulator@0
|
718 echo "/$MOUNTDIR/$(basename "$1")" | tr -s /
|
slaxemulator@0
|
719 }
|
slaxemulator@0
|
720
|
slaxemulator@0
|
721 # Find file-path on given device
|
slaxemulator@0
|
722 # First it mounts the device read-only. If then the 'path' is found,
|
slaxemulator@0
|
723 # then remount without RO flag (causes it to be mounted read-write if possible)
|
slaxemulator@0
|
724 # and return the path, else unmount and exit.
|
slaxemulator@0
|
725 # If the device/dev_directory is already mounted, preserve it mounted
|
slaxemulator@0
|
726 # $1 = device
|
slaxemulator@0
|
727 # $2 = path/filename
|
slaxemulator@0
|
728 #
|
slaxemulator@0
|
729 find_filepath()
|
slaxemulator@0
|
730 {
|
slaxemulator@0
|
731 debug_log "find_filepath" "$*"
|
slaxemulator@0
|
732 local DIR FOUND PRESERVE
|
slaxemulator@0
|
733
|
slaxemulator@0
|
734 DIR=$(device_mountdir $1)
|
slaxemulator@0
|
735 ismountpoint $DIR
|
slaxemulator@0
|
736 if [ $? -eq 0 ]; then
|
slaxemulator@0
|
737 PRESERVE="true"
|
slaxemulator@0
|
738 else
|
slaxemulator@0
|
739 mount_device $1 $DIR ro
|
slaxemulator@0
|
740 if [ $? -ne 0 ]; then rmdir $DIR 2>/dev/null; return 1; fi
|
slaxemulator@0
|
741 PRESERVE=""
|
slaxemulator@0
|
742 fi
|
slaxemulator@0
|
743
|
slaxemulator@0
|
744 FOUND=$(ls -A1d $DIR/$2 2>/dev/null | head -n 1 | tr -s '/')
|
slaxemulator@0
|
745
|
slaxemulator@0
|
746 if [ "$FOUND" = "" ]; then
|
slaxemulator@0
|
747 if [ "$PRESERVE" != "true" ]; then
|
slaxemulator@0
|
748 fumount $DIR
|
slaxemulator@0
|
749 rmdir $DIR 2>/dev/null
|
slaxemulator@0
|
750 fi
|
slaxemulator@0
|
751 return 1
|
slaxemulator@0
|
752 else
|
slaxemulator@0
|
753 # remount without the 'ro' option now, so use rw or defaults
|
slaxemulator@0
|
754 # Only in the case it was not mounted already before.
|
slaxemulator@0
|
755 if [ "$PRESERVE" != "true" ]; then
|
slaxemulator@0
|
756 fumount $DIR
|
slaxemulator@0
|
757 mount_device $1 $DIR
|
slaxemulator@0
|
758 if [ $? -ne 0 ]; then
|
slaxemulator@0
|
759 rmdir $DIR 2>/dev/null
|
slaxemulator@0
|
760 return 2
|
slaxemulator@0
|
761 fi
|
slaxemulator@0
|
762 fi
|
slaxemulator@0
|
763 echo "$FOUND"
|
slaxemulator@0
|
764 return 0
|
slaxemulator@0
|
765 fi
|
slaxemulator@0
|
766 }
|
slaxemulator@0
|
767
|
slaxemulator@0
|
768 # Find file in computer by mounting disks or other storage devices
|
slaxemulator@0
|
769 # and searching for $1 in the mounted directory
|
slaxemulator@0
|
770 # $1 = filename or device-path or devicepath/filename
|
slaxemulator@0
|
771 #
|
slaxemulator@0
|
772 find_file()
|
slaxemulator@0
|
773 {
|
slaxemulator@0
|
774 debug_log "find_file" "$*"
|
slaxemulator@0
|
775 local FIND DEVICE DEVPART PATHPART
|
slaxemulator@0
|
776
|
slaxemulator@0
|
777 # allow using /mnt/... as well as /dev/...
|
slaxemulator@0
|
778 FIND=$(echo "$1" | sed -r "s:^/mnt/:/dev/:")
|
slaxemulator@0
|
779
|
slaxemulator@0
|
780 # if parameter is just a device, echo it and exit
|
slaxemulator@0
|
781 if [ -b "$FIND" -o -c "$FIND" -o "$FIND" = "" ]; then echo "$FIND"; return; fi
|
slaxemulator@0
|
782
|
slaxemulator@0
|
783 # If path doesn't start with /dev/, try to find the exact path on all devices
|
slaxemulator@0
|
784 # First, split DEV/PATH parts
|
slaxemulator@0
|
785 DEVPART=$(echo "$FIND" | egrep -o "^/dev/[^/]+")
|
slaxemulator@0
|
786
|
slaxemulator@0
|
787 if [ "$DEVPART" = "" ]; then
|
slaxemulator@0
|
788 # no device is specified. Search all devices for filename $FIND
|
slaxemulator@0
|
789 PATHPART="$FIND";
|
slaxemulator@0
|
790 for DEVICE in $(list_mounted_directories) $(list_block_devices); do
|
slaxemulator@0
|
791 if ! grep -q ":$DEVICE@$PATHPART:" /tmp/_findfile 2>/dev/null; then
|
slaxemulator@0
|
792 find_filepath "$DEVICE" "$PATHPART"
|
slaxemulator@0
|
793 if [ $? -eq 0 ]; then return 0; fi
|
slaxemulator@0
|
794 echo ":$DEVICE@$PATHPART:" >>/tmp/_findfile
|
slaxemulator@0
|
795 fi
|
slaxemulator@0
|
796 done
|
slaxemulator@0
|
797 else
|
slaxemulator@0
|
798 # try to find PATHPART only on the given device
|
slaxemulator@0
|
799 PATHPART=$(echo "$FIND" | sed -r 's:^/dev/[^/]+(.*):\1:')
|
slaxemulator@0
|
800 find_filepath $DEVPART $PATHPART
|
slaxemulator@0
|
801 fi
|
slaxemulator@0
|
802 }
|
slaxemulator@0
|
803
|
slaxemulator@0
|
804 # Find In Computer
|
slaxemulator@0
|
805 # use 'find_file' function to find the given file/dir
|
slaxemulator@0
|
806 # if nothing found, sleep for a while to allow devices to settle and try again.
|
slaxemulator@0
|
807 # (is there any way to find out if there are devices queued through /sys?)
|
slaxemulator@0
|
808 # $1 = file or directory to find
|
slaxemulator@0
|
809 #
|
slaxemulator@0
|
810 find_in_computer()
|
slaxemulator@0
|
811 {
|
slaxemulator@0
|
812 debug_log "find_in_computer" "$*"
|
slaxemulator@0
|
813 local TIMEOUT RESULT
|
slaxemulator@0
|
814
|
slaxemulator@0
|
815 TIMEOUT=$(cmdline_value scantimeout | sed -r 's/[^0-9]*([0-9]+).*/\1/')
|
slaxemulator@0
|
816 if [ "$TIMEOUT" = "" ]; then TIMEOUT=10; fi
|
slaxemulator@0
|
817
|
slaxemulator@0
|
818 RESULT=$(find_file "$1")
|
slaxemulator@0
|
819
|
slaxemulator@0
|
820 while [ $TIMEOUT -gt 0 -a "$RESULT" = "" ]; do
|
slaxemulator@0
|
821 echo -ne "- wait a while\r" >&2
|
slaxemulator@0
|
822 sleep 1
|
slaxemulator@0
|
823 TIMEOUT=$((TIMEOUT-1))
|
slaxemulator@0
|
824 RESULT=$(find_file "$1")
|
slaxemulator@0
|
825 done
|
slaxemulator@0
|
826
|
slaxemulator@0
|
827 echo $RESULT
|
slaxemulator@0
|
828 }
|
slaxemulator@0
|
829
|
slaxemulator@0
|
830 # Find and run all scripts from the given module
|
slaxemulator@0
|
831 # This function is used by the activate and deactivate script when the distro
|
slaxemulator@0
|
832 # is already started, not during live setup
|
slaxemulator@0
|
833 # $1 = mounted module full path
|
slaxemulator@0
|
834 # $2..$n = optional arguments for the scripts, eg. 'start'
|
slaxemulator@0
|
835 #
|
slaxemulator@0
|
836 find_n_run_scripts()
|
slaxemulator@0
|
837 {
|
slaxemulator@0
|
838 debug_log "find_n_run_scripts" "$*"
|
slaxemulator@0
|
839 local MOD
|
slaxemulator@0
|
840
|
slaxemulator@0
|
841 MOD="$1"
|
slaxemulator@0
|
842 shift
|
slaxemulator@0
|
843
|
slaxemulator@0
|
844 if [ -d $MOD/etc/rc.d -o -d $MOD/etc/rc.d/init.d -o -d $MOD/etc/init.d ]; then
|
slaxemulator@0
|
845 ( find $MOD/etc/rc.d -type f -maxdepth 1 2>/dev/null ; \
|
slaxemulator@0
|
846 find $MOD/etc/init.d -type f -maxdepth 1 2>/dev/null ; \
|
slaxemulator@0
|
847 find $MOD/etc/rc.d/init.d -type f -maxdepth 1 2>/dev/null \
|
slaxemulator@0
|
848 ) | cut -b ${#MOD}- | cut -b 2- | xargs -n 1 -r readlink -f | sort -u | while read SCRIPT; do
|
slaxemulator@0
|
849 if [ "$SCRIPT" != "" -a -x "$SCRIPT" -a ! -d "$SCRIPT" ]; then
|
slaxemulator@0
|
850 # call the script by real path, not from the module
|
slaxemulator@0
|
851 log "starting '$SCRIPT $@'"
|
slaxemulator@0
|
852 ${SCRIPT} "$@"
|
slaxemulator@0
|
853 fi
|
slaxemulator@0
|
854 done
|
slaxemulator@0
|
855 fi
|
slaxemulator@0
|
856 }
|
slaxemulator@0
|
857
|
slaxemulator@0
|
858 # ===========================================================
|
slaxemulator@0
|
859 # hardware preparation functions
|
slaxemulator@0
|
860 # ===========================================================
|
slaxemulator@0
|
861
|
slaxemulator@0
|
862 # Create block devices to /dev described by /sys entries
|
slaxemulator@0
|
863 #
|
slaxemulator@0
|
864 mdev_start_hotplug()
|
slaxemulator@0
|
865 {
|
slaxemulator@0
|
866 debug_log "mdev_start_hotplug" "$*"
|
slaxemulator@0
|
867 echolog "Creating /dev entries for block devices"
|
slaxemulator@0
|
868 mdev -s
|
slaxemulator@0
|
869 #rm /dev/pty??* /dev/tty??* # remove unneeded pty and tty devices
|
slaxemulator@0
|
870 echo /bin/mdev > /proc/sys/kernel/hotplug # use mdev as a hotplug handler
|
slaxemulator@0
|
871 }
|
slaxemulator@0
|
872
|
slaxemulator@0
|
873 # Modprobe kernel modules needed for the LiveCD
|
slaxemulator@0
|
874 #
|
slaxemulator@0
|
875 modprobe_essential_modules()
|
slaxemulator@0
|
876 {
|
slaxemulator@0
|
877 debug_log "modprobe_essential_modules" "$*"
|
slaxemulator@0
|
878
|
slaxemulator@0
|
879 echolog "Loading filesystems modules ..."
|
slaxemulator@0
|
880 modprobe_module loop
|
slaxemulator@0
|
881 modprobe_module isofs
|
slaxemulator@0
|
882 #modprobe_module sqlzma
|
slaxemulator@0
|
883 modprobe_module squashfs
|
slaxemulator@0
|
884 #modprobe_module unlzma
|
slaxemulator@0
|
885 modprobe_module aufs brs=1
|
slaxemulator@0
|
886 modprobe_module ext2
|
slaxemulator@0
|
887 modprobe_module ext3
|
slaxemulator@0
|
888 modprobe_module ext4
|
slaxemulator@0
|
889 modprobe_module btrfs
|
slaxemulator@0
|
890 modprobe_module reiserfs
|
slaxemulator@0
|
891 modprobe_module xfs
|
slaxemulator@0
|
892 modprobe_module vfat
|
slaxemulator@0
|
893 modprobe_module fuse # for ntfs-3g
|
slaxemulator@0
|
894 modprobe_module ntfs # for ro driver
|
slaxemulator@0
|
895 }
|
slaxemulator@0
|
896
|
slaxemulator@0
|
897 # Modprobe kernel modules needed for USB masstorage devices
|
slaxemulator@0
|
898 #
|
slaxemulator@0
|
899 modprobe_usb_modules()
|
slaxemulator@0
|
900 {
|
slaxemulator@0
|
901 debug_log "modprobe_usb_modules" "$*"
|
slaxemulator@0
|
902 local LSPCI
|
slaxemulator@0
|
903
|
slaxemulator@0
|
904 # skip module loading if nohotplug bootparam is present
|
slaxemulator@0
|
905 if [ "$(cmdline_parameter nohotplug)" ]; then return 0; fi
|
slaxemulator@0
|
906
|
slaxemulator@0
|
907 LSPCI=$(lspci -v | grep -i prog-if)
|
slaxemulator@0
|
908 if [ "$(echo $LSPCI | egrep -i [eou]hci)" = "" ]; then
|
slaxemulator@0
|
909 return 0
|
slaxemulator@0
|
910 fi
|
slaxemulator@0
|
911
|
slaxemulator@0
|
912 echolog "Loading USB modules ..."
|
slaxemulator@0
|
913 if [ "$(echo $LSPCI | grep -i ehci)" != "" ]; then
|
slaxemulator@0
|
914 modprobe_module ehci-hcd
|
slaxemulator@0
|
915 fi
|
slaxemulator@0
|
916 if [ "$(echo $LSPCI | grep -i ohci)" != "" ]; then
|
slaxemulator@0
|
917 modprobe_module ohci-hcd
|
slaxemulator@0
|
918 fi
|
slaxemulator@0
|
919 if [ "$(echo $LSPCI | grep -i uhci)" != "" ]; then
|
slaxemulator@0
|
920 modprobe_module uhci-hcd
|
slaxemulator@0
|
921 fi
|
slaxemulator@0
|
922 modprobe_module usb-storage
|
slaxemulator@0
|
923 }
|
slaxemulator@0
|
924
|
slaxemulator@0
|
925 # Load drivers for PCMCIA CardBus devices
|
slaxemulator@0
|
926 #
|
slaxemulator@0
|
927 modprobe_pcmcia_modules()
|
slaxemulator@0
|
928 {
|
slaxemulator@0
|
929 debug_log "modprobe_pcmcia_modules" "$*"
|
slaxemulator@0
|
930
|
slaxemulator@0
|
931 # skip module loading if nohotplug bootparam is present
|
slaxemulator@0
|
932 if [ "$(cmdline_parameter nohotplug)" ]; then return 0; fi
|
slaxemulator@0
|
933
|
slaxemulator@0
|
934 echolog "Loading PCMCIA CardBus modules ..."
|
slaxemulator@0
|
935 modprobe_module pcmcia_core
|
slaxemulator@0
|
936 modprobe_module pcmcia
|
slaxemulator@0
|
937 modprobe_module rsrc_nonstatic
|
slaxemulator@0
|
938 modprobe_module yenta_socket
|
slaxemulator@0
|
939 }
|
slaxemulator@0
|
940
|
slaxemulator@0
|
941 # Load network drivers unless eth[0-9] is found
|
slaxemulator@0
|
942 #
|
slaxemulator@0
|
943 modprobe_network_modules()
|
slaxemulator@0
|
944 {
|
slaxemulator@0
|
945 debug_log "modprobe_network_modules" "$*"
|
slaxemulator@0
|
946 local ETH
|
slaxemulator@0
|
947
|
slaxemulator@0
|
948 # skip module loading if nohotplug bootparam is present
|
slaxemulator@0
|
949 if [ "$(cmdline_parameter nohotplug)" ]; then return 0; fi
|
slaxemulator@0
|
950
|
slaxemulator@0
|
951 # probe all drivers. Start by the ones mentioned in pcimodules' output
|
slaxemulator@0
|
952 for module in $(list_network_drivers | egrep "$(pcimodules | tr "\n" "|")!") $(list_network_drivers); do
|
slaxemulator@0
|
953 modprobe_module $module
|
slaxemulator@0
|
954 ETH=$(cat /proc/net/dev | grep : | grep -v lo: | cut -d : -f 1 | tr -d " ")
|
slaxemulator@0
|
955 if [ "$ETH" != "" ]; then
|
slaxemulator@0
|
956 echo $ETH
|
slaxemulator@0
|
957 return 0
|
slaxemulator@0
|
958 fi
|
slaxemulator@0
|
959 rmmod $module 2>/dev/null
|
slaxemulator@0
|
960 done
|
slaxemulator@0
|
961 }
|
slaxemulator@0
|
962
|
slaxemulator@0
|
963 # Start udhcpc to get IP address from DHCP server
|
slaxemulator@0
|
964 # $1 = interface to use (optional)
|
slaxemulator@0
|
965 #
|
slaxemulator@0
|
966 init_dhcp()
|
slaxemulator@0
|
967 {
|
slaxemulator@0
|
968 debug_log "start_dhcp_client" "$*"
|
slaxemulator@0
|
969
|
slaxemulator@0
|
970 if [ "$1" != "" ]; then
|
slaxemulator@0
|
971 ifconfig $1 up
|
slaxemulator@0
|
972 udhcpc -i $1 -q
|
slaxemulator@0
|
973 else
|
slaxemulator@0
|
974 ifconfig eth0 up
|
slaxemulator@0
|
975 udhcpc -q
|
slaxemulator@0
|
976 fi
|
slaxemulator@0
|
977 }
|
slaxemulator@0
|
978
|
slaxemulator@0
|
979 # Mount http filesystem from the given server
|
slaxemulator@0
|
980 # $1 = server
|
slaxemulator@0
|
981 # $2 = mountdir
|
slaxemulator@0
|
982 #
|
slaxemulator@0
|
983 mount_httpfs()
|
slaxemulator@0
|
984 {
|
slaxemulator@0
|
985 debug_log "mount_httpfs" "$*"
|
slaxemulator@0
|
986
|
slaxemulator@0
|
987 mkdir -p $2
|
slaxemulator@0
|
988 httpfs $1 $2
|
slaxemulator@0
|
989 }
|
slaxemulator@0
|
990
|
slaxemulator@0
|
991
|
slaxemulator@0
|
992 # Unload modules loaded to kernel which are not used
|
slaxemulator@0
|
993 # This function used to unload more modules, but it may cause
|
slaxemulator@0
|
994 # problems to auto-remove some of them (eg. a network module
|
slaxemulator@0
|
995 # can seem unneeded even if network is to be used very soon.
|
slaxemulator@0
|
996 #
|
slaxemulator@0
|
997 rmmod_unused_modules()
|
slaxemulator@0
|
998 {
|
slaxemulator@0
|
999 debug_log "rmmod_unused_modules" "$*"
|
slaxemulator@0
|
1000 rmmod usb-storage uhci-hcd ohci-hcd ehci-hcd 2>/dev/null
|
slaxemulator@0
|
1001 rmmod yenta_socket rsrc_nonstatic pcmcia pcmcia_core 2>/dev/null
|
slaxemulator@0
|
1002 }
|
slaxemulator@0
|
1003
|
slaxemulator@0
|
1004 # kill all unneeded processes, which have bigger PID then the PID of
|
slaxemulator@0
|
1005 # current shell. We can't use killall5, as it would kill some processes
|
slaxemulator@0
|
1006 # which may be currently needed, for example ntfs-3g.
|
slaxemulator@0
|
1007 # $1 = maximum pid (kill all lower)
|
slaxemulator@0
|
1008 #
|
slaxemulator@0
|
1009 killall_unneeded()
|
slaxemulator@0
|
1010 {
|
slaxemulator@0
|
1011 debug_log "killall_unneeded" "$*"
|
slaxemulator@0
|
1012 local LIST PID
|
slaxemulator@0
|
1013
|
slaxemulator@0
|
1014 PID=$1
|
slaxemulator@0
|
1015 for pid in $(ps | grep -v "PID" | egrep -v "\[.*\]" | fgrep -v mount | fgrep -v posixovl | fgrep -v ntfs | sed -r "s/^[[:space:]]*([0-9]+).*/\\1/"); do
|
slaxemulator@0
|
1016 if [ $pid -lt $PID ]; then
|
slaxemulator@0
|
1017 LIST="$LIST $pid"
|
slaxemulator@0
|
1018 fi
|
slaxemulator@0
|
1019 done
|
slaxemulator@0
|
1020
|
slaxemulator@0
|
1021 kill -SIGTERM $LIST 2>/dev/null # SIGTERM
|
slaxemulator@0
|
1022 sleep 2
|
slaxemulator@0
|
1023 kill -SIGKILL $LIST 2>/dev/null # SIGKILL
|
slaxemulator@0
|
1024 }
|
slaxemulator@0
|
1025
|
slaxemulator@0
|
1026 # enable/disable CD autoejecting when unmounted
|
slaxemulator@0
|
1027 # $1 = 1|0 ... enable|disable
|
slaxemulator@0
|
1028 #
|
slaxemulator@0
|
1029 cd_autoeject()
|
slaxemulator@0
|
1030 {
|
slaxemulator@0
|
1031 debug_log "cd_autoeject" "$*"
|
slaxemulator@0
|
1032 echo $1 >/proc/sys/dev/cdrom/autoeject
|
slaxemulator@0
|
1033 }
|
slaxemulator@0
|
1034
|
slaxemulator@0
|
1035 # ===========================================================
|
slaxemulator@0
|
1036 # FSTAB functions
|
slaxemulator@0
|
1037 # ===========================================================
|
slaxemulator@0
|
1038
|
slaxemulator@0
|
1039 # $1 = fstab file
|
slaxemulator@0
|
1040 # $2 = device name
|
slaxemulator@0
|
1041 dev_is_in_fstab()
|
slaxemulator@0
|
1042 {
|
slaxemulator@0
|
1043 debug_log "dev_is_in_fstab" "$*"
|
slaxemulator@0
|
1044 cat "$1" | sed -r "s/#.*//" | egrep -q "^[[:space:]]*$2[[:space:]]"
|
slaxemulator@0
|
1045 }
|
slaxemulator@0
|
1046
|
slaxemulator@0
|
1047 # update given line in fstab, add new values only if the device is not found
|
slaxemulator@0
|
1048 # $1 = fstab file to parse
|
slaxemulator@0
|
1049 # $2 = device name
|
slaxemulator@0
|
1050 # $3 = mountpoint
|
slaxemulator@0
|
1051 # $4 = filesystem
|
slaxemulator@0
|
1052 # $5 = mount options
|
slaxemulator@0
|
1053 #
|
slaxemulator@0
|
1054 fstab_add_line()
|
slaxemulator@0
|
1055 {
|
slaxemulator@0
|
1056 debug_log "fstab_add_line" "$*"
|
slaxemulator@0
|
1057 local DIR
|
slaxemulator@0
|
1058
|
slaxemulator@0
|
1059 if [ "$4" != "swap" ]; then DIR="$3"; else DIR="none"; fi
|
slaxemulator@0
|
1060 if ! dev_is_in_fstab "$1" "$2"; then
|
slaxemulator@0
|
1061 echo "$2" "$DIR" "$4" "$5" 0 0 "$FSTABLLFLAG" >>$1
|
slaxemulator@0
|
1062 fi
|
slaxemulator@0
|
1063 }
|
slaxemulator@0
|
1064
|
slaxemulator@0
|
1065 # create correct fstab file in $1/etc/fstab and create apropriate
|
slaxemulator@0
|
1066 # mount directories in $1/mnt. This function is only calld once,
|
slaxemulator@0
|
1067 # during liveCD startup (even before init from the distro is started).
|
slaxemulator@0
|
1068 # $1 = root directory (union)
|
slaxemulator@0
|
1069 #
|
slaxemulator@0
|
1070 fstab_update()
|
slaxemulator@0
|
1071 {
|
slaxemulator@0
|
1072 debug_log "fstab_update" "$*"
|
slaxemulator@0
|
1073 local FSTAB FSTABTMP
|
slaxemulator@0
|
1074
|
slaxemulator@0
|
1075 FSTAB="$1/etc/fstab"
|
slaxemulator@0
|
1076 FSTABTMP=$FSTAB$$
|
slaxemulator@0
|
1077 mkdir -p $1/etc $1/mnt
|
slaxemulator@0
|
1078 cat $FSTAB 2>/dev/null | grep -v "$FSTABLLFLAG" >$FSTABTMP
|
slaxemulator@0
|
1079
|
slaxemulator@0
|
1080 fstab_add_line $FSTABTMP none / unionfs defaults
|
slaxemulator@0
|
1081 fstab_add_line $FSTABTMP none /proc proc defaults
|
slaxemulator@0
|
1082 fstab_add_line $FSTABTMP none /sys sysfs defaults
|
slaxemulator@0
|
1083 fstab_add_line $FSTABTMP none /dev/pts devpts gid=5,mode=620
|
slaxemulator@0
|
1084 fstab_add_line $FSTABTMP tmpfs /dev/shm tmpfs defaults
|
slaxemulator@0
|
1085
|
slaxemulator@0
|
1086 list_cdrom_devices | while read DEVICE; do
|
slaxemulator@0
|
1087 MNT=$(device_mountdir $DEVICE)
|
slaxemulator@0
|
1088 FS=$(device_filesystem $DEVICE)
|
slaxemulator@0
|
1089 if [ "$FS" = "" ]; then FS=iso9660,udf; fi
|
slaxemulator@0
|
1090 mkdir -p "$1/$MNT"
|
slaxemulator@0
|
1091 fstab_add_line $FSTABTMP $DEVICE $MNT $FS $(fs_options $FS fstab)
|
slaxemulator@0
|
1092 done
|
slaxemulator@0
|
1093 list_partition_devices | while read DEVICE; do
|
slaxemulator@0
|
1094 MNT=$(device_mountdir $DEVICE)
|
slaxemulator@0
|
1095 FS=$(device_filesystem $DEVICE)
|
slaxemulator@0
|
1096 OPT=$(fs_options $FS fstab)
|
slaxemulator@0
|
1097
|
slaxemulator@0
|
1098 if [ "$FS" = "swap" ]; then
|
slaxemulator@0
|
1099 fstab_add_line $FSTABTMP $DEVICE $MNT $FS $OPT
|
slaxemulator@0
|
1100 fi
|
slaxemulator@0
|
1101
|
slaxemulator@0
|
1102 # If the partition has a valid filesystem, add it to fstab
|
slaxemulator@0
|
1103 if is_supported_filesystem "$FS"; then
|
slaxemulator@0
|
1104 fstab_add_line $FSTABTMP $DEVICE $MNT $FS $OPT
|
slaxemulator@0
|
1105 mkdir -p "$1/$MNT"
|
slaxemulator@0
|
1106 fi
|
slaxemulator@0
|
1107 done
|
slaxemulator@0
|
1108
|
slaxemulator@0
|
1109 mv -f $FSTABTMP $FSTAB
|
slaxemulator@0
|
1110 }
|
slaxemulator@0
|
1111
|
slaxemulator@0
|
1112 # create correct fstab file in $1/etc/fstab only with aufs,proc,sysfs and devpts
|
slaxemulator@0
|
1113 # No partition will be mounted and mount point created
|
slaxemulator@0
|
1114 # HAL is going to manage mount points and medias
|
slaxemulator@0
|
1115 fstab_clean()
|
slaxemulator@0
|
1116 {
|
slaxemulator@0
|
1117 debug_log "fstab_update" "$*"
|
slaxemulator@0
|
1118 local FSTAB FSTABTMP
|
slaxemulator@0
|
1119
|
slaxemulator@0
|
1120 FSTAB="$1/etc/fstab"
|
slaxemulator@0
|
1121 FSTABTMP=$FSTAB$$
|
slaxemulator@0
|
1122 mkdir -p $1/etc $1/mnt
|
slaxemulator@0
|
1123 cat $FSTAB 2>/dev/null | grep -v "$FSTABLLFLAG" >$FSTABTMP
|
slaxemulator@0
|
1124
|
slaxemulator@0
|
1125 fstab_add_line $FSTABTMP aufs / aufs defaults
|
slaxemulator@0
|
1126 fstab_add_line $FSTABTMP proc /proc proc defaults
|
slaxemulator@0
|
1127 fstab_add_line $FSTABTMP sysfs /sys sysfs defaults
|
slaxemulator@0
|
1128 fstab_add_line $FSTABTMP devpts /dev/pts devpts gid=5,mode=620
|
slaxemulator@0
|
1129 fstab_add_line $FSTABTMP tmpfs /dev/shm tmpfs defaults
|
slaxemulator@0
|
1130 mv -f $FSTABTMP $FSTAB
|
slaxemulator@0
|
1131 }
|