Implement ZFS Support
[genkernel.git] / defaults / initrd.scripts
1 #!/bin/ash
2
3 . /etc/initrd.defaults
4
5 backup() {
6         echo -ne "\033[0G\033[0K"
7 }
8
9 modules_load() {
10         for module in $*
11         do
12                 echo ${module} >> /etc/modules/extra_load
13         done
14
15         modules_scan extra_load
16 }
17
18 modules_scan() {
19         local MODS
20         [ -d "/etc/modules/${1}" ] || touch /etc/modules/${1}
21
22         [ -f "/etc/modules/${1}" ] && MODS=`cat /etc/modules/${1}`
23         for x in ${MODS}
24         do
25                 MLOAD=`echo ${MLIST} | sed -e "s/.*${x}.*/${x}/"`
26                 if [ "${MLOAD}" = "${x}" ] # Only module to no-load
27                 then
28                         echo -e "${BOLD}   ::${NORMAL} Skipping ${x}..."
29                 elif [ "${MLOAD}" = "${MLIST}" ] # == No change == No specified no-load
30                 then
31                         [ -n "${DEBUG}" ] && echo -ne "${BOLD}   ::${NORMAL} Checking for ${x}..."
32                         # find -name does not work since the return status is always zero
33                         if find /lib/modules/${KV} | grep /"${x}${KSUFF}" >/dev/null 2>&1
34                         then
35                                 echo -ne "${BOLD}   ::${NORMAL} Scanning for ${x}..."
36                                 modprobe ${x} -n
37                                 backup
38                                 echo -ne "${NORMAL}"
39                         fi
40                 else
41                         echo -e "${BOLD}   ::${NORMAL} Skipping ${x}..."
42                 fi
43         done
44 }
45
46 uppercase(){
47         # needs tr on busybox
48         echo $1 | tr 'a-z' 'A-Z'
49 }
50
51
52 findmediamount() {
53         # $1 = mount dir name / media name
54         # $2 = recognition file
55         # $3 = variable to have the device path
56         # $4 = actual mount dir path (full path)
57         # args remaining are possible devices 
58
59         local media=$1 recon=$2 vrbl=$3 mntdir=$4
60         shift 4
61
62         good_msg "Looking for the ${media}" ${CRYPT_SILENT}
63
64         if [ "$#" -gt "0" ]
65         then
66                 [ ! -d "${mntdir}" ] && mkdir -p ${mntdir} 2>/dev/null >/dev/null
67                 if [ -n "${ISOBOOT}" ]
68                 then
69                         mntcddir="${mntdir%${media}}iso"
70                         if [ ! -f ${mntcddir} ]
71                         then
72                                 mkdir ${mntcddir}
73                         fi
74                 else
75                         mntcddir=${mntdir}
76                 fi
77
78                 for x in $*
79                 do
80                         # Check for a block device to mount
81                         if [ -b "${x}" ]
82                         then
83                                 skip=0
84                                 bsn=`basename "${x}"`
85                                 #
86                                 # If disk and it has at least one partition, skip.
87                                 # We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
88                                 # don't skip device mapper devices. Even the craziest scenario
89                                 # deserves a fair chance.
90                                 #
91                                 for part in `ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null`
92                                 do
93                                         skip=1
94                                         break;
95                                 done
96                                 if [ ${skip} -eq 1 ]
97                                 then
98                                         continue
99                                 fi
100                                 good_msg "Attempting to mount media:- ${x}" ${CRYPT_SILENT}
101
102                                 mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1
103                                 if [ "$?" = '0' ]
104                                 then
105                                         if [ -n "${ISOBOOT}" ]; then
106                                                 if [ -f ${mntcddir}/${ISOBOOT} ]; then
107                                                         mount -o loop ${mntcddir}/${ISOBOOT} ${mntdir}
108                                                         if [ "$?" = "0" ]; then
109                                                                 good_msg "iso mounted on ${mntdir}"
110                                                         fi
111                                                 fi
112                                         fi
113
114                                         # Check for the media
115                                         if [ -f "${mntdir}/${recon}" ]
116                                         then
117                                                 #set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
118                                                 eval ${vrbl}'='"${x}"
119                                                 good_msg "Media found on ${x}" ${CRYPT_SILENT}
120                                                 break
121                                         else
122                                                 umount ${mntcddir}
123                                         fi
124                                 fi
125                         fi
126                 done
127         fi
128
129         eval local result='$'${vrbl}
130
131         [ -n "${result}" ] || bad_msg "Media not found" ${CRYPT_SILENT}
132 }
133
134 devicelist(){
135         # Locate the cdrom device with our media on it.
136         # CDROM DEVICES
137         local DEVICES="/dev/cdroms/* /dev/ide/cd/* /dev/sr*"
138         # USB Keychain/Storage
139         DEVICES="$DEVICES /dev/sd*"
140         # IDE devices
141         DEVICES="$DEVICES /dev/hd*"
142         # virtio devices
143         DEVICES="$DEVICES /dev/vd*"
144         # USB using the USB Block Driver
145         DEVICES="$DEVICES /dev/ubd* /dev/ubd/*"
146         # iSeries devices
147         DEVICES="$DEVICES /dev/iseries/vcd*"
148         # builtin mmc/sd card reader devices
149         DEVICES="$DEVICES /dev/mmcblk* /dev/mmcblk*/*"
150         # fallback scanning, this might scan something twice, but it's better than
151         # failing to boot.
152         [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk -r '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
153         echo ${DEVICES}
154 }
155
156 bootstrapCD() {
157         local DEVICES=`devicelist`
158         # The device was specified on the command line, so there's no need to scan
159         # a bunch of extra devices
160         [ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}"
161
162         findmediamount "cdrom" "${SUBDIR}/livecd" "REAL_ROOT" "${CDROOT_PATH}" ${DEVICES}
163 }
164
165 bootstrapKey() {
166         # $1 = ROOT/SWAP
167         local KEYDEVS=`devicelist`
168         eval local keyloc='"${CRYPT_'${1}'_KEY}"'
169
170         findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS}
171 }
172
173 cache_cd_contents() {
174         # Check loop file exists and cache to ramdisk if DO_cache is enabled
175         if [ "${LOOPTYPE}" != "noloop" ] && [ "${LOOPTYPE}" != "sgimips" ]
176         then
177                 check_loop
178                 if [ "${DO_cache}" ]
179                 then
180                         # TODO: Check the size of the image versus the size of our tmpfs
181                         # along with the amount of available RAM and increase tmpfs size
182                         # if necessary. (Not having awk sucks...)
183                         # z=0
184                         # for i in $(cat /proc/meminfo | grep -e ^MemFree -e ^Cached | \
185                         # cut -d: -f2 | cut -dk -f1 | sed -e "s/^\s*//") ; do
186                         # z=$(($z + $i)) ; done
187                         # echo $z
188                         good_msg "Copying loop file for caching..."
189                         # Verify that the needed directory exists
190                         mkdir -p "$(dirname ${NEW_ROOT}/mnt/${LOOP})"
191                         cp -a ${CDROOT_PATH}/${LOOP} ${NEW_ROOT}/mnt/${LOOP}
192                         if [ $? -ne 0 ]
193                         then
194                                 bad_msg "Failed to cache the loop file! Lack of space?"
195                                 rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null
196                                 rm -rf ${NEW_ROOT}/mnt/image.* 2>/dev/null
197                                 rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null
198                         else
199                                 LOOPEXT='../'
200                         fi
201                 fi
202         fi
203 }
204
205 mount_sysfs() {
206         mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null 2>&1
207         ret=$?
208         [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!"
209 }
210
211 findnfsmount() {
212         if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q
213         then
214                 [ -e /rootpath ] && NFSROOT=`cat /rootpath`
215
216                 if [ "${NFSROOT}" = '' ]
217                 then
218                         # Obtain NFSIP  
219                         OPTIONS=`busybox dmesg | grep rootserver | sed -e "s/,/ /g"`
220                         for OPTION in $OPTIONS
221                         do
222                                 if [ `echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1` = 'rootserver' ]
223                                 then
224                                         NFSIP=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`
225                                 fi 
226                         done
227                         
228                         # Obtain NFSPATH
229                         OPTIONS=`busybox dmesg | grep rootpath | sed -e "s/,/ /g"`      
230                         for OPTION in $OPTIONS
231                         do
232                                 if [ `echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1` = 'rootpath' ]
233                                 then
234                                         NFSPATH=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`
235                                 fi
236                         done
237
238                         # Setup NFSROOT
239                         if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ]
240                         then
241                                 NFSROOT="${NFSIP}:${NFSPATH}"
242                         else
243                                 bad_msg "The DHCP Server did not send a valid root-path."
244                                 bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter."
245                         fi
246                 fi
247
248                 if [ "${NFSROOT}" != '' ]
249                 then
250                         NFSOPTIONS=${NFSROOT#*,}
251                         NFSROOT=${NFSROOT%%,*}
252                         if [ "${NFSOPTIONS}" = "${NFSROOT}" ]
253                         then
254                                 NFSOPTIONS=$DEFAULT_NFSOPTIONS
255                         else
256                                 NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}"
257                         fi
258
259                         if [ "${CDROOT}" != '0' ]
260                         then
261                                 good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}"
262                                 mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH}
263                                 if [ "$?" = '0' ]
264                                 then
265                                         REAL_ROOT="/dev/nfs"
266                                 else
267                                         bad_msg "NFS Mounting failed. Is the path corrent ?"
268                                 fi
269                         else    
270                                 good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}"
271                                 mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT}
272                                 if [ "$?" = '0' ]
273                                 then
274                                         REAL_ROOT="/dev/nfs"
275                                 else
276                                         bad_msg "NFS Mounting failed. Is the path correct ?"
277                                 fi
278                                 # FIXME: Need to start portmap and the other rpc daemons in
279                                 # order to remount rw.
280                         fi
281
282                 fi
283         fi
284 }
285
286 check_loop() {
287         if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ]
288         then
289         
290                 bad_msg "Invalid loop location: ${LOOP}"
291                 bad_msg 'Please export LOOP with a valid location, or reboot and pass a proper loop=...'
292                 bad_msg 'kernel command line!'
293         
294                 run_shell
295         fi
296 }
297
298 run_shell() {
299         /bin/ash
300 }
301
302 runmdev() {
303         # Use devtmpfs if enabled in kernel,
304         # else tmpfs. Always run mdev just in case
305         devfs=tmpfs
306         if grep -qs devtmpfs /proc/filesystems ; then
307                 devfs=devtmpfs
308         fi
309
310         # Options copied from /etc/init.d/udev-mount, should probably be kept in sync
311         mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \
312                 || bad_msg "Failed to mount /dev as ${devfs}"
313
314         # http://git.busybox.net/busybox/plain/docs/mdev.txt
315         mkdir -m 0755 /dev/pts
316         mount -t devpts -o gid=5,mode=0620 devpts /dev/pts  || bad_msg "Failed to mount /dev/pts"
317         mdev -s  || bad_msg "Failed to receive dynamic updates from mdev"
318 }
319
320 test_success() {
321         retcode=$?
322         # If last command failed send error message and fall back to a shell    
323         if [ "$retcode" != '0' ]
324         then
325                 error_string=$1
326                 error_string="${error_string:-run command}"
327                 bad_msg 'Failed to $1; failing back to the shell...'
328                 run_shell
329         fi
330 }
331
332
333 # msg functions arguments
334 # $1 string
335 # $2 hide flag
336
337 good_msg() {    
338         msg_string=$1
339         msg_string="${msg_string:-...}"
340         [ "$2" != 1 ] && echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
341 }
342
343 bad_msg() {
344         msg_string=$1
345         msg_string="${msg_string:-...}"
346         if [ "$2" != 1 ]
347         then
348                 splash 'verbose' > /dev/null &
349                 echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
350         fi
351
352
353 warn_msg() {
354         msg_string=$1
355         msg_string="${msg_string:-...}"
356         [ "$2" != 1 ] && echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
357 }
358
359 crypt_filter() {
360         if [ "${CRYPT_SILENT}" = '1' ]
361         then
362                 eval $1 >/dev/null 2>/dev/null
363         else
364                 splash 'verbose' > /dev/null &
365                 eval $1
366                 res=$?
367                 if [ ${res} -eq 0 ]
368                 then
369                         splash set_msg 'Disk unlocked.'
370                 fi
371                 return ${res}
372         fi
373 }
374
375 prompt_user(){
376         # $1 = variable whose value is the path (examples: "REAL_ROOT",
377         #      "LUKS_KEYDEV")
378         # $2 = label
379         # $3 = optional explanations for failure
380
381         eval local oldvalue='$'${1}
382
383         [ \( $# != 2 \) -a \( $# != 3 \) ] && \
384                 bad_msg "Bad invocation of function prompt_user, please file a bug \
385                 report with this message" && exit 1
386         [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="."
387         
388         bad_msg "Could not find the ${2} in ${oldvalue}${explnt}"
389         echo '   Please specify another value or: press Enter for the same, type "shell" for a shell, or "q" to skip...'
390         echo -n "${2}(${oldvalue}) :: "
391         read ${1}
392         case `eval echo '$'${1}` in
393                 'q')
394                         eval ${1}'='${oldvalue}
395                         warn_msg "Skipping step, this will likely cause a boot failure."
396                         break
397                         ;;
398                 'shell')
399                         eval ${1}'='${oldvalue}
400                         echo "To leave and try again just press <Ctrl>+D"
401                         run_shell
402                         ;;
403                 '')
404                         eval ${1}'='${oldvalue}
405                         ;;
406         esac
407 }
408
409 setup_hotplug() {
410         if [ "${KV_2_6_OR_GREATER}" ]
411         then
412                 echo /sbin/mdev > /proc/sys/kernel/hotplug
413         fi
414 }
415
416 setup_slowusb() {
417         # This function removes unset DO_slowusb if there is no usb-storage attached.
418         # If noslowusb is set, skip this function
419         [ "${DO_slowusb}" ] || return
420
421         # Unset DO_slowusb, so we can set it again if usb-storage has something attached
422         unset DO_slowusb
423
424         local usb_storage_dir="/sys/bus/usb/drivers/usb-storage"
425         if [ ! -d "${usb_storage_dir}" ]
426         then
427                 # no automated slowusb required. no usb-storage devices attached.
428                 return
429         fi
430         for x in "${usb_storage_dir}"/*
431         do
432                 [ -d "${x}" ]  && [ "${x}" != "${usb_storage_dir}/module" ] \
433                         && { DO_slowusb="1" ; break ; }
434         done
435 }
436
437 start_dev_mgr() {
438         if [ "${KV_2_6_OR_GREATER}" ]
439         then
440                 cd /sys
441                 good_msg 'Activating mdev'
442                 runmdev
443                 cd /
444         fi
445 }
446
447 cmdline_hwopts() {
448         # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
449         local FOUND
450         local TMP_HWOPTS
451
452         for x in $HWOPTS
453         do
454                 for y in $CMDLINE
455                 do
456                         if [ "${y}" = "do${x}" ]
457                         then
458                                 MY_HWOPTS="${MY_HWOPTS} $x"
459                         elif [ "${y}" = "no${x}" ]
460                         then
461                                 MY_HWOPTS="`echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -`"
462                         fi
463                         if [ "$(echo ${y} | cut -b -7)" = "keymap=" ]
464                         then
465                                 MY_HWOPTS="${MY_HWOPTS} keymap"
466                         fi
467                 done
468         done
469    
470         # Shouldnt need to sort this as the following loop should figure out the
471         # duplicates and strip them out
472         #MY_HWOPTS=`echo ${MY_HWOPTS}|  sort`
473         
474         for x in ${MY_HWOPTS}
475         do
476                 FOUND=0
477                 for y in ${TMP_HWOPTS}
478                 do
479                         if [ "${y}" = "${x}" ]
480                         then 
481                                 continue 2
482                         fi
483                 done
484                 TMP_HWOPTS="${TMP_HWOPTS} ${x}"
485                 eval DO_`echo ${x} | sed 's/-//'`=1
486         done
487
488         MY_HWOPTS=${TMP_HWOPTS}
489 }
490
491 load_modules() {
492         # Load modules listed in MY_HWOPTS if /lib/modules exists for the running
493         # kernel version
494         if [ -d "/lib/modules/${KV}" ]
495         then
496                 good_msg 'Loading modules'
497                 # Load appropriate kernel modules
498                 for modules in $MY_HWOPTS
499                 do
500                         modules_scan $modules
501                 done
502         else
503                 good_msg 'Skipping module load; no modules in the ramdisk!'
504         fi
505 }
506
507 setup_keymap() {
508         if [ "${DO_keymap}" ]
509         then
510                 if [ ! -e /dev/vc/0 -a ! -e /dev/tty0 ]
511                 then
512                         DEVBIND=1
513                         mount -o bind ${NEW_ROOT}/dev /dev
514                 fi
515                 [ ! -e /dev/tty0 ] && ln -s /dev/tty1 /dev/tty0
516
517                 [ -f /lib/keymaps/keymapList ] && chooseKeymap
518
519                 [ "${DEVBIND}" = '1' ] && umount /dev
520                 
521                 if [ -e /etc/sysconfig/keyboard -a "${CDROOT}" = '1' ]
522                 then
523                         mkdir -p ${NEW_ROOT}/etc/sysconfig/
524                         cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard
525                 fi
526         fi
527 }
528
529 chooseKeymap() {
530         good_msg "Loading keymaps"
531         if [ -z "${keymap}" ]
532         then
533                 splash 'verbose' > /dev/null &
534                 cat /lib/keymaps/keymapList
535                 read -t 10 -p '<< Load keymap (Enter for default): ' keymap
536                 case ${keymap} in
537                         1|azerty) keymap=azerty ;;
538                         2|be) keymap=be ;;
539                         3|bg) keymap=bg ;;
540                         4|br-a) keymap=br-a ;;
541                         5|br-l) keymap=br-l ;;
542                         6|by) keymap=by ;;
543                         7|cf) keymap=cf ;;
544                         8|croat) keymap=croat ;;
545                         9|cz) keymap=cz ;;
546                         10|de) keymap=de ;;
547                         11|dk) keymap=dk ;;
548                         12|dvorak) keymap=dvorak ;;
549                         13|es) keymap=es ;;
550                         14|et) keymap=et ;;
551                         15|fi) keymap=fi ;;
552                         16|fr) keymap=fr ;;
553                         17|gr) keymap=gr ;;
554                         18|hu) keymap=hu ;;
555                         19|il) keymap=il ;;
556                         20|is) keymap=is ;;
557                         21|it) keymap=it ;;
558                         22|jp) keymap=jp ;;
559                         23|la) keymap=la ;;
560                         24|lt) keymap=lt ;;
561                         25|mk) keymap=mk ;;
562                         26|nl) keymap=nl ;;
563                         27|no) keymap=no ;;
564                         28|pl) keymap=pl ;;
565                         29|pt) keymap=pt ;;
566                         30|ro) keymap=ro ;;
567                         31|ru) keymap=ru ;;
568                         32|se) keymap=se ;;
569                         33|sg) keymap=sg ;;
570                         34|sk-y) keymap=sk-y ;;
571                         35|sk-z) keymap=sk-z ;;
572                         36|slovene) keymap=slovene ;;
573                         37|trf) keymap=trf ;;
574                         38|trq) keymap=trq ;;
575                         39|ua) keymap=ua ;;
576                         40|uk) keymap=uk ;;
577                         41|us) keymap=us ;;
578                         42|wangbe) keymap=wangbe ;;
579                 esac
580         fi
581         if [ -e /lib/keymaps/${keymap}.map ]
582         then
583                 good_msg "Loading the ''${keymap}'' keymap"
584                 loadkmap < /lib/keymaps/${keymap}.map
585 #               xkeymap=${keymap}
586 #               echo ${keymap} | egrep -e "[0-9]+" >/dev/null 2>&1
587 #               if [ $? -eq 0 ]
588 #               then
589 #                       xkeymap=`tail -n 7 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
590 #               fi
591                 mkdir -p /etc/sysconfig
592 #               echo "XKEYBOARD=${xkeymap}" > /etc/sysconfig/keyboard
593                 echo "XKEYBOARD=${keymap}" > /etc/sysconfig/keyboard
594                 splash set_msg "Set keymap to ${keymap}"
595         elif [ -z "${keymap}" ]
596         then
597                 echo
598                 good_msg "Keeping default keymap"
599                 splash set_msg "Keeping default keymap"
600         else
601                 bad_msg "Sorry, but keymap ''${keymap}'' is invalid!"
602                 unset keymap
603                 chooseKeymap
604         fi
605 }
606
607 startVolumes() {
608         #good_msg 'Checking if volumes need to be started...'
609
610         # Here, we check for /dev/device-mapper, and if it exists, we setup a
611         # a symlink, which should hopefully fix bug #142775 and bug #147015
612         if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ]
613         then
614                 mkdir -p /dev/mapper
615                 ln -sf /dev/device-mapper /dev/mapper/control
616         fi
617         
618         if [ "${USE_MDADM}" = '1' ]
619         then
620                 /sbin/mdadm --assemble --scan
621         fi
622
623         if [ "${USE_DMRAID_NORMAL}" = '1' ]
624         then
625                 if [ -e '/sbin/dmraid' ]
626                 then
627                         good_msg "Activating Device-Mapper RAID(s)"
628                         if [ '${DMRAID_OPTS}' = '' ]
629                         then
630                                 /sbin/dmraid -ay
631                         else
632                                 /sbin/dmraid -ay ${DMRAID_OPTS}
633                         fi
634                 fi
635         fi
636
637         if [ "${USE_LVM_NORMAL}" = '1' ]
638         then
639                 if [ -e '/bin/lvm' ]
640                 then
641                         for dev in ${RAID_DEVICES}
642                         do
643                                 setup_md_device "${dev}"
644                         done
645
646                         # This is needed for /bin/lvm to accept the following logic
647                         lvm_commands="#! /bin/lvm"
648
649                         # If there is a cahe, update it. Unbreak at least dmcrypt
650                         [ -d /etc/lvm/cache ] && lvm_commands="${lvm_commands} \nvgscan"
651
652                         # To activate volumegroups on all devices in the cache
653                         lvm_commands="${lvm_commands} \nvgchange -ay --sysinit"
654                         
655                         # To create symlinks so users can use real_root=/dev/vg/root
656                         # This needs to run after vgchange, using vgchange --mknodes is too
657                         # early.
658                         lvm_commands="${lvm_commands} \nvgmknodes --ignorelockingfailure"
659
660                         # And finally execute it all (/proc/... needed if lvm is compiled without readline)
661                         good_msg "Scanning for and activating Volume Groups"
662                         printf "%b\n" "${lvm_commands}" | /bin/lvm /proc/self/fd/0
663                 else
664                         bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!"
665                 fi
666         fi
667         
668         if [ "${USE_ZFS}" = '1' ]
669         then
670                 /sbin/zpool import -N -a ${ZPOOL_FORCE}
671         fi
672 }
673
674 startiscsi() {
675         
676         if [ ! -n "${ISCSI_NOIBFT}" ]
677         then
678                 good_msg "Activating iSCSI via iBFT"
679                 iscsistart -b
680         fi
681
682         if [ -n "${ISCSI_INITIATORNAME}" ] && [ -n "${ISCSI_TARGET}" ] && [ -n "${ISCSI_ADDRESS}" ]
683         then
684                 good_msg "Activating iSCSI via cmdline"
685
686                 if [ "${ISCSI_TGPT}" ]
687                 then
688                         ADDITIONAL="${ADDITIONAL} -g ${ISCSI_TGPT}"
689                 else
690                         ADDITIONAL="${ADDITIONAL} -g 1"
691                 fi
692                 
693                 if [ "${ISCSI_PORT}" ]
694                 then
695                         ADDITIONAL="${ADDITIONAL} -p ${ISCSI_PORT}"
696                 fi
697
698                 if [ "${ISCSI_USERNAME}" ]
699                 then
700                         ADDITIONAL="${ADDITIONAL} -u ${ISCSI_USERNAME}"
701                 fi
702
703                 if [ "${ISCSI_PASSWORD}" ]
704                 then
705                         ADDITIONAL="${ADDITIONAL} -w ${ISCSI_PASSWORD}"
706                 fi
707
708                 if [ "${ISCSI_USERNAME_IN}" ]
709                 then
710                         ADDITIONAL="${ADDITIONAL} -U ${ISCSI_USERNAME_IN}"
711                 fi
712
713                 if [ "${ISCSI_PASSWORD_IN}" ]
714                 then
715                         ADDITIONAL="${ADDITIONAL} -W ${ISCSI_PASSWORD_IN}"
716                 fi
717
718                 if [ "${ISCSI_DEBUG}" ]
719                 then
720                         ADDITIONAL="${ADDITIONAL} -d ${ISCSI_DEBUG}"
721                 fi
722
723                 iscsistart -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -a "${ISCSI_ADDRESS}" ${ADDITIONAL}
724
725                 # let iscsid settle - otherwise mounting the iSCSI-disk will fail (very rarely, though)
726                 sleep 1
727         fi
728 }
729
730
731 # Open a LUKS device
732 # It is either the root or a swap, other devices are supported in the scripts provided with sys-fs/cryptsetup-luks
733 # $1 - root/swap
734 openLUKS() {
735         # please use 'tr' and this line, or remove it
736         # eval local TYPE=`uppercase $1`
737
738         case $1 in
739                 root)
740                         local TYPE=ROOT
741                         ;;
742                 swap)
743                         local TYPE=SWAP
744                         ;;
745         esac
746
747         eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' LUKS_TRIM='"${CRYPT_'${TYPE}'_TRIM}"'
748         local DEV_ERROR=0 KEY_ERROR=0 KEYDEV_ERROR=0
749         local mntkey="/mnt/key/" cryptsetup_options=''
750
751         [ ! -e /sbin/cryptsetup ] && bad_msg "The ramdisk does not support LUKS" && exit 1
752         while [ 1 ]
753         do
754                 local gpg_cmd=""
755                 # if crypt_silent=1 and some error occurs, enter shell quietly
756                 if [ \( ${CRYPT_SILENT} -eq 1 \) -a \( \( \( ${DEV_ERROR} -eq 1 \) -o \( ${KEY_ERROR} -eq 1 \) \) -o \( ${KEYDEV_ERROR} -eq 1 \) \) ]
757                 then
758                         run_shell
759                 elif [ ${DEV_ERROR} -eq 1 ]
760                 then
761                         prompt_user "LUKS_DEVICE" "${LUKS_NAME}"
762                         DEV_ERROR=0
763                 elif [ ${KEY_ERROR} -eq 1 ]
764                 then
765                         prompt_user "LUKS_KEY" "${LUKS_NAME} key"
766                         KEY_ERROR=0
767                 elif [ ${KEYDEV_ERROR} -eq 1 ]
768                 then
769                         prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device"
770                         KEYDEV_ERROR=0
771                 else
772                         case "${LUKS_DEVICE}" in
773                                 UUID\=*|LABEL\=*)
774                                         local REAL_LUKS=""
775                                         local retval=1
776
777                                         if [ "${retval}" -ne 0 ]; then
778                                                 REAL_LUKS=`findfs "${LUKS_DEVICE}" 2>/dev/null`
779                                                 retval=$?
780                                         fi
781
782                                         if [ "$retval" -ne 0 ]; then
783                                                 REAL_LUKS=`busybox findfs "${LUKS_DEVICE}" 2>/dev/null`
784                                                 retval=$?
785                                         fi
786
787                                         if [ "${retval}" -ne 0 ]; then
788                                                 REAL_LUKS=`blkid -l -t "${LUKS_DEVICE}" | cut -d ":" -f 1 2>/dev/null`
789                                                 retval=$?
790                                         fi
791
792                                         if [ "${retval}" -eq 0 ] && [ -n "${REAL_LUKS}" ]; then
793                                                 good_msg "Detected device ${REAL_LUKS}"
794                                                 LUKS_DEVICE="${REAL_LUKS}"
795                                         fi
796                                 ;;
797                         esac
798
799                         setup_md_device ${LUKS_DEVICE}
800                         cryptsetup isLuks ${LUKS_DEVICE}
801                         if [ $? -ne 0 ]
802                         then
803                                 bad_msg "The LUKS device ${LUKS_DEVICE} does not contain a LUKS header" ${CRYPT_SILENT}
804                                 DEV_ERROR=1
805                                 continue
806                         else
807                                 # Handle keys
808                                 if [ "x${LUKS_TRIM}" = "xyes" ]
809                                 then
810                                         good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT}
811                                         cryptsetup_options="${cryptsetup_options} --allow-discards"
812                                 fi
813
814                                 if [ -n "${LUKS_KEY}" ] 
815                                 then
816                                         if [ ! -e "${mntkey}${LUKS_KEY}" ] 
817                                         then
818                                                 if [ -b "${LUKS_KEYDEV}" ]
819                                                 then good_msg "Using key device ${LUKS_KEYDEV}." ${CRYPT_SILENT}
820                                                 else
821                                                         good_msg "Please insert removable device ${LUKS_KEYDEV} for ${LUKS_NAME}" ${CRYPT_SILENT}
822                                                         # abort after 10 secs
823                                                         local count=10
824                                                         while [ ${count} -gt 0 ]
825                                                         do 
826                                                                 count=$((count-1))
827                                                                 sleep 1
828                                                                 if [ -b "${LUKS_KEYDEV}" ]
829                                                                 then
830                                                                         good_msg "Removable device ${LUKS_KEYDEV} detected." ${CRYPT_SILENT}
831                                                                         break
832                                                                 fi
833                                                         done
834                                                         if [ ! -b "${LUKS_KEYDEV}" ]
835                                                         then
836                                                                 eval CRYPT_${TYPE}_KEY=${LUKS_KEY}
837                                                                 bootstrapKey ${TYPE}
838                                                                 eval LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"'
839                                                                 if [ ! -b "${LUKS_KEYDEV}" ]; then
840                                                                         KEYDEV_ERROR=1
841                                                                         bad_msg "Removable device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
842                                                                         continue
843                                                                 fi
844                                                                 # continue otherwise will mount keydev which is mounted by bootstrap
845                                                                 continue
846                                                         fi
847                                                 fi
848                                                 # At this point a device was recognized, now let's see if the key is there
849                                                 [ ! -d "$mntkey" ] && mkdir -p ${mntkey} 2>/dev/null >/dev/null
850
851                                                 mount -n -o ro ${LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null
852                                                 if [ "$?" != '0' ]
853                                                 then
854                                                         KEYDEV_ERROR=1
855                                                         bad_msg "Mounting of device ${LUKS_KEYDEV} failed." ${CRYPT_SILENT}
856                                                         continue
857                                                 else
858                                                         good_msg "Removable device ${LUKS_KEYDEV} mounted." ${CRYPT_SILENT}
859                                                         sleep 2
860                                                         # keyfile exists?
861                                                         if [ ! -e "${mntkey}${LUKS_KEY}" ]; then
862                                                                 umount -n ${mntkey} 2>/dev/null >/dev/null
863                                                                 KEY_ERROR=1
864                                                                 KEYDEV_ERROR=1
865                                                                 bad_msg "Key {LUKS_KEY} on device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
866                                                                 continue
867                                                         fi
868                                                 fi
869                                         fi
870                                         # At this point a candidate key exists (either mounted before or not)
871                                         good_msg "${LUKS_KEY} on device ${LUKS_KEYDEV} found" ${CRYPT_SILENT}
872                                         if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /sbin/gpg ] ; then
873                                                 [ -e /dev/tty ] && mv /dev/tty /dev/tty.org
874                                                 mknod /dev/tty c 5 1
875                                                 cryptsetup_options="-d -"
876                                                 gpg_cmd="/sbin/gpg --logger-file /dev/null --quiet --decrypt ${mntkey}${LUKS_KEY} |"
877                                         else
878                                                 cryptsetup_options="-d ${mntkey}${LUKS_KEY}"
879                                         fi
880                                 fi
881                                 # At this point, keyfile or not, we're ready!
882                                 crypt_filter "${gpg_cmd}cryptsetup ${cryptsetup_options} luksOpen ${LUKS_DEVICE} ${LUKS_NAME}"
883                                 if [ $? -eq 0 ]
884                                 then
885                                         good_msg "LUKS device ${LUKS_DEVICE} opened" ${CRYPT_SILENT}
886                                         break
887                                 else
888                                         bad_msg "Failed to open LUKS device ${LUKS_DEVICE}" ${CRYPT_SILENT}
889                                         DEV_ERROR=1
890                                         KEY_ERROR=1
891                                         KEYDEV_ERROR=1
892                                 fi
893                         fi
894                 fi
895         done
896         umount ${mntkey} 2>/dev/null >/dev/null
897         rmdir -p ${mntkey} 2>/dev/null >/dev/null
898 }
899
900 startLUKS() {
901
902         # if key is set but key device isn't, find it
903         
904         [ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \
905                 && sleep 6 && bootstrapKey "ROOT"
906
907         if [ -n "${CRYPT_ROOT}" ]; then
908                 openLUKS "root"
909                 if [ -n "${REAL_ROOT}" ]
910                 then
911                         # Rescan volumes
912                         startVolumes
913                 else
914                         REAL_ROOT="/dev/mapper/root"
915                 fi
916         fi
917
918         # same for swap, but no need to sleep if root was unencrypted
919         [ -n "${CRYPT_SWAP_KEY}" ] && [ -z "${CRYPT_SWAP_KEYDEV}" ] \
920                 && { [ -z "${CRYPT_ROOT}" ] && sleep 6; bootstrapKey "SWAP"; }
921
922         if [ -n "${CRYPT_SWAP}" ]; then
923                 openLUKS "swap"
924                 if [ -z "${REAL_RESUME}" ]
925                 then
926                         # Resume from swap as default
927                         REAL_RESUME="/dev/mapper/swap"
928                 fi
929         fi
930 }
931
932 sdelay() {
933         # Sleep a specific number of seconds if SDELAY is set
934         if [ "${SDELAY}" ]
935         then
936                 good_msg "Waiting ${SDELAY} seconds..."
937                 sleep ${SDELAY}
938         elif [ "${CDROOT}" = '1' ]
939         then
940                 # many CD/DVD drives require extra sleep, especially when
941                 # connected via USB. Many people reported that 1 second sleep
942                 # is not enough on their notebooks, that's why sleep 3, when booting
943                 # off a livecd is a better default.
944                 sleep 3
945         else
946                 good_msg 'Hint: Use parameter scandelay[=seconds] if you need waiting here'
947         fi
948 }
949
950 quiet_kmsg() {
951         # if QUIET is set make the kernel less chatty
952         [ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk
953 }
954
955 verbose_kmsg() {
956         # if QUIET is set make the kernel less chatty
957         [ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk
958 }
959
960
961 cdupdate() {
962         if [ "${CDROOT}" = '1' ]
963         then
964                 if [ -x /${CDROOT_PATH}/cdupdate.sh ]
965                 then
966                         good_msg "Running cdupdate.sh"
967                         ${CDROOT_PATH}/cdupdate.sh
968                         if [ "$?" != '0' ]
969                         then
970                                 bad_msg "Executing cdupdate.sh failed!"
971                                 run_shell
972                         fi
973                 else
974                         good_msg 'No cdupdate.sh script found, skipping...'
975                 fi
976         fi
977 }
978
979 setup_btrfsctl() {
980         # start BTRFS volume detection, if available
981         [ -x /sbin/btrfsctl ] && /sbin/btrfsctl -a
982 }
983
984 setup_md_device() {
985         local device
986
987         [ -z "$1" ] && device="${REAL_ROOT}" || device="$1"
988         [ -z "${device}" ] && return # LiveCD
989
990         if [ `echo ${device}|sed -e 's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#'` = "/dev/md" ]
991         then
992                 good_msg 'Detected real_root as a md device. Setting up the device node...'
993                 MD_NUMBER=`echo ${device}|sed -e 's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#'`
994                 if [ ! -e /dev/md${MD_NUMBER} ]
995                 then
996                         mknod /dev/md${MD_NUMBER} b 9 ${MD_NUMBER} >/dev/null 2>&1
997                         [ $? -ne 0 ] && bad_msg "Creation of /dev/md${MD_NUMBER} failed..."
998                 fi
999                 mdstart ${MDPART} /dev/md${MD_NUMBER}
1000         fi
1001 }
1002
1003 rundebugshell() {
1004         if [ -n "$DEBUG" ]
1005         then
1006                 good_msg 'Starting debug shell as requested by "debug" option.'
1007                 good_msg 'Type "exit" to continue with normal bootup.'
1008                 [ -x /bin/sh ] && /bin/sh || /bin/ash
1009         fi
1010 }
1011
1012 do_resume() {
1013         if [ -d /proc/suspend2 -o -d /sys/power/suspend2 -o -d /sys/power/tuxonice ]; then
1014                 tuxonice_resume
1015         else
1016                 swsusp_resume
1017         fi
1018 }
1019
1020 swsusp_resume() {
1021         # determine swap resume partition
1022         local device=$(ls -lL "${REAL_RESUME}" | sed 's/\  */ /g' | cut -d \  -f 5-6 | sed 's/,\ */:/')
1023         [ -f /sys/power/resume ] && echo "${device}" > /sys/power/resume
1024 }
1025
1026 tuxonice_resume() {
1027         local splash_theme
1028         if grep "splash=" /proc/cmdline > /dev/null 2>&1; then
1029                 splash_theme=$(cat /proc/cmdline | sed 's/.*splash=/splash=/' | sed 's/ .*//' | sed 's/.*theme://' | sed 's/,.*//')
1030         fi
1031
1032         local tuxonice_userui_program="/sys/power/tuxonice/user_interface/program"
1033         local tuxonice_do_resume="/sys/power/tuxonice/do_resume"
1034         local tuxonice_resumedev="/sys/power/tuxonice/resume"
1035         local tuxonice_replace_swsusp="/sys/power/tuxonice/replace_swsusp"
1036
1037         #
1038         # Backward compatibility
1039         #
1040         if [ -e /sys/power/suspend2 ]; then
1041                 tuxonice_userui_program="/sys/power/suspend2/user_interface/program"
1042                 tuxonice_do_resume="/sys/power/suspend2/do_resume"
1043                 tuxonice_resumedev="/sys/power/suspend2/resume"
1044                 tuxonice_replace_swsusp="/sys/power/suspend2/replace_swsusp"
1045         elif [ -e /proc/suspend2 ]; then
1046                 tuxonice_userui_program="/proc/suspend2/userui_program"
1047                 tuxonice_do_resume="/proc/suspend2/do_resume"
1048                 tuxonice_resumedev="/proc/suspend2/resume"
1049                 tuxonice_replace_swsusp="/proc/suspend2/replace_swsusp"
1050         fi
1051
1052         # if 'use_swsusp' is given, use swsusp instead
1053         if grep "use_swsusp" /proc/cmdline > /dev/null 2>&1; then
1054                 echo 0 > ${tuxonice_replace_swsusp}
1055                 swsusp_resume
1056                 return
1057         fi
1058
1059         modules_scan tuxonice
1060
1061         # we both configure tuxonice and activate resuming,
1062         # however the kernel will resume only if an image is found
1063
1064         if ! grep suspend_noui /proc/cmdline > /dev/null 2>&1; then
1065                 which suspend2ui_text > /dev/null 2>&1 && which suspend2ui_text > "${tuxonice_userui_program}"
1066                 which tuxoniceui_text > /dev/null 2>&1 && which tuxoniceui_text > "${tuxonice_userui_program}"
1067
1068                 if [ -n "${splash_theme}" ]; then
1069                         ln -s /etc/splash/${splash_theme} /etc/splash/suspend2
1070                         ln -s /etc/splash/${splash_theme} /etc/splash/tuxonice
1071
1072                         which suspend2ui_fbsplash > /dev/null 2>&1 && which suspend2ui_fbsplash > "${tuxonice_userui_program}"
1073                         which tuxoniceui_fbsplash > /dev/null 2>&1 && which tuxoniceui_fbsplash > "${tuxonice_userui_program}"
1074                 fi
1075
1076         fi
1077         echo "${REAL_RESUME}" > "${tuxonice_resumedev}"
1078         echo > "${tuxonice_do_resume}"
1079 }
1080
1081 find_loop() {
1082         for loop in ${LOOPS}
1083         do
1084                 if [ -e "${CDROOT_PATH}""${loop}" ]
1085                 then
1086                         LOOP="${loop}"
1087                 fi
1088         done
1089 }
1090
1091 find_looptype() {
1092         LOOPTYPE="${LOOP##*.}"
1093         [ "${LOOPTYPE}" == "loop" ] && LOOPTYPE="normal"
1094         [ "${LOOP}" == "/zisofs" ] && LOOPTYPE="${LOOP#/}"
1095         [ -z "${LOOPTYPE}" ] && LOOPTYPE="noloop"
1096 }
1097
1098 getdvhoff() {
1099         echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512))
1100 }
1101
1102 setup_squashfs_aufs() {
1103         (
1104         # Setup aufs directories and vars
1105         local overlay=/mnt/overlay
1106         local static=/mnt/livecd
1107
1108         for i in "${overlay}" "${static}"; do
1109                 [ ! -d "${i}" ] && mkdir -p "${i}"
1110         done
1111         good_msg "Loading aufs"
1112         modprobe aufs > /dev/null 2>&1
1113
1114         mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}"
1115         mount -t tmpfs none "${overlay}"
1116         mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}"
1117
1118         [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}"
1119         [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}"
1120         echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab
1121         for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done
1122
1123         # have handy /mnt/cdrom (CDROOT_PATH) as well
1124         local new_cdroot="${NEW_ROOT}${CDROOT_PATH}"
1125         [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}"
1126         mount --bind "${CDROOT_PATH}" "${new_cdroot}"
1127         )
1128 }
1129
1130 setup_unionfs() {
1131         local rw_dir=$1
1132         local ro_dir=$2
1133         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
1134         then
1135                 # Directory used for rw changes in union mount filesystem
1136                 UNION=/union
1137 #               MEMORY=/memory
1138 #               if [ -z "$UID" ]
1139 #               then
1140 #                       CHANGES=$MEMORY/unionfs_changes/default
1141 #               else
1142 #                       CHANGES=$MEMORY/unionfs_changes/$UID
1143 #               fi
1144
1145 #               mkdir -p ${MEMORY}
1146                 mkdir -p ${UNION}
1147                 good_msg "Loading fuse module"
1148                 modprobe fuse > /dev/null 2>&1
1149 #                 if [ -n "${UNIONFS}" ]         
1150 #                 then   
1151 #                         CHANGESDEV=${UNIONFS}          
1152 #                         good_msg "mounting $CHANGESDEV to $MEMORY for unionfs support"         
1153 #                         mount -t auto $CHANGESDEV $MEMORY      
1154 #                         # mount tmpfs only in the case when changes= boot parameter was        
1155 #                         # empty or we were not able to mount the storage device        
1156 #                         ret=$?         
1157 #                         if [ ${ret} -ne 0 ]
1158 #                         then   
1159 #                                 bad_msg "mount of $CHANGESDEV failed falling back to ramdisk based unionfs"    
1160 #                                 mount -t tmpfs tmpfs $MEMORY   
1161 #                         fi     
1162 #                         if [ "${CDROOT}" -eq '1' -a ! -f ${MEMORY}/livecd.unionfs  ]   
1163 #                         then   
1164 #                                 umount $MEMORY         
1165 #                                 bad_msg "failed to find livecd.unionfs file on $CHANGESDEV"    
1166 #                                 bad_msg "create a livecd.unionfs file on this device if you wish to use it for unionfs"        
1167 #                                 bad_msg "falling back to ramdisk based unionfs for safety"     
1168 #                                 mount -t tmpfs tmpfs $MEMORY   
1169 #                         fi     
1170 #                 else   
1171 #                         good_msg "Mounting ramdisk to $MEMORY for unionfs support..."          
1172 #                         mount -t tmpfs tmpfs $MEMORY   
1173 #                 fi     
1174          
1175                 mkdir /tmp
1176                 mkdir -p ${UNION}
1177 #               mkdir -p $CHANGES
1178 #               mount -t unionfs -o dirs=$CHANGES=rw unionfs ${UNION}
1179                 good_msg "Creating union mount"
1180                 unionfs -o allow_other,cow,noinitgroups,suid,dev,default_permissions,use_ino ${rw_dir}=RW:${ro_dir}=RO ${UNION} 2>/dev/null
1181                 ret=$?
1182                 if [ ${ret} -ne 0 ]
1183                 then
1184                         bad_msg "Can't setup union mount!"
1185                         USE_UNIONFS_NORMAL=0
1186                 fi
1187                 [ ! -d "${NEW_ROOT}${CDROOT_PATH}" ] && mkdir -p "${NEW_ROOT}${CDROOT_PATH}"
1188                 mount --bind "${CDROOT_PATH}" "${NEW_ROOT}${CDROOT_PATH}"
1189         else
1190                 USE_UNIONFS_NORMAL=0
1191         fi
1192 }
1193
1194 get_mounts_list()
1195 {
1196         awk '
1197                 /^[[:blank:]]*#/ { next }
1198                 { print $1 }
1199                 ' ${NEW_ROOT}/etc/initramfs.mounts
1200 }
1201
1202 get_mount_options()
1203 {
1204         awk -v fs="$1" '
1205                 /^[[:blank:]]*#/ { next }
1206                 $2 == fs { print $3 }
1207                 ' ${NEW_ROOT}/etc/fstab
1208 }
1209
1210 get_mount_device()
1211 {
1212         awk -v fs="$1" '
1213                 /^[[:blank:]]*#/ { next }
1214                 $2 == fs { print $1 }
1215                 ' ${NEW_ROOT}/etc/fstab
1216 }
1217