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