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
42 mkdir -p /etc/cmdline /etc/modprobe.d
72 # Start livecd loop, looptype options
82 # Start Volume manager options
87 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
103 if [ "${x#*=}" = 'force' ]
122 MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g')
129 MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
132 # Redirect output to a specific tty
135 CONSOLE=$(basename ${CONSOLE})
136 # exec >${CONSOLE} <${CONSOLE} 2>&1
140 RAID_DEVICES="${x#*=}"
141 RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
155 iscsi_initiatorname=*)
156 ISCSI_INITIATORNAME=${x#*=}
165 ISCSI_ADDRESS=${x#*=}
171 ISCSI_USERNAME=${x#*=}
174 ISCSI_PASSWORD=${x#*=}
177 ISCSI_USERNAME_IN=${x#*=}
180 ISCSI_PASSWORD_IN=${x#*=}
196 CRYPT_ROOT_KEY=${x#*=}
199 CRYPT_ROOT_KEYDEV=${x#*=}
202 CRYPT_ROOT_TRIM=${x#*=}
206 CRYPT_SWAP_KEY=${x#*=}
209 CRYPT_SWAP_KEYDEV=${x#*=}
211 real_resume=*|resume=*)
221 REAL_ROOTFLAGS=${x#*=}
233 if [ ! -x /sbin/unionfs ]
236 bad_msg 'unionfs binary not found: aborting use of unionfs!'
247 echo "${x#*.}" >> "/etc/module_options/${x%%.*}.conf"
254 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
256 REAL_ROOT="${FAKE_ROOT}"
259 # Set variables based on the value of REAL_ROOT
260 case "${REAL_ROOT}" in
262 ZFS_POOL=${REAL_ROOT#*=}
263 ZFS_POOL=${ZFS_POOL%%/*}
271 # Verify that it is safe to use ZFS
272 if [ "USE_ZFS" = "1" ]
274 if [ -x /sbin/zfs -a -x /sbin/zpool ]
276 MY_HWOPTS="${MY_HWOPTS} zfs"
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!'
297 if [ "${KV_2_6_OR_GREATER}" ]
299 good_msg 'Activating mdev'
301 # Serialize hotplug events
304 # Setup hotplugging for firmware loading
305 echo /sbin/mdev > /proc/sys/kernel/hotplug
308 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
309 if [ -z "${DO_modules}" ]
311 good_msg 'Skipping module load; disabled via commandline'
312 elif [ -d "/lib/modules/${KV}" ]
314 good_msg 'Loading modules'
315 # Load appropriate kernel modules
316 if [ "${NODETECT}" != '1' ]
318 for modules in ${MY_HWOPTS}
320 modules_scan ${modules}
323 # Always eval doload=...
324 modules_load ${MDOLIST}
326 good_msg 'Skipping module load; no modules in the ramdisk!'
329 # Ensure that device nodes are properly configured
330 if [ "${KV_2_6_OR_GREATER}" ]
332 mdev -s || bad_msg "mdev -s failed"
335 # Apply scan delay if specified
338 # Setup slow USB bits
343 # if doslowusb is passed, pause other 10 seconds here, after mdev load
344 [ "${DO_slowusb}" ] && sleep 10
347 if [ -e /bin/iscsistart ]
352 # Setup btrfs, see bug 303529
355 # Setup md device nodes if they dont exist
363 # Initialize LUKS root device except for livecd's
364 if [ "${CDROOT}" != 1 ]
367 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
369 case "${REAL_RESUME}" in
375 if [ ${retval} -ne 0 ]; then
376 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
380 if [ ${retval} -ne 0 ]; then
381 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
385 if [ ${retval} -ne 0 ]; then
386 RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}")
390 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
391 good_msg "Detected real_resume=${RESUME_DEV}"
392 REAL_RESUME="${RESUME_DEV}"
401 mkdir -p "${NEW_ROOT}"
404 # Run debug shell if requested
407 if [ "${CDROOT}" = '1' ]
409 good_msg "Making tmpfs for ${NEW_ROOT}"
410 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
412 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
414 mkdir -p "${NEW_ROOT}/${i}"
415 chmod 755 "${NEW_ROOT}/${i}"
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
421 # For SGI LiveCDs ...
422 if [ "${LOOPTYPE}" = "sgimips" ]
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
428 # Required for splash to work. Not an issue with the initrd as this
429 # device isn't created there and is not needed.
432 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
435 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
440 if [ "${REAL_ROOT}" = '' ]
442 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
445 while [ ${COUNTER} -lt 3 ]; do
448 let COUNTER=${COUNTER}+1
456 if [ "${REAL_ROOT}" = '' ]
459 umount "${NEW_ROOT}/dev" 2>/dev/null
460 umount "${NEW_ROOT}/sys" 2>/dev/null
461 umount /sys 2>/dev/null
464 rm -rf "${NEW_ROOT}/*"
466 bad_msg 'Could not find CD to boot, something else needed!'
471 # Determine root device
472 good_msg 'Determining root device...'
475 while [ "${got_good_root}" != '1' ]
477 case "${REAL_ROOT}" in
483 if [ ${retval} -ne 0 ]; then
484 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
488 if [ ${retval} -ne 0 ]; then
489 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
493 if [ ${retval} -ne 0 ]; then
494 ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
498 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
499 good_msg "Detected real_root=${ROOT_DEV}"
500 REAL_ROOT="${ROOT_DEV}"
502 prompt_user "REAL_ROOT" "root block device"
508 if [ "${USE_ZFS}" = '0' ]; then
509 prompt_user "REAL_ROOT" "root block device"
513 ROOT_DEV="${REAL_ROOT#*=}"
514 if [ "${ROOT_DEV}" != 'ZFS' ]
516 if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
519 REAL_ROOT=${ROOT_DEV}
522 bad_msg "${ROOT_DEV} is not a filesystem"
523 prompt_user "REAL_ROOT" "root block device"
528 BOOTFS=$(/sbin/zpool list -H -o bootfs)
529 if [ "${BOOTFS}" != '-' ]
535 zfs get type ${i} > /dev/null
538 if [ ${retval} -eq 0 ]; then
553 if [ ${got_good_root} -ne 1 ]; then
554 prompt_user "REAL_ROOT" "root block device"
562 if [ "${REAL_ROOT}" = '' ]
564 # No REAL_ROOT determined/specified. Prompt user for root block device.
565 prompt_user "REAL_ROOT" "root block device"
568 # Check for a block device or /dev/nfs
569 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
574 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
581 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
583 # CD already mounted; no further checks necessary
585 elif [ "${LOOPTYPE}" = "sgimips" ]
587 # sgimips mounts the livecd root partition directly
588 # there is no isofs filesystem to worry about
591 good_msg "Mounting $REAL_ROOT as root..."
593 if [ "${ROOTFSTYPE}" = 'zfs' ]
595 if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
599 MOUNT_STATE=rw,zfsutil
605 # Try to mount the device as ${NEW_ROOT}
606 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
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}
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}
622 # If mount is successful break out of the loop
623 # else not a good root and start over.
626 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
630 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
635 bad_msg "Could not mount specified ROOT, try again"
641 # End determine root device
645 # If CD root is set determine the looptype to boot
646 if [ "${CDROOT}" = '1' ]
648 good_msg 'Determining looptype ...'
651 # Find loop and looptype
652 [ -z "${LOOP}" ] && find_loop
653 [ -z "${LOOPTYPE}" ] && find_looptype
657 # If encrypted, find key and mount, otherwise mount as usual
658 if [ -n "${CRYPT_ROOT}" ]
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}"
664 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
665 test_success 'Preparing loop filesystem'
674 MOUNTTYPE="${LOOPTYPE}"
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
682 if [ "${LOOPTYPE}" = 'normal' ]
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' ]
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\"."
706 good_msg 'Mounting squashfs & aufs filesystems'
708 test_success 'Mount filesystem'
710 FS_LOCATION='mnt/livecd'
711 elif [ "${LOOPTYPE}" = 'gcloop' ]
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'
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' ]
722 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
723 elif [ "${LOOPTYPE}" = 'noloop' ]
725 FS_LOCATION="${CDROOT_PATH/\/}"
726 elif [ "${LOOPTYPE}" = 'sgimips' ]
728 # getdvhoff finds the starting offset (in bytes) of the squashfs
729 # partition on the cdrom and returns this offset for losetup
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.
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
737 good_msg 'Locating the SGI LiveCD Root Partition'
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'
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'
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' ]
758 if [ -e "${CDROOT_PATH}/add" ]
760 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
762 tarname=$(basename ${targz})
763 good_msg "Adding additional package ${tarname}"
764 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
770 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
772 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
774 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
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."
783 # Now we do the links.
784 for x in ${ROOT_LINKS}
786 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
788 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
790 # List all subdirectories of x
791 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
793 # Strip the prefix of the FS_LOCATION
794 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
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
803 # Test if the directory exists already
804 if [ -e "/${NEW_ROOT}/${directory}" ]
806 # It does exist, link all the individual files
807 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
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
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}"
822 mkdir initramfs proc tmp sys run 2>/dev/null
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}"
832 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
833 #if [ "${UML}" = 'UML' ]
836 # good_msg 'Updating for uml system'
839 # Let Init scripts know that we booted from CD
843 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
846 mount -t tmpfs tmpfs /union_changes
847 setup_unionfs /union_changes ${NEW_ROOT}
848 mkdir -p ${UNION}/tmp/.initrd
852 # Mount the additional things as required by udev & systemd
853 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
854 fslist=$(get_mounts_list)
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
870 dev=${NEW_ROOT}${dev}
872 # ro must be trailing, and the options will always contain at least 'defaults'
873 opts="$(get_mount_options $fs | strip_mount_options),ro"
876 cmd="mount -t $fstype -o $opts $dev $mnt"
877 good_msg "Mounting $dev as ${fs}: $cmd"
879 bad_msg "Unable to mount $dev for $fs"
883 # Execute script on the cdrom just before boot to update things if necessary
886 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
888 good_msg "Entering ${SUBDIR} to boot"
889 CHROOT="${CHROOT}/${SUBDIR}"
894 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
897 mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
898 echo -ne "${BOLD}.${NORMAL}"
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
904 if grep -qs "$fs" /proc/mounts
906 if ! mount --move $fs "${CHROOT}"$fs
908 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
913 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
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" ]
918 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
921 echo -e "${BOLD}.${NORMAL}"
923 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
925 # If we get here, something bad has happened
928 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
929 echo "boot correctly. Trying to open a shell..."