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