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