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 -o noexec,nosuid,nodev 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
36 CMDLINE=$(cat /proc/cmdline)
37 # Scan CMDLINE for any specified real_root= or cdroot arguments
71 # Start livecd loop, looptype options
81 # Start Volume manager options
86 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
113 MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g'`)
120 MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
123 # Redirect output to a specific tty
126 CONSOLE=$(basename ${CONSOLE})
127 # exec >${CONSOLE} <${CONSOLE} 2>&1
131 RAID_DEVICES="${x#*=}"
132 RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
146 iscsi_initiatorname=*)
147 ISCSI_INITIATORNAME=${x#*=}
156 ISCSI_ADDRESS=${x#*=}
162 ISCSI_USERNAME=${x#*=}
165 ISCSI_PASSWORD=${x#*=}
168 ISCSI_USERNAME_IN=${x#*=}
171 ISCSI_PASSWORD_IN=${x#*=}
187 CRYPT_ROOT_KEY=${x#*=}
190 CRYPT_ROOT_KEYDEV=${x#*=}
193 CRYPT_SWAP_KEY=${x#*=}
196 CRYPT_SWAP_KEYDEV=${x#*=}
198 real_resume=*|resume=*)
208 REAL_ROOTFLAGS=${x#*=}
220 if [ ! -x /sbin/unionfs ]
223 bad_msg 'unionfs binary not found: aborting use of unionfs!'
234 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
236 REAL_ROOT="${FAKE_ROOT}"
246 # Setup hotplugging for firmware loading
249 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
250 if [ -z "${DO_modules}" ]
252 good_msg 'Skipping module load; disabled via commandline'
253 elif [ -d "/lib/modules/${KV}" ]
255 good_msg 'Loading modules'
256 # Load appropriate kernel modules
257 if [ "${NODETECT}" != '1' ]
259 for modules in ${MY_HWOPTS}
261 modules_scan ${modules}
264 # Always eval doload=...
265 modules_load ${MDOLIST}
267 good_msg 'Skipping module load; no modules in the ramdisk!'
270 # Apply scan delay if specified
273 # Setup slow USB bits
276 # Start device manager
279 # if doslowusb is passed, pause other 10 seconds here, after mdev load
280 [ "${DO_slowusb}" ] && sleep 10
283 if [ -e /bin/iscsistart ]
288 # Setup btrfs, see bug 303529
291 # Setup md device nodes if they dont exist
299 # Initialize LUKS root device except for livecd's
300 if [ "${CDROOT}" != 1 ]
303 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
305 case "${REAL_RESUME}" in
311 if [ ${retval} -ne 0 ]; then
312 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
316 if [ ${retval} -ne 0 ]; then
317 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
321 if [ ${retval} -ne 0 ]; then
322 RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
326 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
327 good_msg "Detected real_resume=${RESUME_DEV}"
328 REAL_RESUME="${RESUME_DEV}"
337 mkdir -p "${NEW_ROOT}"
340 # Run debug shell if requested
343 if [ "${CDROOT}" = '1' ]
345 good_msg "Making tmpfs for ${NEW_ROOT}"
346 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
348 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
350 mkdir -p "${NEW_ROOT}/${i}"
351 chmod 755 "${NEW_ROOT}/${i}"
353 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
354 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
356 # For SGI LiveCDs ...
357 if [ "${LOOPTYPE}" = "sgimips" ]
359 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
360 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
363 # Required for splash to work. Not an issue with the initrd as this
364 # device isn't created there and is not needed.
367 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
370 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
375 if [ "${REAL_ROOT}" = '' ]
377 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
380 while [ ${COUNTER} -lt 3 ]; do
383 let COUNTER=${COUNTER}+1
391 if [ "${REAL_ROOT}" = '' ]
394 umount "${NEW_ROOT}/dev" 2>/dev/null
395 umount "${NEW_ROOT}/sys" 2>/dev/null
396 umount /sys 2>/dev/null
399 rm -rf "${NEW_ROOT}/*"
401 bad_msg 'Could not find CD to boot, something else needed!'
406 # Determine root device
407 good_msg 'Determining root device...'
410 while [ "${got_good_root}" != '1' ]
412 case "${REAL_ROOT}" in
418 if [ ${retval} -ne 0 ]; then
419 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
423 if [ ${retval} -ne 0 ]; then
424 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
428 if [ ${retval} -ne 0 ]; then
429 ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
433 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
434 good_msg "Detected real_root=${ROOT_DEV}"
435 REAL_ROOT="${ROOT_DEV}"
437 prompt_user "REAL_ROOT" "root block device"
444 if [ "${REAL_ROOT}" = '' ]
446 # No REAL_ROOT determined/specified. Prompt user for root block device.
447 prompt_user "REAL_ROOT" "root block device"
450 # Check for a block device or /dev/nfs
451 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
456 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
463 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
465 # CD already mounted; no further checks necessary
467 elif [ "${LOOPTYPE}" = "sgimips" ]
469 # sgimips mounts the livecd root partition directly
470 # there is no isofs filesystem to worry about
473 good_msg "Mounting root..."
475 # Try to mount the device as ${NEW_ROOT}
476 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
479 # mount ro so fsck doesn't barf later
480 if [ "${REAL_ROOTFLAGS}" = '' ]; then
481 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
482 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
484 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
485 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
489 # If mount is successful break out of the loop
490 # else not a good root and start over.
493 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
497 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
502 bad_msg "Could not mount specified ROOT, try again"
508 # End determine root device
512 # If CD root is set determine the looptype to boot
513 if [ "${CDROOT}" = '1' ]
515 good_msg 'Determining looptype ...'
518 # Find loop and looptype
519 [ -z "${LOOP}" ] && find_loop
520 [ -z "${LOOPTYPE}" ] && find_looptype
524 # If encrypted, find key and mount, otherwise mount as usual
525 if [ -n "${CRYPT_ROOT}" ]
527 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
528 CRYPT_ROOT='/dev/loop0'
529 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
531 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
532 test_success 'Preparing loop filesystem'
541 MOUNTTYPE="${LOOPTYPE}"
544 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
545 test_success 'Mount filesystem'
546 FS_LOCATION='mnt/livecd'
547 # Setup the loopback mounts, if unencrypted
549 if [ "${LOOPTYPE}" = 'normal' ]
551 good_msg 'Mounting loop filesystem'
552 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
553 test_success 'Mount filesystem'
554 FS_LOCATION='mnt/livecd'
555 elif [ "${LOOPTYPE}" = 'squashfs' ]
557 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
558 good_msg 'Mounting squashfs filesystem'
559 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
561 good_msg 'Mounting squashfs & aufs filesystems'
563 test_success 'Mount filesystem'
565 FS_LOCATION='mnt/livecd'
566 elif [ "${LOOPTYPE}" = 'gcloop' ]
568 good_msg 'Mounting gcloop filesystem'
569 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
570 test_success 'losetup the loop device'
572 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
573 test_success 'Mount the losetup loop device'
574 FS_LOCATION='mnt/livecd'
575 elif [ "${LOOPTYPE}" = 'zisofs' ]
577 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
578 elif [ "${LOOPTYPE}" = 'noloop' ]
580 FS_LOCATION='mnt/cdrom'
581 elif [ "${LOOPTYPE}" = 'sgimips' ]
583 # getdvhoff finds the starting offset (in bytes) of the squashfs
584 # partition on the cdrom and returns this offset for losetup
586 # All currently supported SGI Systems use SCSI CD-ROMs, so
587 # so we know that the CD-ROM is usually going to be /dev/sr0.
589 # We use the value given to losetup to set /dev/loop0 to point
590 # to the liveCD root partition, and then mount /dev/loop0 as
592 good_msg 'Locating the SGI LiveCD Root Partition'
594 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
595 "${NEW_ROOT}${CDROOT_DEV}" \
596 "${NEW_ROOT}${REAL_ROOT}"
597 test_success 'losetup /dev/sr0 /dev/loop0'
599 good_msg 'Mounting the Root Partition'
600 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
601 test_success 'mount /dev/loop0 /'
602 FS_LOCATION='mnt/livecd'
608 # Unpacking additional packages from NFS mount
609 # This is useful for adding kernel modules to /lib
610 # We do this now, so that additional packages can add whereever they want.
611 if [ "${REAL_ROOT}" = '/dev/nfs' ]
613 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
615 for targz in $(ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz)
617 tarname=$(basename ${targz})
618 good_msg "Adding additional package ${tarname}"
619 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
625 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
627 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
629 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
631 good_msg "Copying read-write image contents to tmpfs"
632 # Copy over stuff that should be writable
633 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
635 # Now we do the links.
636 for x in ${ROOT_LINKS}
638 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
640 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
642 # List all subdirectories of x
643 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
645 # Strip the prefix of the FS_LOCATION
646 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
648 # Skip this directory if we already linked a parent directory
649 if [ "${current_parent}" != '' ]; then
650 var=$(echo "${directory}" | grep "^${current_parent}")
651 if [ "${var}" != '' ]; then
655 # Test if the directory exists already
656 if [ -e "/${NEW_ROOT}/${directory}" ]
658 # It does exist, link all the individual files
659 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
661 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
662 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
666 # It does not exist, make a link to the livecd
667 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
668 current_parent="${directory}"
674 mkdir initramfs proc tmp sys 2>/dev/null
679 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
680 #if [ "${UML}" = 'UML' ]
683 # good_msg 'Updating for uml system'
686 # Let Init scripts know that we booted from CD
690 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
693 mount -t tmpfs tmpfs /union_changes
694 setup_unionfs /union_changes ${NEW_ROOT}
695 mkdir -p ${UNION}/tmp/.initrd
699 # Execute script on the cdrom just before boot to update things if necessary
702 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
704 good_msg "Entering ${SUBDIR} to boot"
705 CHROOT="${CHROOT}/${SUBDIR}"
710 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
713 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
714 echo -ne "${BOLD}.${NORMAL}"
716 # If devtmpfs is mounted, try move it to the new root
717 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
718 for fs in /dev /sys /proc
720 if grep -qs "$fs" /proc/mounts
722 if ! mount --move $fs "${CHROOT}"$fs
724 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
729 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
731 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
732 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
734 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
737 echo -e "${BOLD}.${NORMAL}"
739 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
741 # If we get here, something bad has happened
744 echo 'A fatal error has probably occured since /sbin/init did not'
745 echo 'boot correctly. Trying to open a shell...'