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