63366bdfbf77f0dfad9fd85f5c109ad1b4e0300b
[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         esac
232 done
233
234 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \)  -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
235 then
236         REAL_ROOT="${FAKE_ROOT}"
237 fi
238
239 splash 'init'
240
241 cmdline_hwopts
242
243 # Mount sysfs
244 mount_sysfs
245
246 # Setup hotplugging for firmware loading
247 setup_hotplug
248
249 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
250 if [ -z "${DO_modules}" ]
251 then
252         good_msg 'Skipping module load; disabled via commandline'
253 elif [ -d "/lib/modules/${KV}" ]
254 then
255         good_msg 'Loading modules'
256         # Load appropriate kernel modules
257         if [ "${NODETECT}" != '1' ]
258         then
259                 for modules in ${MY_HWOPTS}
260                 do
261                         modules_scan ${modules}
262                 done
263         fi
264         # Always eval doload=...
265         modules_load ${MDOLIST}
266 else
267         good_msg 'Skipping module load; no modules in the ramdisk!'
268 fi
269
270 # Apply scan delay if specified
271 sdelay
272
273 # Setup slow USB bits
274 setup_slowusb
275
276 # Start device manager
277 start_dev_mgr
278
279 # if doslowusb is passed, pause other 10 seconds here, after mdev load
280 [ "${DO_slowusb}" ] && sleep 10
281
282 # Start iSCSI
283 if [ -e /bin/iscsistart ]
284 then
285         startiscsi
286 fi
287
288 # Setup btrfs, see bug 303529
289 setup_btrfsctl
290
291 # Setup md device nodes if they dont exist
292 setup_md_device
293
294 # Scan volumes
295 startVolumes
296
297 setup_keymap
298
299 # Initialize LUKS root device except for livecd's
300 if [ "${CDROOT}" != 1 ]
301 then
302         startLUKS
303         if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
304         then
305                 case "${REAL_RESUME}" in
306                         LABEL=*|UUID=*)
307
308                                 RESUME_DEV=""
309                                 retval=1
310
311                                 if [ ${retval} -ne 0 ]; then
312                                         RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
313                                         retval=$?
314                                 fi
315
316                                 if [ ${retval} -ne 0 ]; then
317                                         RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
318                                         retval=$?
319                                 fi
320
321                                 if [ ${retval} -ne 0 ]; then
322                                         RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
323                                         retval=$?
324                                 fi
325
326                                 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
327                                         good_msg "Detected real_resume=${RESUME_DEV}"
328                                         REAL_RESUME="${RESUME_DEV}"
329                                 fi
330                                 ;;
331                 esac
332
333                 do_resume
334         fi
335 fi
336
337 mkdir -p "${NEW_ROOT}"
338 CHROOT="${NEW_ROOT}"
339
340 # Run debug shell if requested
341 rundebugshell
342
343 if [ "${CDROOT}" = '1' ]
344 then
345         good_msg "Making tmpfs for ${NEW_ROOT}"
346         mount -n -t tmpfs tmpfs "${NEW_ROOT}"
347
348         for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
349         do
350                 mkdir -p "${NEW_ROOT}/${i}"
351                 chmod 755 "${NEW_ROOT}/${i}"
352         done
353         [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
354         [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
355         [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
356
357         # For SGI LiveCDs ...
358         if [ "${LOOPTYPE}" = "sgimips" ]
359         then
360                 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
361                 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
362         fi
363
364         # Required for splash to work.  Not an issue with the initrd as this
365         # device isn't created there and is not needed.
366         if [ -e /dev/tty1 ]
367         then
368                 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
369         fi
370
371         if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
372         then
373                 bootstrapCD
374         fi
375
376         if [ "${REAL_ROOT}" = '' ]
377         then
378                 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
379
380                 COUNTER=0
381                 while [ ${COUNTER} -lt 3 ]; do
382                         sleep 3
383                         echo -n '.'
384                         let COUNTER=${COUNTER}+1
385                 done
386
387                 sleep 1
388                 echo -e "${NORMAL}"
389                 bootstrapCD
390         fi
391
392         if [ "${REAL_ROOT}" = '' ]
393         then
394                 # Undo stuff
395                 umount  "${NEW_ROOT}/dev" 2>/dev/null
396                 umount  "${NEW_ROOT}/sys" 2>/dev/null
397                 umount /sys 2>/dev/null
398
399                 umount  "${NEW_ROOT}"
400                 rm -rf  "${NEW_ROOT}/*"
401
402                 bad_msg 'Could not find CD to boot, something else needed!'
403                 CDROOT=0
404         fi
405 fi
406
407 # Determine root device
408 good_msg 'Determining root device...'
409 while true
410 do
411         while [ "${got_good_root}" != '1' ]
412         do
413                 case "${REAL_ROOT}" in
414                         LABEL=*|UUID=*)
415
416                                 ROOT_DEV=""
417                                 retval=1
418
419                                 if [ ${retval} -ne 0 ]; then
420                                         ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
421                                         retval=$?
422                                 fi
423
424                                 if [ ${retval} -ne 0 ]; then
425                                         ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
426                                         retval=$?
427                                 fi
428
429                                 if [ ${retval} -ne 0 ]; then
430                                         ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
431                                         retval=$?
432                                 fi
433
434                                 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
435                                         good_msg "Detected real_root=${ROOT_DEV}"
436                                         REAL_ROOT="${ROOT_DEV}"
437                                 else
438                                         prompt_user "REAL_ROOT" "root block device"
439                                         got_good_root=0
440                                         continue
441                                 fi
442                                 ;;
443                 esac
444
445                 if [ "${REAL_ROOT}" = '' ]
446                 then
447                         # No REAL_ROOT determined/specified. Prompt user for root block device.
448                         prompt_user "REAL_ROOT" "root block device"
449                         got_good_root=0
450
451                 # Check for a block device or /dev/nfs
452                 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
453                 then
454                         got_good_root=1
455
456                 else
457                         bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
458                         REAL_ROOT=""
459                         got_good_root=0
460                 fi
461         done
462
463
464         if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
465         then
466                 # CD already mounted; no further checks necessary
467                 break
468         elif [ "${LOOPTYPE}" = "sgimips" ]
469         then
470                 # sgimips mounts the livecd root partition directly
471                 # there is no isofs filesystem to worry about
472                 break
473         else
474                 good_msg "Mounting root..."
475
476                 # Try to mount the device as ${NEW_ROOT}
477                 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
478                         findnfsmount
479                 else
480                         # mount ro so fsck doesn't barf later
481                         if [ "${REAL_ROOTFLAGS}" = '' ]; then
482                                 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
483                                 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
484                         else
485                                 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
486                                 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
487                         fi
488                 fi
489
490                 # If mount is successful break out of the loop
491                 # else not a good root and start over.
492                 if [ "$?" = '0' ]
493                 then
494                         if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
495                         then
496                                 break
497                         else
498                                 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
499                                 got_good_root=0
500                                 REAL_ROOT=''
501                         fi
502                 else
503                         bad_msg "Could not mount specified ROOT, try again"
504                         got_good_root=0
505                         REAL_ROOT=''
506                 fi
507         fi
508 done
509 # End determine root device
510
511 #verbose_kmsg
512
513 # If CD root is set determine the looptype to boot
514 if [ "${CDROOT}" = '1' ]
515 then
516         good_msg 'Determining looptype ...'
517         cd "${NEW_ROOT}"
518
519         # Find loop and looptype
520         [ -z "${LOOP}" ] && find_loop
521         [ -z "${LOOPTYPE}" ] && find_looptype
522
523         cache_cd_contents
524
525         # If encrypted, find key and mount, otherwise mount as usual
526         if [ -n "${CRYPT_ROOT}" ]
527         then
528                 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
529                 CRYPT_ROOT='/dev/loop0'
530                 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
531
532                 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
533                 test_success 'Preparing loop filesystem'
534
535                 startLUKS
536
537                 case ${LOOPTYPE} in
538                         normal)
539                                 MOUNTTYPE="ext2"
540                                 ;;
541                         *)
542                                 MOUNTTYPE="${LOOPTYPE}"
543                                 ;;
544                 esac
545                 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
546                 test_success 'Mount filesystem'
547                 FS_LOCATION='mnt/livecd'
548         # Setup the loopback mounts, if unencrypted
549         else
550                 if [ "${LOOPTYPE}" = 'normal' ]
551                 then
552                         good_msg 'Mounting loop filesystem'
553                         mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
554                         test_success 'Mount filesystem'
555                         FS_LOCATION='mnt/livecd'
556                 elif [ "${LOOPTYPE}" = 'squashfs' ]
557                 then
558                         if [ "${USE_AUFS_NORMAL}" != '1' ]; then
559                                 good_msg 'Mounting squashfs filesystem'
560                                 mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
561                         else
562                                 good_msg 'Mounting squashfs & aufs filesystems'
563                                 setup_squashfs_aufs
564                                 test_success 'Mount filesystem'
565                         fi
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" "${CDROOT_PATH}/${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="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
579                 elif [ "${LOOPTYPE}" = 'noloop' ]
580                 then
581                         FS_LOCATION="${CDROOT_PATH/\/}"
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 "${CDROOT_PATH}/add" ]
615                 then
616                                 for targz in $(ls ${CDROOT_PATH}/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} /${FS_LOCATION}
629                 CHROOT=/union
630         elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
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 [ "${current_parent}" != '' ]; then
651                                         var=$(echo "${directory}" | grep "^${current_parent}")
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         mkdir initramfs proc tmp sys 2>/dev/null
676         chmod 1777 tmp
677
678         fi
679
680         #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
681         #if [ "${UML}" = 'UML' ]
682         #then
683         #       # UML Fixes
684         #       good_msg 'Updating for uml system'
685         #fi
686
687         # Let Init scripts know that we booted from CD
688         export CDBOOT
689         CDBOOT=1
690 else
691         if [ "${USE_UNIONFS_NORMAL}" = '1' ]
692         then
693                 mkdir /union_changes
694                 mount -t tmpfs tmpfs /union_changes
695                 setup_unionfs /union_changes ${NEW_ROOT}
696                 mkdir -p ${UNION}/tmp/.initrd
697         fi
698 fi
699
700 # Execute script on the cdrom just before boot to update things if necessary
701 cdupdate
702
703 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
704 then
705         good_msg "Entering ${SUBDIR} to boot"
706         CHROOT="${CHROOT}/${SUBDIR}"
707 fi
708
709 verbose_kmsg
710
711 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
712
713 cd "${CHROOT}"
714 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
715 echo -ne "${BOLD}.${NORMAL}"
716
717 # If devtmpfs is mounted, try move it to the new root
718 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
719 for fs in /dev /sys /proc
720 do
721         if grep -qs "$fs" /proc/mounts
722         then
723                 if ! mount --move $fs "${CHROOT}"$fs
724                 then
725                         umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
726                 fi
727         fi
728 done
729
730 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
731 then
732         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
733 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
734 then
735         echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
736 fi
737
738 echo -e "${BOLD}.${NORMAL}"
739
740 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
741
742 # If we get here, something bad has happened
743 splash 'verbose'
744
745 echo 'A fatal error has probably occured since /sbin/init did not'
746 echo 'boot correctly. Trying to open a shell...'
747 echo
748 exec /bin/bash
749 exec /bin/sh
750 exec /bin/ash
751 exec sh