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