10 [ -e /etc/initrd.splash ] && . /etc/initrd.splash
13 exec >${CONSOLE} <${CONSOLE} 2>&1
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".'
23 mount -t proc proc /proc >/dev/null 2>&1
24 mount -o remount,rw / >/dev/null 2>&1
27 /bin/busybox --install -s
31 [ -e /linuxrc ] && rm /linuxrc
35 ln -s /bin/lvm /bin/vgscan
36 ln -s /bin/lvm /bin/vgchange
42 CMDLINE=`cat /proc/cmdline`
43 # Scan CMDLINE for any specified real_root= or cdroot arguments
51 REAL_ROOT=`parse_opt "${x}"`
54 FAKE_ROOT=`parse_opt "${x}"`
57 SUBDIR=`parse_opt "${x}"`
60 REAL_INIT=`parse_opt "${x}"`
63 INIT_OPTS=`parse_opt "${x}"`
71 CDROOT_DEV=`parse_opt "${x}"`
74 CDROOT_TYPE=`parse_opt "${x}"`
76 # Start livecd loop, looptype options
78 LOOP=`parse_opt "${x}"`
81 LOOPTYPE=`parse_opt "${x}"`
83 # Start Volume manager options
88 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
98 DMRAID_OPTS=`parse_opt "${x}"`
105 bad_msg 'Using doevms2 is deprecated, use doevms, instead.'
114 SDELAY=`parse_opt "${x}"`
121 MDOLIST=`parse_opt "${x}"`
122 MDOLIST="`echo ${MDOLIST} | sed -e 's/,/ /g'`"
128 MLIST=`parse_opt "${x}"`
129 MLIST="`echo ${MLIST} | sed -e 's/,/ /g'`"
132 # Redirect output to a specific tty
133 CONSOLE\=*|console\=*)
134 CONSOLE=`parse_opt "${x}"`
135 exec >${CONSOLE} <${CONSOLE} 2>&1
139 RAID_DEVICES="`parse_opt ${x}`"
140 RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
143 MDPART=`parse_opt "${x}"`
147 IP=`parse_opt "${x}"`
150 NFSROOT=`parse_opt "${x}"`
153 CRYPT_ROOT=`parse_opt "${x}"`
156 CRYPT_SWAP=`parse_opt "${x}"`
159 CRYPT_ROOT_KEY=`parse_opt "${x}"`
162 CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
165 CRYPT_SWAP_KEY=`parse_opt "${x}"`
168 CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
171 REAL_RESUME=`parse_opt "${x}"`
180 REAL_ROOTFLAGS=`parse_opt "${x}"`
183 keymap=`parse_opt "${x}"`
186 if [ ! -x /sbin/unionfs ]
189 bad_msg 'unionfs binary not found: aborting use of unionfs!'
198 # if [ ! -x /sbin/unionfs ]
200 # USE_UNIONFS_NORMAL=0
201 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
203 # USE_UNIONFS_NORMAL=1
204 # CMD_UNIONFS=`parse_opt "${x}"`
205 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
206 # if [ "$?" -eq '0' ]
208 # UID=`echo ${CMD_UNIONFS#*,}`
209 # UNIONFS=`echo ${CMD_UNIONFS%,*}`
211 # UNIONFS=${CMD_UNIONFS}
218 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" -eq 0 \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
220 REAL_ROOT="${FAKE_ROOT}"
230 # Setup hotplugging for firmware loading
233 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
234 if [ -z "${DO_modules}" ]
236 good_msg 'Skipping module load; disabled via commandline'
237 elif [ -d "/lib/modules/${KV}" ]
239 good_msg 'Loading modules'
240 # Load appropriate kernel modules
241 if [ "${NODETECT}" != '1' ]
243 for modules in ${MY_HWOPTS}
245 modules_scan ${modules}
248 # Always eval doload=...
249 modules_load ${MDOLIST}
251 good_msg 'Skipping module load; no modules in the ramdisk!'
254 # Delay if needed for USB hardware
257 # Start device manager
260 # Setup md device nodes if they dont exist
268 # Initialize LUKS root device except for livecd's
269 if [ "${CDROOT}" != 1 ]
272 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
274 case "${REAL_RESUME}" in
280 if [ "${retval}" -ne '0' ]; then
281 RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
285 if [ "$retval" -ne '0' ]; then
286 RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
290 if [ "${retval}" -ne '0' ]; then
291 RESUME_DEV=`blkid -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
295 if [ "${retval}" -eq '0' ] && [ -n "${RESUME_DEV}" ]; then
296 good_msg "Detected real_resume=${RESUME_DEV}"
297 REAL_RESUME="${RESUME_DEV}"
308 mkdir -p "${NEW_ROOT}"
311 # Run debug shell if requested
314 if [ "${CDROOT}" = '1' ]
316 good_msg "Making tmpfs for ${NEW_ROOT}"
317 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
319 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
321 mkdir -p "${NEW_ROOT}/${i}"
322 chmod 755 "${NEW_ROOT}/${i}"
324 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
325 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
327 # For SGI LiveCDs ...
328 if [ "${LOOPTYPE}" = "sgimips" ]
330 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
331 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
334 # Required for splash to work. Not an issue with the initrd as this
335 # device isn't created there and is not needed.
338 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
341 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
346 if [ "${REAL_ROOT}" = '' ]
348 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
351 while [ ${COUNTER} -lt 3 ]; do
354 let COUNTER=${COUNTER}+1
362 if [ "${REAL_ROOT}" = '' ]
365 umount "${NEW_ROOT}/dev" 2>/dev/null
366 umount "${NEW_ROOT}/sys" 2>/dev/null
367 umount /sys 2>/dev/null
370 rm -rf "${NEW_ROOT}/*"
372 bad_msg 'Could not find CD to boot, something else needed!'
377 # Determine root device
378 good_msg 'Determining root device...'
381 while [ "${got_good_root}" != '1' ]
383 case "${REAL_ROOT}" in
389 if [ "${retval}" -ne '0' ]; then
390 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
394 if [ "$retval" -ne '0' ]; then
395 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
399 if [ "${retval}" -ne '0' ]; then
400 ROOT_DEV=`blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
404 if [ "${retval}" -eq '0' ] && [ -n "${ROOT_DEV}" ]; then
405 good_msg "Detected real_root=${ROOT_DEV}"
406 REAL_ROOT="${ROOT_DEV}"
408 whereis "REAL_ROOT" "root block device"
415 if [ "${REAL_ROOT}" = '' ]
417 # No REAL_ROOT determined/specified. Prompt user for root block device.
418 whereis "REAL_ROOT" "root block device"
421 # Check for a block device or /dev/nfs
422 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
427 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
434 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
436 # CD already mounted; no further checks necessary
438 elif [ "${LOOPTYPE}" = "sgimips" ]
440 # sgimips mounts the livecd root partition directly
441 # there is no isofs filesystem to worry about
444 good_msg "Mounting root..."
446 # Try to mount the device as ${NEW_ROOT}
447 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
450 # mount ro so fsck doesn't barf later
451 if [ "${REAL_ROOTFLAGS}" = '' ]; then
452 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
454 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
455 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
459 # If mount is successful break out of the loop
460 # else not a good root and start over.
463 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
467 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
472 bad_msg "Could not mount specified ROOT, try again"
478 # End determine root device
482 # If CD root is set determine the looptype to boot
483 if [ "${CDROOT}" = '1' ]
485 good_msg 'Determining looptype ...'
488 # Find loop and looptype
489 [ -z "${LOOP}" ] && find_loop
490 [ -z "${LOOPTYPE}" ] && find_looptype
494 # If encrypted, find key and mount, otherwise mount as usual
495 if [ -n "${CRYPT_ROOT}" ]
497 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
498 CRYPT_ROOT='/dev/loop0'
499 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
501 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
502 test_success 'Preparing loop filesystem'
511 MOUNTTYPE="${LOOPTYPE}"
514 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
515 test_success 'Mount filesystem'
516 FS_LOCATION='mnt/livecd'
517 # Setup the loopback mounts, if unencrypted
519 if [ "${LOOPTYPE}" = 'normal' ]
521 good_msg 'Mounting loop filesystem'
522 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
523 test_success 'Mount filesystem'
524 FS_LOCATION='mnt/livecd'
525 elif [ "${LOOPTYPE}" = 'squashfs' ]
527 good_msg 'Mounting squashfs filesystem'
528 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
529 test_success 'Mount filesystem'
530 FS_LOCATION='mnt/livecd'
531 elif [ "${LOOPTYPE}" = 'gcloop' ]
533 good_msg 'Mounting gcloop filesystem'
534 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
535 test_success 'losetup the loop device'
537 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
538 test_success 'Mount the losetup loop device'
539 FS_LOCATION='mnt/livecd'
540 elif [ "${LOOPTYPE}" = 'zisofs' ]
542 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
543 elif [ "${LOOPTYPE}" = 'noloop' ]
545 FS_LOCATION='mnt/cdrom'
546 elif [ "${LOOPTYPE}" = 'sgimips' ]
548 # getdvhoff finds the starting offset (in bytes) of the squashfs
549 # partition on the cdrom and returns this offset for losetup
551 # All currently supported SGI Systems use SCSI CD-ROMs, so
552 # so we know that the CD-ROM is usually going to be /dev/sr0.
554 # We use the value given to losetup to set /dev/loop0 to point
555 # to the liveCD root partition, and then mount /dev/loop0 as
557 good_msg 'Locating the SGI LiveCD Root Partition'
559 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
560 "${NEW_ROOT}${CDROOT_DEV}" \
561 "${NEW_ROOT}${REAL_ROOT}"
562 test_success 'losetup /dev/sr0 /dev/loop0'
564 good_msg 'Mounting the Root Partition'
565 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
566 test_success 'mount /dev/loop0 /'
567 FS_LOCATION='mnt/livecd'
573 # Unpacking additional packages from NFS mount
574 # This is useful for adding kernel modules to /lib
575 # We do this now, so that additional packages can add whereever they want.
576 if [ "${REAL_ROOT}" = '/dev/nfs' ]
578 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
580 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
582 tarname=`basename ${targz}`
583 good_msg "Adding additional package ${tarname}"
584 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
590 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
592 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
596 good_msg "Copying read-write image contents to tmpfs"
597 # Copy over stuff that should be writable
598 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
600 # Now we do the links.
601 for x in ${ROOT_LINKS}
603 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
605 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
607 # List all subdirectories of x
608 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
610 # Strip the prefix of the FS_LOCATION
611 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
613 # Skip this directory if we already linked a parent directory
614 if [ "${curent_parrent}" != '' ]; then
615 var=`echo "${directory}" | grep "^${curent_parrent}"`
616 if [ "${var}" != '' ]; then
620 # Test if the directory exists already
621 if [ -e "/${NEW_ROOT}/${directory}" ]
623 # It does exist, link all the individual files
624 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
626 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
627 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
631 # It does not exist, make a link to the livecd
632 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
633 current_parent="${directory}"
639 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
643 mkdir initramfs proc tmp sys 2>/dev/null
648 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
649 #if [ "${UML}" = 'UML' ]
652 # good_msg 'Updating for uml system'
655 # Let Init scripts know that we booted from CD
659 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
664 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
667 mount -t tmpfs tmpfs /union_changes
668 setup_unionfs /union_changes ${NEW_ROOT}
669 mkdir -p ${UNION}/tmp/.initrd
673 # Execute script on the cdrom just before boot to update things if necessary
676 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
678 good_msg "Entering ${SUBDIR} to boot"
679 CHROOT="${CHROOT}/${SUBDIR}"
684 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
685 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
687 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
688 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
690 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
694 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
695 echo -ne "${BOLD}.${NORMAL}"
696 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
697 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
698 echo -e "${BOLD}.${NORMAL}"
700 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
702 # If we get here, something bad has happened
705 echo 'A fatal error has probably occured since /sbin/init did not'
706 echo 'boot correctly. Trying to open a shell...'