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