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
254 ZFS_POOL=${REAL_ROOT#*=}
255 ZFS_POOL=${ZFS_POOL%%/*}
263 # Verify that it is safe to use ZFS
264 if [ "USE_ZFS" = "1" ]
266 if [ -x /sbin/zfs -a -x /sbin/zpool ]
268 MY_HWOPTS="${MY_HWOPTS} zfs"
272 [ -x /sbin/zfs ] || bad_msg '/sbin/zfs not found!'
273 [ -x /sbin/zpool ] || bad_msg '/sbin/zpool not found!'
274 bad_msg 'Aborting use of zfs!'
289 if [ "${KV_2_6_OR_GREATER}" ]
291 good_msg 'Activating mdev'
293 # Serialize hotplug events
296 # Setup hotplugging for firmware loading
297 echo /sbin/mdev > /proc/sys/kernel/hotplug
299 # Setup mdev netlink socket daemon
300 ( cd /sys && mdev -s ) || bad_msg "Failed to receive dynamic updates from mdev"
303 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
304 if [ -z "${DO_modules}" ]
306 good_msg 'Skipping module load; disabled via commandline'
307 elif [ -d "/lib/modules/${KV}" ]
309 good_msg 'Loading modules'
310 # Load appropriate kernel modules
311 if [ "${NODETECT}" != '1' ]
313 for modules in ${MY_HWOPTS}
315 modules_scan ${modules}
318 # Always eval doload=...
319 modules_load ${MDOLIST}
321 good_msg 'Skipping module load; no modules in the ramdisk!'
324 # Apply scan delay if specified
327 # Setup slow USB bits
332 # if doslowusb is passed, pause other 10 seconds here, after mdev load
333 [ "${DO_slowusb}" ] && sleep 10
336 if [ -e /bin/iscsistart ]
341 # Setup btrfs, see bug 303529
344 # Setup md device nodes if they dont exist
352 # Initialize LUKS root device except for livecd's
353 if [ "${CDROOT}" != 1 ]
356 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
358 case "${REAL_RESUME}" in
364 if [ ${retval} -ne 0 ]; then
365 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
369 if [ ${retval} -ne 0 ]; then
370 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
374 if [ ${retval} -ne 0 ]; then
375 RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}")
379 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
380 good_msg "Detected real_resume=${RESUME_DEV}"
381 REAL_RESUME="${RESUME_DEV}"
390 mkdir -p "${NEW_ROOT}"
393 # Run debug shell if requested
396 if [ "${CDROOT}" = '1' ]
398 good_msg "Making tmpfs for ${NEW_ROOT}"
399 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
401 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
403 mkdir -p "${NEW_ROOT}/${i}"
404 chmod 755 "${NEW_ROOT}/${i}"
406 [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
407 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
408 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
410 # For SGI LiveCDs ...
411 if [ "${LOOPTYPE}" = "sgimips" ]
413 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
414 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
417 # Required for splash to work. Not an issue with the initrd as this
418 # device isn't created there and is not needed.
421 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
424 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
429 if [ "${REAL_ROOT}" = '' ]
431 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
434 while [ ${COUNTER} -lt 3 ]; do
437 let COUNTER=${COUNTER}+1
445 if [ "${REAL_ROOT}" = '' ]
448 umount "${NEW_ROOT}/dev" 2>/dev/null
449 umount "${NEW_ROOT}/sys" 2>/dev/null
450 umount /sys 2>/dev/null
453 rm -rf "${NEW_ROOT}/*"
455 bad_msg 'Could not find CD to boot, something else needed!'
460 # Determine root device
461 good_msg 'Determining root device...'
464 while [ "${got_good_root}" != '1' ]
466 case "${REAL_ROOT}" in
472 if [ ${retval} -ne 0 ]; then
473 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
477 if [ ${retval} -ne 0 ]; then
478 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
482 if [ ${retval} -ne 0 ]; then
483 ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
487 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
488 good_msg "Detected real_root=${ROOT_DEV}"
489 REAL_ROOT="${ROOT_DEV}"
491 prompt_user "REAL_ROOT" "root block device"
497 if [ "${USE_ZFS}" = '0' ]; then
498 prompt_user "REAL_ROOT" "root block device"
502 ROOT_DEV="${REAL_ROOT#*=}"
503 if [ "${ROOT_DEV}" != 'ZFS' ]
505 if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
508 REAL_ROOT=${ROOT_DEV}
511 bad_msg "${ROOT_DEV} is not a filesystem"
512 prompt_user "REAL_ROOT" "root block device"
517 BOOTFS=$(/sbin/zpool list -H -o bootfs)
518 if [ "${BOOTFS}" != '-' ]
524 zfs get type ${i} > /dev/null
527 if [ ${retval} -eq 0 ]; then
540 if [ ${got_good_root} -ne 1 ]; then
541 prompt_user "REAL_ROOT" "root block device"
549 if [ "${REAL_ROOT}" = '' ]
551 # No REAL_ROOT determined/specified. Prompt user for root block device.
552 prompt_user "REAL_ROOT" "root block device"
555 # Check for a block device or /dev/nfs
556 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
561 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
568 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
570 # CD already mounted; no further checks necessary
572 elif [ "${LOOPTYPE}" = "sgimips" ]
574 # sgimips mounts the livecd root partition directly
575 # there is no isofs filesystem to worry about
578 good_msg "Mounting $REAL_ROOT as root..."
580 if [ "${ROOTFSTYPE}" = 'zfs' ]
582 if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
586 MOUNT_STATE=rw,zfsutil
592 # Try to mount the device as ${NEW_ROOT}
593 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
596 # If $REAL_ROOT is a symlink
597 # Resolve it like util-linux mount does
598 [ -L ${REAL_ROOT} ] && REAL_ROOT=`readlink ${REAL_ROOT}`
599 # mount ro so fsck doesn't barf later
600 if [ "${REAL_ROOTFLAGS}" = '' ]; then
601 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
602 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
604 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
605 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
609 # If mount is successful break out of the loop
610 # else not a good root and start over.
613 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
617 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
622 bad_msg "Could not mount specified ROOT, try again"
628 # End determine root device
632 # If CD root is set determine the looptype to boot
633 if [ "${CDROOT}" = '1' ]
635 good_msg 'Determining looptype ...'
638 # Find loop and looptype
639 [ -z "${LOOP}" ] && find_loop
640 [ -z "${LOOPTYPE}" ] && find_looptype
644 # If encrypted, find key and mount, otherwise mount as usual
645 if [ -n "${CRYPT_ROOT}" ]
647 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
648 CRYPT_ROOT='/dev/loop0'
649 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
651 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
652 test_success 'Preparing loop filesystem'
661 MOUNTTYPE="${LOOPTYPE}"
664 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
665 test_success 'Mount filesystem'
666 FS_LOCATION='mnt/livecd'
667 # Setup the loopback mounts, if unencrypted
669 if [ "${LOOPTYPE}" = 'normal' ]
671 good_msg 'Mounting loop filesystem'
672 mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
673 test_success 'Mount filesystem'
674 FS_LOCATION='mnt/livecd'
675 elif [ "${LOOPTYPE}" = 'squashfs' ]
677 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
678 good_msg 'Mounting squashfs filesystem'
679 _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}"
680 _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached
681 # Upgrade to cached version if possible
682 [ "${DO_cache}" -a -f "${_CACHED_SQUASHFS_PATH}" ] \
683 && _squashfs_path=${_CACHED_SQUASHFS_PATH}
684 mount -t squashfs -o loop,ro "${_squashfs_path}" "${NEW_ROOT}/mnt/livecd" || {
685 bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
686 if [ -e /proc/filesystems ]; then
687 fgrep -q squashfs /proc/filesystems || \
688 bad_msg "HINT: Your kernel does not know filesystem \"squashfs\"."
693 good_msg 'Mounting squashfs & aufs filesystems'
695 test_success 'Mount filesystem'
697 FS_LOCATION='mnt/livecd'
698 elif [ "${LOOPTYPE}" = 'gcloop' ]
700 good_msg 'Mounting gcloop filesystem'
701 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
702 test_success 'losetup the loop device'
704 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
705 test_success 'Mount the losetup loop device'
706 FS_LOCATION='mnt/livecd'
707 elif [ "${LOOPTYPE}" = 'zisofs' ]
709 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
710 elif [ "${LOOPTYPE}" = 'noloop' ]
712 FS_LOCATION="${CDROOT_PATH/\/}"
713 elif [ "${LOOPTYPE}" = 'sgimips' ]
715 # getdvhoff finds the starting offset (in bytes) of the squashfs
716 # partition on the cdrom and returns this offset for losetup
718 # All currently supported SGI Systems use SCSI CD-ROMs, so
719 # so we know that the CD-ROM is usually going to be /dev/sr0.
721 # We use the value given to losetup to set /dev/loop0 to point
722 # to the liveCD root partition, and then mount /dev/loop0 as
724 good_msg 'Locating the SGI LiveCD Root Partition'
726 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
727 "${NEW_ROOT}${CDROOT_DEV}" \
728 "${NEW_ROOT}${REAL_ROOT}"
729 test_success 'losetup /dev/sr0 /dev/loop0'
731 good_msg 'Mounting the Root Partition'
732 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
733 test_success 'mount /dev/loop0 /'
734 FS_LOCATION='mnt/livecd'
740 # Unpacking additional packages from NFS mount
741 # This is useful for adding kernel modules to /lib
742 # We do this now, so that additional packages can add whereever they want.
743 if [ "${REAL_ROOT}" = '/dev/nfs' ]
745 if [ -e "${CDROOT_PATH}/add" ]
747 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
749 tarname=$(basename ${targz})
750 good_msg "Adding additional package ${tarname}"
751 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
757 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
759 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
761 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
763 good_msg "Copying read-write image contents to tmpfs"
764 # Copy over stuff that should be writable
765 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") || {
766 bad_msg "Copying failed, dropping into a shell."
770 # Now we do the links.
771 for x in ${ROOT_LINKS}
773 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
775 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
777 # List all subdirectories of x
778 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
780 # Strip the prefix of the FS_LOCATION
781 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
783 # Skip this directory if we already linked a parent directory
784 if [ "${current_parent}" != '' ]; then
785 var=$(echo "${directory}" | grep "^${current_parent}")
786 if [ "${var}" != '' ]; then
790 # Test if the directory exists already
791 if [ -e "/${NEW_ROOT}/${directory}" ]
793 # It does exist, link all the individual files
794 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
796 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
797 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
801 # It does not exist, make a link to the livecd
802 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
803 current_parent="${directory}"
809 mkdir initramfs proc tmp sys run 2>/dev/null
814 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
815 #if [ "${UML}" = 'UML' ]
818 # good_msg 'Updating for uml system'
821 # Let Init scripts know that we booted from CD
825 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
828 mount -t tmpfs tmpfs /union_changes
829 setup_unionfs /union_changes ${NEW_ROOT}
830 mkdir -p ${UNION}/tmp/.initrd
834 # Mount the additional things as required by udev & systemd
835 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
836 fslist=$(get_mounts_list)
841 for fs in $fslist; do
842 dev=$(get_mount_device $fs)
843 [ -z "${dev}" ] && continue
844 # Resolve it like util-linux mount does
845 [ -L ${dev} ] && dev=`readlink ${dev}`
846 # In this case, it's probably part of the filesystem
847 # and not a mountpoint
848 [ -z "$dev" ] && continue
849 fstype=$(get_mount_fstype $fs)
850 if get_mount_options $fs | fgrep -q bind ; then
852 dev=${NEW_ROOT}${dev}
854 # ro must be trailing, and the options will always contain at least 'defaults'
855 opts="$(get_mount_options $fs | strip_mount_options),ro"
858 cmd="mount -t $fstype -o $opts $dev $mnt"
859 good_msg "Mounting $dev as ${fs}: $cmd"
861 bad_msg "Unable to mount $dev for $fs"
865 # Execute script on the cdrom just before boot to update things if necessary
868 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
870 good_msg "Entering ${SUBDIR} to boot"
871 CHROOT="${CHROOT}/${SUBDIR}"
876 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
879 mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
880 echo -ne "${BOLD}.${NORMAL}"
882 # If devtmpfs is mounted, try move it to the new root
883 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
884 for fs in /dev /sys /proc
886 if grep -qs "$fs" /proc/mounts
888 if ! mount --move $fs "${CHROOT}"$fs
890 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
895 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
897 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
898 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
900 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
903 echo -e "${BOLD}.${NORMAL}"
905 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
907 # If we get here, something bad has happened
910 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
911 echo "boot correctly. Trying to open a shell..."