d9b9c24cf0bd43c82b80d76a120a12910b6c7f36
[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 # let iscsid settle - otherwise mounting the iSCSI-disk will fail (very rarely, though)
296 sleep 1
297
298 # Setup md device nodes if they dont exist
299 setup_md_device
300
301 # Scan volumes
302 startVolumes
303
304 setup_keymap
305
306 # Initialize LUKS root device except for livecd's
307 if [ "${CDROOT}" != 1 ]
308 then
309         startLUKS
310         if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
311         then
312                 case "${REAL_RESUME}" in
313                         LABEL\=*|UUID\=*)
314
315                                 RESUME_DEV=""
316                                 retval=1
317                                 
318                                 if [ "${retval}" -ne '0' ]; then
319                                         RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
320                                         retval=$?
321                                 fi
322                                 
323                                 if [ "$retval" -ne '0' ]; then
324                                         RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
325                                         retval=$?
326                                 fi
327                                 
328                                 if [ "${retval}" -ne '0' ]; then
329                                         RESUME_DEV=`blkid -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
330                                         retval=$?
331                                 fi
332                                 
333                                 if [ "${retval}" -eq '0' ] && [ -n "${RESUME_DEV}" ]; then
334                                         good_msg "Detected real_resume=${RESUME_DEV}"
335                                         REAL_RESUME="${RESUME_DEV}"
336                                 fi
337                                 ;;
338                 esac
339
340                 do_resume
341         fi
342 fi
343
344 mkdir -p "${NEW_ROOT}"
345 CHROOT="${NEW_ROOT}"
346
347 # Run debug shell if requested
348 rundebugshell
349
350 if [ "${CDROOT}" = '1' ]
351 then
352         good_msg "Making tmpfs for ${NEW_ROOT}"
353         mount -n -t tmpfs tmpfs "${NEW_ROOT}"
354         
355         for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
356         do
357                 mkdir -p "${NEW_ROOT}/${i}"
358                 chmod 755 "${NEW_ROOT}/${i}"
359         done
360         [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
361         [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
362
363         # For SGI LiveCDs ...
364         if [ "${LOOPTYPE}" = "sgimips" ]
365         then
366                 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
367                 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
368         fi
369
370         # Required for splash to work.  Not an issue with the initrd as this
371         # device isn't created there and is not needed.
372         if [ -e /dev/tty1 ]
373         then
374                 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
375         fi
376
377         if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
378         then
379                 bootstrapCD
380         fi
381
382         if [ "${REAL_ROOT}" = '' ]
383         then
384                 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
385                 
386                 COUNTER=0
387                 while [ ${COUNTER} -lt 3 ]; do
388                         sleep 3
389                         echo -n '.'
390                         let COUNTER=${COUNTER}+1
391                 done
392
393                 sleep 1
394                 echo -e "${NORMAL}"
395                 bootstrapCD
396         fi
397
398         if [ "${REAL_ROOT}" = '' ]
399         then
400                 # Undo stuff
401                 umount  "${NEW_ROOT}/dev" 2>/dev/null
402                 umount  "${NEW_ROOT}/sys" 2>/dev/null
403                 umount /sys 2>/dev/null
404
405                 umount  "${NEW_ROOT}"
406                 rm -rf  "${NEW_ROOT}/*"
407
408                 bad_msg 'Could not find CD to boot, something else needed!'
409                 CDROOT=0
410         fi
411 fi
412
413 # Determine root device
414 good_msg 'Determining root device...'
415 while true
416 do
417         while [ "${got_good_root}" != '1' ]
418         do
419                 case "${REAL_ROOT}" in
420                         LABEL\=*|UUID\=*)
421                         
422                                 ROOT_DEV=""
423                                 retval=1
424                                 
425                                 if [ "${retval}" -ne '0' ]; then
426                                         ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
427                                         retval=$?
428                                 fi
429                                 
430                                 if [ "$retval" -ne '0' ]; then
431                                         ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
432                                         retval=$?
433                                 fi
434                                 
435                                 if [ "${retval}" -ne '0' ]; then
436                                         ROOT_DEV=`blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
437                                         retval=$?
438                                 fi
439                                 
440                                 if [ "${retval}" -eq '0' ] && [ -n "${ROOT_DEV}" ]; then
441                                         good_msg "Detected real_root=${ROOT_DEV}"
442                                         REAL_ROOT="${ROOT_DEV}"
443                                 else
444                                         whereis "REAL_ROOT" "root block device"
445                                         got_good_root=0
446                                         continue
447                                 fi
448                                 ;;
449                 esac
450                                 
451                 if [ "${REAL_ROOT}" = '' ]
452                 then
453                         # No REAL_ROOT determined/specified. Prompt user for root block device.
454                         whereis "REAL_ROOT" "root block device"
455                         got_good_root=0
456
457                 # Check for a block device or /dev/nfs
458                 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
459                 then
460                         got_good_root=1
461
462                 else
463                         bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
464                         REAL_ROOT=""
465                         got_good_root=0
466                 fi
467         done
468
469
470         if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
471         then
472                 # CD already mounted; no further checks necessary
473                 break
474         elif [ "${LOOPTYPE}" = "sgimips" ]
475         then
476                 # sgimips mounts the livecd root partition directly
477                 # there is no isofs filesystem to worry about
478                 break
479         else
480                 good_msg "Mounting root..."
481
482                 # Try to mount the device as ${NEW_ROOT}
483                 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
484                         findnfsmount
485                 else
486                         # mount ro so fsck doesn't barf later
487                         if [ "${REAL_ROOTFLAGS}" = '' ]; then
488                                 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
489                         else
490                                 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
491                                 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
492                         fi
493                 fi
494                 
495                 # If mount is successful break out of the loop 
496                 # else not a good root and start over.
497                 if [ "$?" = '0' ]
498                 then
499                         if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
500                         then
501                                 break
502                         else
503                                 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
504                                 got_good_root=0
505                                 REAL_ROOT=''
506                         fi
507                 else
508                         bad_msg "Could not mount specified ROOT, try again"
509                         got_good_root=0
510                         REAL_ROOT=''
511                 fi
512         fi
513 done
514 # End determine root device
515
516 #verbose_kmsg
517
518 # If CD root is set determine the looptype to boot
519 if [ "${CDROOT}" = '1' ]
520 then
521         good_msg 'Determining looptype ...'
522         cd "${NEW_ROOT}"
523
524         # Find loop and looptype
525         [ -z "${LOOP}" ] && find_loop
526         [ -z "${LOOPTYPE}" ] && find_looptype
527
528         cache_cd_contents
529
530         # If encrypted, find key and mount, otherwise mount as usual
531         if [ -n "${CRYPT_ROOT}" ]
532         then
533                 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
534                 CRYPT_ROOT='/dev/loop0'
535                 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
536
537                 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
538                 test_success 'Preparing loop filesystem'
539
540                 startLUKS
541
542                 case ${LOOPTYPE} in
543                         normal)
544                                 MOUNTTYPE="ext2"
545                                 ;;
546                         *)
547                                 MOUNTTYPE="${LOOPTYPE}"
548                                 ;;
549                 esac
550                 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
551                 test_success 'Mount filesystem'
552                 FS_LOCATION='mnt/livecd'
553         # Setup the loopback mounts, if unencrypted
554         else
555                 if [ "${LOOPTYPE}" = 'normal' ]
556                 then
557                         good_msg 'Mounting loop filesystem'
558                         mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
559                         test_success 'Mount filesystem'
560                         FS_LOCATION='mnt/livecd'
561                 elif [ "${LOOPTYPE}" = 'squashfs' ]
562                 then
563                         good_msg 'Mounting squashfs filesystem'
564                         mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
565                         test_success 'Mount filesystem'
566                         FS_LOCATION='mnt/livecd'
567                 elif [ "${LOOPTYPE}" = 'gcloop' ]
568                 then
569                         good_msg 'Mounting gcloop filesystem'
570                         echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
571                         test_success 'losetup the loop device'
572
573                         mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
574                         test_success 'Mount the losetup loop device'
575                         FS_LOCATION='mnt/livecd'
576                 elif [ "${LOOPTYPE}" = 'zisofs' ]
577                 then
578                         FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
579                 elif [ "${LOOPTYPE}" = 'noloop' ]
580                 then
581                         FS_LOCATION='mnt/cdrom'
582                 elif [ "${LOOPTYPE}" = 'sgimips' ]
583                 then
584                         # getdvhoff finds the starting offset (in bytes) of the squashfs
585                         # partition on the cdrom and returns this offset for losetup
586                         #
587                         # All currently supported SGI Systems use SCSI CD-ROMs, so
588                         # so we know that the CD-ROM is usually going to be /dev/sr0.
589                         #
590                         # We use the value given to losetup to set /dev/loop0 to point
591                         # to the liveCD root partition, and then mount /dev/loop0 as
592                         # the LiveCD rootfs
593                         good_msg 'Locating the SGI LiveCD Root Partition'
594                         echo ' ' | \
595                                 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
596                                         "${NEW_ROOT}${CDROOT_DEV}" \
597                                         "${NEW_ROOT}${REAL_ROOT}"
598                         test_success 'losetup /dev/sr0 /dev/loop0'
599         
600                         good_msg 'Mounting the Root Partition'
601                         mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
602                         test_success 'mount /dev/loop0 /'
603                         FS_LOCATION='mnt/livecd'
604                 fi
605         fi
606
607
608
609         # Unpacking additional packages from NFS mount
610         # This is useful for adding kernel modules to /lib
611         # We do this now, so that additional packages can add whereever they want.
612         if [ "${REAL_ROOT}" = '/dev/nfs' ]
613         then
614                 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
615                 then
616                                 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
617                                 do      
618                                         tarname=`basename ${targz}`
619                                         good_msg "Adding additional package ${tarname}"
620                                         (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
621                                 done
622                 fi
623         fi
624
625
626         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
627         then
628                 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
629                 CHROOT=/union
630         else
631         
632         good_msg "Copying read-write image contents to tmpfs"
633         # Copy over stuff that should be writable
634         (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
635
636         # Now we do the links.
637         for x in ${ROOT_LINKS}
638         do
639                 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
640                 then
641                         ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
642                 else
643                         # List all subdirectories of x
644                         find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
645                         do
646                                 # Strip the prefix of the FS_LOCATION
647                                 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
648
649                                 # Skip this directory if we already linked a parent directory
650                                 if [ "${curent_parrent}" != '' ]; then
651                                         var=`echo "${directory}" | grep "^${curent_parrent}"`
652                                         if [ "${var}" != '' ]; then
653                                                 continue
654                                         fi
655                                 fi
656                                 # Test if the directory exists already
657                                 if [ -e "/${NEW_ROOT}/${directory}" ]
658                                 then
659                                         # It does exist, link all the individual files
660                                         for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
661                                         do
662                                         if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
663                                                         ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
664                                                 fi
665                                         done
666                                 else
667                                         # It does not exist, make a link to the livecd
668                                         ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
669                                         current_parent="${directory}"
670                                 fi
671                         done
672                 fi
673         done
674
675         if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
676         then
677                 sleep 10
678         fi
679         mkdir initramfs proc tmp sys 2>/dev/null
680         chmod 1777 tmp
681
682         fi
683
684         #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
685         #if [ "${UML}" = 'UML' ]
686         #then
687         #       # UML Fixes
688         #       good_msg 'Updating for uml system'
689         #fi
690
691         # Let Init scripts know that we booted from CD
692         export CDBOOT
693         CDBOOT=1
694         check_slowusb
695         if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
696         then
697                 sleep 10
698         fi
699 else
700         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
701         then
702                 mkdir /union_changes
703                 mount -t tmpfs tmpfs /union_changes
704                 setup_unionfs /union_changes ${NEW_ROOT}
705                 mkdir -p ${UNION}/tmp/.initrd
706         fi
707 fi
708
709 # Execute script on the cdrom just before boot to update things if necessary
710 cdupdate
711
712 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
713 then
714         good_msg "Entering ${SUBDIR} to boot"
715         CHROOT="${CHROOT}/${SUBDIR}"
716 fi
717
718 verbose_kmsg
719
720 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
721 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
722 then
723         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
724 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
725 then
726         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
727 fi
728
729 cd "${CHROOT}"
730 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
731 echo -ne "${BOLD}.${NORMAL}"
732 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
733 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
734 echo -e "${BOLD}.${NORMAL}"
735
736 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
737
738 # If we get here, something bad has happened
739 splash 'verbose'
740
741 echo 'A fatal error has probably occured since /sbin/init did not'
742 echo 'boot correctly. Trying to open a shell...'
743 echo
744 exec /bin/bash
745 exec /bin/sh
746 exec /bin/ash
747 exec sh