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