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.'
102 if [ "${x#*=}" = 'force' ]
121 MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g')
128 MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
131 # Redirect output to a specific tty
134 CONSOLE=$(basename ${CONSOLE})
135 # exec >${CONSOLE} <${CONSOLE} 2>&1
139 RAID_DEVICES="${x#*=}"
140 RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
154 iscsi_initiatorname=*)
155 ISCSI_INITIATORNAME=${x#*=}
164 ISCSI_ADDRESS=${x#*=}
170 ISCSI_USERNAME=${x#*=}
173 ISCSI_PASSWORD=${x#*=}
176 ISCSI_USERNAME_IN=${x#*=}
179 ISCSI_PASSWORD_IN=${x#*=}
195 CRYPT_ROOT_KEY=${x#*=}
198 CRYPT_ROOT_KEYDEV=${x#*=}
201 CRYPT_ROOT_TRIM=${x#*=}
205 CRYPT_SWAP_KEY=${x#*=}
208 CRYPT_SWAP_KEYDEV=${x#*=}
210 real_resume=*|resume=*)
220 REAL_ROOTFLAGS=${x#*=}
232 if [ ! -x /sbin/unionfs ]
235 bad_msg 'unionfs binary not found: aborting use of unionfs!'
246 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
248 REAL_ROOT="${FAKE_ROOT}"
251 # Set variables based on the value of REAL_ROOT
252 case "${REAL_ROOT}" in
258 # Verify that it is safe to use ZFS
259 if [ "USE_ZFS" = "1" ]
263 MY_HWOPTS="${MY_HWOPTS} zfs"
265 bad_msg 'zfs binary not found: aborting use of zfs!'
280 # Setup hotplugging for firmware loading
284 if [ "${KV_2_6_OR_GREATER}" ]
286 good_msg 'Activating mdev'
287 ( cd /sys && mdev -s ) || bad_msg "Failed to receive dynamic updates from mdev"
290 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
291 if [ -z "${DO_modules}" ]
293 good_msg 'Skipping module load; disabled via commandline'
294 elif [ -d "/lib/modules/${KV}" ]
296 good_msg 'Loading modules'
297 # Load appropriate kernel modules
298 if [ "${NODETECT}" != '1' ]
300 for modules in ${MY_HWOPTS}
302 modules_scan ${modules}
305 # Always eval doload=...
306 modules_load ${MDOLIST}
308 good_msg 'Skipping module load; no modules in the ramdisk!'
311 # Apply scan delay if specified
314 # Setup slow USB bits
319 # if doslowusb is passed, pause other 10 seconds here, after mdev load
320 [ "${DO_slowusb}" ] && sleep 10
323 if [ -e /bin/iscsistart ]
328 # Setup btrfs, see bug 303529
331 # Setup md device nodes if they dont exist
339 # Initialize LUKS root device except for livecd's
340 if [ "${CDROOT}" != 1 ]
343 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
345 case "${REAL_RESUME}" in
351 if [ ${retval} -ne 0 ]; then
352 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
356 if [ ${retval} -ne 0 ]; then
357 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
361 if [ ${retval} -ne 0 ]; then
362 RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
366 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
367 good_msg "Detected real_resume=${RESUME_DEV}"
368 REAL_RESUME="${RESUME_DEV}"
377 mkdir -p "${NEW_ROOT}"
380 # Run debug shell if requested
383 if [ "${CDROOT}" = '1' ]
385 good_msg "Making tmpfs for ${NEW_ROOT}"
386 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
388 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
390 mkdir -p "${NEW_ROOT}/${i}"
391 chmod 755 "${NEW_ROOT}/${i}"
393 [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
394 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
395 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
397 # For SGI LiveCDs ...
398 if [ "${LOOPTYPE}" = "sgimips" ]
400 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
401 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
404 # Required for splash to work. Not an issue with the initrd as this
405 # device isn't created there and is not needed.
408 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
411 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
416 if [ "${REAL_ROOT}" = '' ]
418 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
421 while [ ${COUNTER} -lt 3 ]; do
424 let COUNTER=${COUNTER}+1
432 if [ "${REAL_ROOT}" = '' ]
435 umount "${NEW_ROOT}/dev" 2>/dev/null
436 umount "${NEW_ROOT}/sys" 2>/dev/null
437 umount /sys 2>/dev/null
440 rm -rf "${NEW_ROOT}/*"
442 bad_msg 'Could not find CD to boot, something else needed!'
447 # Determine root device
448 good_msg 'Determining root device...'
451 while [ "${got_good_root}" != '1' ]
453 case "${REAL_ROOT}" in
459 if [ ${retval} -ne 0 ]; then
460 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
464 if [ ${retval} -ne 0 ]; then
465 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
469 if [ ${retval} -ne 0 ]; then
470 ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
474 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
475 good_msg "Detected real_root=${ROOT_DEV}"
476 REAL_ROOT="${ROOT_DEV}"
478 prompt_user "REAL_ROOT" "root block device"
484 ROOT_DEV="${REAL_ROOT#*=}"
485 if [ "${ROOT_DEV}" != 'ZFS' ]
487 zfs get type ${ROOT_DEV} > /dev/null
492 REAL_ROOT=${ROOT_DEV}
496 BOOTFS=$(/sbin/zpool list -H -o bootfs)
497 if [ "${BOOTFS}" != '-' ]
503 zfs get type ${i} > /dev/null
506 if [ ${retval} -eq 0 ]; then
519 if [ ${got_good_root} -ne 1 ]; then
520 prompt_user "REAL_ROOT" "root block device"
528 if [ "${REAL_ROOT}" = '' ]
530 # No REAL_ROOT determined/specified. Prompt user for root block device.
531 prompt_user "REAL_ROOT" "root block device"
534 # Check for a block device or /dev/nfs
535 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
540 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
547 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
549 # CD already mounted; no further checks necessary
551 elif [ "${LOOPTYPE}" = "sgimips" ]
553 # sgimips mounts the livecd root partition directly
554 # there is no isofs filesystem to worry about
557 good_msg "Mounting $REAL_ROOT as root..."
559 if [ "${ROOTFSTYPE}" = 'zfs' ]
566 # Try to mount the device as ${NEW_ROOT}
567 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
570 # If $REAL_ROOT is a symlink
571 # Resolve it like util-linux mount does
572 [ -L ${REAL_ROOT} ] && REAL_ROOT=`readlink ${REAL_ROOT}`
573 # mount ro so fsck doesn't barf later
574 if [ "${REAL_ROOTFLAGS}" = '' ]; then
575 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
576 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
578 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
579 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
583 # If mount is successful break out of the loop
584 # else not a good root and start over.
587 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
591 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
596 bad_msg "Could not mount specified ROOT, try again"
602 # End determine root device
606 # If CD root is set determine the looptype to boot
607 if [ "${CDROOT}" = '1' ]
609 good_msg 'Determining looptype ...'
612 # Find loop and looptype
613 [ -z "${LOOP}" ] && find_loop
614 [ -z "${LOOPTYPE}" ] && find_looptype
618 # If encrypted, find key and mount, otherwise mount as usual
619 if [ -n "${CRYPT_ROOT}" ]
621 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
622 CRYPT_ROOT='/dev/loop0'
623 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
625 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
626 test_success 'Preparing loop filesystem'
635 MOUNTTYPE="${LOOPTYPE}"
638 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
639 test_success 'Mount filesystem'
640 FS_LOCATION='mnt/livecd'
641 # Setup the loopback mounts, if unencrypted
643 if [ "${LOOPTYPE}" = 'normal' ]
645 good_msg 'Mounting loop filesystem'
646 mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
647 test_success 'Mount filesystem'
648 FS_LOCATION='mnt/livecd'
649 elif [ "${LOOPTYPE}" = 'squashfs' ]
651 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
652 good_msg 'Mounting squashfs filesystem'
653 _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}"
654 _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached
655 # Upgrade to cached version if possible
656 [ "${DO_cache}" -a -f "${_CACHED_SQUASHFS_PATH}" ] \
657 && _squashfs_path=${_CACHED_SQUASHFS_PATH}
658 mount -t squashfs -o loop,ro "${_squashfs_path}" "${NEW_ROOT}/mnt/livecd" || {
659 bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
660 if [ -e /proc/filesystems ]; then
661 fgrep -q squashfs /proc/filesystems || \
662 bad_msg "HINT: Your kernel does not know filesystem \"squashfs\"."
667 good_msg 'Mounting squashfs & aufs filesystems'
669 test_success 'Mount filesystem'
671 FS_LOCATION='mnt/livecd'
672 elif [ "${LOOPTYPE}" = 'gcloop' ]
674 good_msg 'Mounting gcloop filesystem'
675 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
676 test_success 'losetup the loop device'
678 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
679 test_success 'Mount the losetup loop device'
680 FS_LOCATION='mnt/livecd'
681 elif [ "${LOOPTYPE}" = 'zisofs' ]
683 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
684 elif [ "${LOOPTYPE}" = 'noloop' ]
686 FS_LOCATION="${CDROOT_PATH/\/}"
687 elif [ "${LOOPTYPE}" = 'sgimips' ]
689 # getdvhoff finds the starting offset (in bytes) of the squashfs
690 # partition on the cdrom and returns this offset for losetup
692 # All currently supported SGI Systems use SCSI CD-ROMs, so
693 # so we know that the CD-ROM is usually going to be /dev/sr0.
695 # We use the value given to losetup to set /dev/loop0 to point
696 # to the liveCD root partition, and then mount /dev/loop0 as
698 good_msg 'Locating the SGI LiveCD Root Partition'
700 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
701 "${NEW_ROOT}${CDROOT_DEV}" \
702 "${NEW_ROOT}${REAL_ROOT}"
703 test_success 'losetup /dev/sr0 /dev/loop0'
705 good_msg 'Mounting the Root Partition'
706 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
707 test_success 'mount /dev/loop0 /'
708 FS_LOCATION='mnt/livecd'
714 # Unpacking additional packages from NFS mount
715 # This is useful for adding kernel modules to /lib
716 # We do this now, so that additional packages can add whereever they want.
717 if [ "${REAL_ROOT}" = '/dev/nfs' ]
719 if [ -e "${CDROOT_PATH}/add" ]
721 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
723 tarname=$(basename ${targz})
724 good_msg "Adding additional package ${tarname}"
725 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
731 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
733 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
735 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
737 good_msg "Copying read-write image contents to tmpfs"
738 # Copy over stuff that should be writable
739 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") || {
740 bad_msg "Copying failed, dropping into a shell."
744 # Now we do the links.
745 for x in ${ROOT_LINKS}
747 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
749 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
751 # List all subdirectories of x
752 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
754 # Strip the prefix of the FS_LOCATION
755 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
757 # Skip this directory if we already linked a parent directory
758 if [ "${current_parent}" != '' ]; then
759 var=$(echo "${directory}" | grep "^${current_parent}")
760 if [ "${var}" != '' ]; then
764 # Test if the directory exists already
765 if [ -e "/${NEW_ROOT}/${directory}" ]
767 # It does exist, link all the individual files
768 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
770 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
771 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
775 # It does not exist, make a link to the livecd
776 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
777 current_parent="${directory}"
783 mkdir initramfs proc tmp sys 2>/dev/null
788 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
789 #if [ "${UML}" = 'UML' ]
792 # good_msg 'Updating for uml system'
795 # Let Init scripts know that we booted from CD
799 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
802 mount -t tmpfs tmpfs /union_changes
803 setup_unionfs /union_changes ${NEW_ROOT}
804 mkdir -p ${UNION}/tmp/.initrd
808 # Mount the additional things as required by udev & systemd
809 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
810 fslist=$(get_mounts_list)
815 for fs in $fslist; do
816 dev=$(get_mount_device $fs)
817 [ -z "${dev}" ] && continue
818 # Resolve it like util-linux mount does
819 [ -L ${dev} ] && dev=`readlink ${dev}`
820 # In this case, it's probably part of the filesystem
821 # and not a mountpoint
822 [ -z "$dev" ] && continue
823 fstype=$(get_mount_fstype $fs)
824 # ro must be trailing, and the options will always contain at least 'defaults'
825 opts="$(get_mount_options $fs | strip_mount_options),ro"
827 cmd="mount -t $fstype -o $opts $dev $mnt"
828 good_msg "Mounting $dev as ${fs}: $cmd"
830 bad_msg "Unable to mount $dev for $fs"
834 # Execute script on the cdrom just before boot to update things if necessary
837 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
839 good_msg "Entering ${SUBDIR} to boot"
840 CHROOT="${CHROOT}/${SUBDIR}"
845 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
848 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
849 echo -ne "${BOLD}.${NORMAL}"
851 # If devtmpfs is mounted, try move it to the new root
852 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
853 for fs in /dev /sys /proc
855 if grep -qs "$fs" /proc/mounts
857 if ! mount --move $fs "${CHROOT}"$fs
859 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
864 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
866 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
867 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
869 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
872 echo -e "${BOLD}.${NORMAL}"
874 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
876 # If we get here, something bad has happened
879 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
880 echo "boot correctly. Trying to open a shell..."