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