Do no delay if scandelay[=seconds] is not specified (bug #323317 again)
[genkernel.git] / defaults / linuxrc
1 #!/bin/sh
2
3 . /etc/initrd.defaults
4 . /etc/initrd.scripts
5
6 splash() {
7         return 0
8 }
9
10 [ -e /etc/initrd.splash ] && . /etc/initrd.splash
11
12 # Clean input/output
13 exec >${CONSOLE} <${CONSOLE} 2>&1
14
15 if [ "$$" != '1' ]
16 then
17         echo '/linuxrc has to be run as the init process as the one'
18         echo 'with a PID of 1. Try adding init="/linuxrc" to the'
19         echo 'kernel command line or running "exec /linuxrc".'
20         exit 1
21 fi
22
23 mount -t proc proc /proc >/dev/null 2>&1
24 mount -o remount,rw / >/dev/null 2>&1
25
26 # Set up symlinks
27 /bin/busybox --install -s
28
29 if [ "$0" = '/init' ]
30 then
31         [ -e /linuxrc ] && rm /linuxrc
32 fi
33
34 if [ -e /bin/lvm ]
35 then
36         [ -e /bin/vgscan   ] || ln -s /bin/lvm /bin/vgscan
37         [ -e /bin/vgchange ] || ln -s /bin/lvm /bin/vgchange
38 fi
39
40 quiet_kmsg
41
42 CMDLINE=`cat /proc/cmdline`
43 # Scan CMDLINE for any specified real_root= or cdroot arguments
44 FAKE_ROOT=''
45 REAL_ROOTFLAGS=''
46 CRYPT_SILENT=0
47 for x in ${CMDLINE}
48 do
49         case "${x}" in
50                 real_root\=*)
51                         REAL_ROOT=`parse_opt "${x}"`
52                 ;;
53                 root\=*)
54                         FAKE_ROOT=`parse_opt "${x}"`
55                 ;;
56                 subdir\=*)
57                         SUBDIR=`parse_opt "${x}"`
58                 ;;
59                 real_init\=*)
60                         REAL_INIT=`parse_opt "${x}"`
61                 ;;
62                 init_opts\=*)
63                         INIT_OPTS=`parse_opt "${x}"`
64                 ;;
65                 # Livecd options
66                 cdroot)
67                         CDROOT=1
68                 ;;
69                 cdroot\=*)
70                         CDROOT=1
71                         CDROOT_DEV=`parse_opt "${x}"`
72                 ;;
73                 cdroot_type\=*)
74                         CDROOT_TYPE=`parse_opt "${x}"`
75                 ;;
76                 # Start livecd loop, looptype options
77                 loop\=*)
78                         LOOP=`parse_opt "${x}"`
79                 ;;
80                 looptype\=*)
81                         LOOPTYPE=`parse_opt "${x}"`
82                 ;;
83                 isoboot\=*)
84                         ISOBOOT=`parse_opt "${x}"`
85                 ;;
86                 # Start Volume manager options 
87                 dolvm)
88                         USE_LVM_NORMAL=1
89                 ;;
90                 dolvm2)
91                         bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
92                         USE_LVM_NORMAL=1
93                 ;;
94                 domdadm)
95                         USE_MDADM=1
96                 ;;
97                 dodmraid)
98                         USE_DMRAID_NORMAL=1
99                 ;;
100                 dodmraid\=*)
101                         DMRAID_OPTS=`parse_opt "${x}"`
102                         USE_DMRAID_NORMAL=1
103                 ;;
104                 doevms)
105                         USE_EVMS_NORMAL=1
106                 ;;
107                 doevms2)
108                         bad_msg 'Using doevms2 is deprecated, use doevms, instead.'
109                         USE_EVMS_NORMAL=1
110                 ;;
111                 # Debug Options
112                 debug)
113                         DEBUG='yes'
114                 ;;
115                 # Scan delay options 
116                 scandelay\=*)
117                         SDELAY=`parse_opt "${x}"`
118                 ;;
119                 scandelay)
120                         SDELAY=3
121                 ;;
122                 # Module no-loads
123                 doload\=*)
124                         MDOLIST=`parse_opt "${x}"`
125                         MDOLIST="`echo ${MDOLIST} | sed -e 's/,/ /g'`"
126                 ;;
127                 nodetect)
128                         NODETECT=1
129                 ;;
130                 noload\=*)
131                         MLIST=`parse_opt "${x}"`
132                         MLIST="`echo ${MLIST} | sed -e 's/,/ /g'`"
133                         export MLIST
134                 ;;
135                 # Redirect output to a specific tty
136                 CONSOLE\=*|console\=*)
137                         CONSOLE=`parse_opt "${x}"`
138 #                       exec >${CONSOLE} <${CONSOLE} 2>&1
139                 ;;
140                 # /dev/md
141                 lvmraid\=*)
142                         RAID_DEVICES="`parse_opt ${x}`"
143                         RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
144                 ;;
145                 part\=*)
146                         MDPART=`parse_opt "${x}"`
147                 ;;
148                 # NFS
149                 ip\=*)
150                         IP=`parse_opt "${x}"`
151                 ;;
152                 nfsroot\=*)
153                         NFSROOT=`parse_opt "${x}"`
154                 ;;
155                 # iSCSI
156                 iscsi_initiatorname\=*)
157                         ISCSI_INITIATORNAME=`parse_opt "${x}"`
158                 ;;
159                 iscsi_target\=*)
160                         ISCSI_TARGET=`parse_opt "${x}"`
161                 ;;
162                 iscsi_tgpt\=*)
163                         ISCSI_TGPT=`parse_opt "${x}"`
164                 ;;
165                 iscsi_address\=*)
166                         ISCSI_ADDRESS=`parse_opt "${x}"`
167                 ;;
168                 iscsi_port\=*)
169                         ISCSI_PORT=`parse_opt "${x}"`
170                 ;;
171                 iscsi_username\=*)
172                         ISCSI_USERNAME=`parse_opt "${x}"`
173                 ;;
174                 iscsi_password\=*)
175                         ISCSI_PASSWORD=`parse_opt "${x}"`
176                 ;;
177                 iscsi_username_in\=*)
178                         ISCSI_USERNAME_IN=`parse_opt "${x}"`
179                 ;;
180                 iscsi_password_in\=*)
181                         ISCSI_PASSWORD_IN=`parse_opt "${x}"`
182                 ;;
183                 iscsi_debug\=*)
184                         ISCSI_DEBUG=`parse_opt "${x}"`
185                 ;;
186                 # Crypto
187                 crypt_root\=*)
188                         CRYPT_ROOT=`parse_opt "${x}"`
189                 ;;
190                 crypt_swap\=*)
191                         CRYPT_SWAP=`parse_opt "${x}"`
192                 ;;
193                 root_key\=*)
194                         CRYPT_ROOT_KEY=`parse_opt "${x}"`
195                 ;;
196                 root_keydev\=*)
197                         CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
198                 ;;
199                 swap_key\=*)
200                         CRYPT_SWAP_KEY=`parse_opt "${x}"`
201                 ;;
202                 swap_keydev\=*)
203                         CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
204                 ;;
205                 real_resume\=*|resume\=*)
206                         REAL_RESUME=`parse_opt "${x}"`
207                 ;;
208                 noresume)
209                         NORESUME=1
210                 ;;
211                 crypt_silent)
212                         CRYPT_SILENT=1
213                 ;;
214                 real_rootflags\=*)
215                         REAL_ROOTFLAGS=`parse_opt "${x}"`
216                 ;;
217                 keymap\=*)
218                         keymap=`parse_opt "${x}"`
219                 ;;
220                 unionfs)
221                         if [ ! -x /sbin/unionfs ]
222                         then
223                                 USE_UNIONFS_NORMAL=0
224                                 bad_msg 'unionfs binary not found: aborting use of unionfs!'
225                         else
226                                 USE_UNIONFS_NORMAL=1
227                         fi
228                         ;;
229                 nounionfs)
230                         USE_UNIONFS_NORMAL=0
231                         ;;
232 #                 unionfs\=*)    
233 #                         if [ ! -x /sbin/unionfs ]      
234 #                         then   
235 #                                 USE_UNIONFS_NORMAL=0   
236 #                                 bad_msg 'unionfs binary not found: aborting use of unionfs!'
237 #                         else   
238 #                                 USE_UNIONFS_NORMAL=1   
239 #                                 CMD_UNIONFS=`parse_opt "${x}"`         
240 #                                 echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1     
241 #                                 if [ $? -eq 0 ]
242 #                                 then   
243 #                                         UID=`echo ${CMD_UNIONFS#*,}`   
244 #                                         UNIONFS=`echo ${CMD_UNIONFS%,*}`       
245 #                                 else   
246 #                                         UNIONFS=${CMD_UNIONFS}         
247 #                                 fi     
248 #                         fi     
249 #                 ;;
250         esac
251 done
252
253 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \)  -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
254 then
255         REAL_ROOT="${FAKE_ROOT}"        
256 fi
257
258 splash 'init'
259
260 cmdline_hwopts
261
262 # Mount sysfs
263 mount_sysfs
264
265 # Setup hotplugging for firmware loading
266 setup_hotplug
267
268 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
269 if [ -z "${DO_modules}" ]
270 then
271         good_msg 'Skipping module load; disabled via commandline'
272 elif [ -d "/lib/modules/${KV}" ]
273 then
274         good_msg 'Loading modules'
275         # Load appropriate kernel modules
276         if [ "${NODETECT}" != '1' ]
277         then
278                 for modules in ${MY_HWOPTS}
279                 do
280                         modules_scan ${modules}
281                 done
282         fi
283         # Always eval doload=...
284         modules_load ${MDOLIST}
285 else
286         good_msg 'Skipping module load; no modules in the ramdisk!'
287 fi
288
289 # Apply scan delay if specified
290 sdelay
291
292 # Setup slow USB bits
293 setup_slowusb
294
295 # Start device manager
296 start_dev_mgr
297
298 # if doslowusb is passed, pause other 10 seconds here, after mdev load
299 [ "${DO_slowusb}" ] && sleep 10
300
301 # Start iSCSI
302 startiscsi
303
304 # let iscsid settle - otherwise mounting the iSCSI-disk will fail (very rarely, though)
305 sleep 1
306
307 # Setup btrfs, see bug 303529
308 setup_btrfsctl
309
310 # Setup md device nodes if they dont exist
311 setup_md_device
312
313 # Scan volumes
314 startVolumes
315
316 setup_keymap
317
318 # Initialize LUKS root device except for livecd's
319 if [ "${CDROOT}" != 1 ]
320 then
321         startLUKS
322         if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
323         then
324                 case "${REAL_RESUME}" in
325                         LABEL\=*|UUID\=*)
326
327                                 RESUME_DEV=""
328                                 retval=1
329                                 
330                                 if [ ${retval} -ne 0 ]; then
331                                         RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
332                                         retval=$?
333                                 fi
334                                 
335                                 if [ ${retval} -ne 0 ]; then
336                                         RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
337                                         retval=$?
338                                 fi
339                                 
340                                 if [ ${retval} -ne 0 ]; then
341                                         RESUME_DEV=`blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
342                                         retval=$?
343                                 fi
344                                 
345                                 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
346                                         good_msg "Detected real_resume=${RESUME_DEV}"
347                                         REAL_RESUME="${RESUME_DEV}"
348                                 fi
349                                 ;;
350                 esac
351
352                 do_resume
353         fi
354 fi
355
356 mkdir -p "${NEW_ROOT}"
357 CHROOT="${NEW_ROOT}"
358
359 # Run debug shell if requested
360 rundebugshell
361
362 if [ "${CDROOT}" = '1' ]
363 then
364         good_msg "Making tmpfs for ${NEW_ROOT}"
365         mount -n -t tmpfs tmpfs "${NEW_ROOT}"
366         
367         for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
368         do
369                 mkdir -p "${NEW_ROOT}/${i}"
370                 chmod 755 "${NEW_ROOT}/${i}"
371         done
372         [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
373         [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
374
375         # For SGI LiveCDs ...
376         if [ "${LOOPTYPE}" = "sgimips" ]
377         then
378                 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
379                 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
380         fi
381
382         # Required for splash to work.  Not an issue with the initrd as this
383         # device isn't created there and is not needed.
384         if [ -e /dev/tty1 ]
385         then
386                 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
387         fi
388
389         if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
390         then
391                 bootstrapCD
392         fi
393
394         if [ "${REAL_ROOT}" = '' ]
395         then
396                 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
397                 
398                 COUNTER=0
399                 while [ ${COUNTER} -lt 3 ]; do
400                         sleep 3
401                         echo -n '.'
402                         let COUNTER=${COUNTER}+1
403                 done
404
405                 sleep 1
406                 echo -e "${NORMAL}"
407                 bootstrapCD
408         fi
409
410         if [ "${REAL_ROOT}" = '' ]
411         then
412                 # Undo stuff
413                 umount  "${NEW_ROOT}/dev" 2>/dev/null
414                 umount  "${NEW_ROOT}/sys" 2>/dev/null
415                 umount /sys 2>/dev/null
416
417                 umount  "${NEW_ROOT}"
418                 rm -rf  "${NEW_ROOT}/*"
419
420                 bad_msg 'Could not find CD to boot, something else needed!'
421                 CDROOT=0
422         fi
423 fi
424
425 # Determine root device
426 good_msg 'Determining root device...'
427 while true
428 do
429         while [ "${got_good_root}" != '1' ]
430         do
431                 case "${REAL_ROOT}" in
432                         LABEL\=*|UUID\=*)
433                         
434                                 ROOT_DEV=""
435                                 retval=1
436                                 
437                                 if [ ${retval} -ne 0 ]; then
438                                         ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
439                                         retval=$?
440                                 fi
441                                 
442                                 if [ ${retval} -ne 0 ]; then
443                                         ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
444                                         retval=$?
445                                 fi
446                                 
447                                 if [ ${retval} -ne 0 ]; then
448                                         ROOT_DEV=`blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
449                                         retval=$?
450                                 fi
451                                 
452                                 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
453                                         good_msg "Detected real_root=${ROOT_DEV}"
454                                         REAL_ROOT="${ROOT_DEV}"
455                                 else
456                                         whereis "REAL_ROOT" "root block device"
457                                         got_good_root=0
458                                         continue
459                                 fi
460                                 ;;
461                 esac
462                                 
463                 if [ "${REAL_ROOT}" = '' ]
464                 then
465                         # No REAL_ROOT determined/specified. Prompt user for root block device.
466                         whereis "REAL_ROOT" "root block device"
467                         got_good_root=0
468
469                 # Check for a block device or /dev/nfs
470                 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
471                 then
472                         got_good_root=1
473
474                 else
475                         bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
476                         REAL_ROOT=""
477                         got_good_root=0
478                 fi
479         done
480
481
482         if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
483         then
484                 # CD already mounted; no further checks necessary
485                 break
486         elif [ "${LOOPTYPE}" = "sgimips" ]
487         then
488                 # sgimips mounts the livecd root partition directly
489                 # there is no isofs filesystem to worry about
490                 break
491         else
492                 good_msg "Mounting root..."
493
494                 # Try to mount the device as ${NEW_ROOT}
495                 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
496                         findnfsmount
497                 else
498                         # mount ro so fsck doesn't barf later
499                         if [ "${REAL_ROOTFLAGS}" = '' ]; then
500                                 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
501                         else
502                                 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
503                                 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
504                         fi
505                 fi
506                 
507                 # If mount is successful break out of the loop 
508                 # else not a good root and start over.
509                 if [ "$?" = '0' ]
510                 then
511                         if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
512                         then
513                                 break
514                         else
515                                 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
516                                 got_good_root=0
517                                 REAL_ROOT=''
518                         fi
519                 else
520                         bad_msg "Could not mount specified ROOT, try again"
521                         got_good_root=0
522                         REAL_ROOT=''
523                 fi
524         fi
525 done
526 # End determine root device
527
528 #verbose_kmsg
529
530 # If CD root is set determine the looptype to boot
531 if [ "${CDROOT}" = '1' ]
532 then
533         good_msg 'Determining looptype ...'
534         cd "${NEW_ROOT}"
535
536         # Find loop and looptype
537         [ -z "${LOOP}" ] && find_loop
538         [ -z "${LOOPTYPE}" ] && find_looptype
539
540         cache_cd_contents
541
542         # If encrypted, find key and mount, otherwise mount as usual
543         if [ -n "${CRYPT_ROOT}" ]
544         then
545                 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
546                 CRYPT_ROOT='/dev/loop0'
547                 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
548
549                 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
550                 test_success 'Preparing loop filesystem'
551
552                 startLUKS
553
554                 case ${LOOPTYPE} in
555                         normal)
556                                 MOUNTTYPE="ext2"
557                                 ;;
558                         *)
559                                 MOUNTTYPE="${LOOPTYPE}"
560                                 ;;
561                 esac
562                 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
563                 test_success 'Mount filesystem'
564                 FS_LOCATION='mnt/livecd'
565         # Setup the loopback mounts, if unencrypted
566         else
567                 if [ "${LOOPTYPE}" = 'normal' ]
568                 then
569                         good_msg 'Mounting loop filesystem'
570                         mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
571                         test_success 'Mount filesystem'
572                         FS_LOCATION='mnt/livecd'
573                 elif [ "${LOOPTYPE}" = 'squashfs' ]
574                 then
575                         good_msg 'Mounting squashfs filesystem'
576                         mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
577                         test_success 'Mount filesystem'
578                         FS_LOCATION='mnt/livecd'
579                 elif [ "${LOOPTYPE}" = 'gcloop' ]
580                 then
581                         good_msg 'Mounting gcloop filesystem'
582                         echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
583                         test_success 'losetup the loop device'
584
585                         mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
586                         test_success 'Mount the losetup loop device'
587                         FS_LOCATION='mnt/livecd'
588                 elif [ "${LOOPTYPE}" = 'zisofs' ]
589                 then
590                         FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
591                 elif [ "${LOOPTYPE}" = 'noloop' ]
592                 then
593                         FS_LOCATION='mnt/cdrom'
594                 elif [ "${LOOPTYPE}" = 'sgimips' ]
595                 then
596                         # getdvhoff finds the starting offset (in bytes) of the squashfs
597                         # partition on the cdrom and returns this offset for losetup
598                         #
599                         # All currently supported SGI Systems use SCSI CD-ROMs, so
600                         # so we know that the CD-ROM is usually going to be /dev/sr0.
601                         #
602                         # We use the value given to losetup to set /dev/loop0 to point
603                         # to the liveCD root partition, and then mount /dev/loop0 as
604                         # the LiveCD rootfs
605                         good_msg 'Locating the SGI LiveCD Root Partition'
606                         echo ' ' | \
607                                 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
608                                         "${NEW_ROOT}${CDROOT_DEV}" \
609                                         "${NEW_ROOT}${REAL_ROOT}"
610                         test_success 'losetup /dev/sr0 /dev/loop0'
611         
612                         good_msg 'Mounting the Root Partition'
613                         mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
614                         test_success 'mount /dev/loop0 /'
615                         FS_LOCATION='mnt/livecd'
616                 fi
617         fi
618
619
620
621         # Unpacking additional packages from NFS mount
622         # This is useful for adding kernel modules to /lib
623         # We do this now, so that additional packages can add whereever they want.
624         if [ "${REAL_ROOT}" = '/dev/nfs' ]
625         then
626                 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
627                 then
628                                 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
629                                 do      
630                                         tarname=`basename ${targz}`
631                                         good_msg "Adding additional package ${tarname}"
632                                         (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
633                                 done
634                 fi
635         fi
636
637
638         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
639         then
640                 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
641                 CHROOT=/union
642         else
643         
644         good_msg "Copying read-write image contents to tmpfs"
645         # Copy over stuff that should be writable
646         (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
647
648         # Now we do the links.
649         for x in ${ROOT_LINKS}
650         do
651                 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
652                 then
653                         ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
654                 else
655                         # List all subdirectories of x
656                         find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
657                         do
658                                 # Strip the prefix of the FS_LOCATION
659                                 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
660
661                                 # Skip this directory if we already linked a parent directory
662                                 if [ "${current_parent}" != '' ]; then
663                                         var=`echo "${directory}" | grep "^${current_parent}"`
664                                         if [ "${var}" != '' ]; then
665                                                 continue
666                                         fi
667                                 fi
668                                 # Test if the directory exists already
669                                 if [ -e "/${NEW_ROOT}/${directory}" ]
670                                 then
671                                         # It does exist, link all the individual files
672                                         for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
673                                         do
674                                         if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
675                                                         ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
676                                                 fi
677                                         done
678                                 else
679                                         # It does not exist, make a link to the livecd
680                                         ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
681                                         current_parent="${directory}"
682                                 fi
683                         done
684                 fi
685         done
686
687         mkdir initramfs proc tmp sys 2>/dev/null
688         chmod 1777 tmp
689
690         fi
691
692         #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
693         #if [ "${UML}" = 'UML' ]
694         #then
695         #       # UML Fixes
696         #       good_msg 'Updating for uml system'
697         #fi
698
699         # Let Init scripts know that we booted from CD
700         export CDBOOT
701         CDBOOT=1
702 else
703         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
704         then
705                 mkdir /union_changes
706                 mount -t tmpfs tmpfs /union_changes
707                 setup_unionfs /union_changes ${NEW_ROOT}
708                 mkdir -p ${UNION}/tmp/.initrd
709         fi
710 fi
711
712 # Execute script on the cdrom just before boot to update things if necessary
713 cdupdate
714
715 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
716 then
717         good_msg "Entering ${SUBDIR} to boot"
718         CHROOT="${CHROOT}/${SUBDIR}"
719 fi
720
721 verbose_kmsg
722
723 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
724 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
725 then
726         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
727 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
728 then
729         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
730 fi
731
732 cd "${CHROOT}"
733 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
734 echo -ne "${BOLD}.${NORMAL}"
735 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
736 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
737 echo -e "${BOLD}.${NORMAL}"
738
739 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
740
741 # If we get here, something bad has happened
742 splash 'verbose'
743
744 echo 'A fatal error has probably occured since /sbin/init did not'
745 echo 'boot correctly. Trying to open a shell...'
746 echo
747 exec /bin/bash
748 exec /bin/sh
749 exec /bin/ash
750 exec sh