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!'
244 ## for "module.param[=val]" we creating
245 ## /etc/modprobe.d/module.param.conf: "options module param[=val]"
246 ## /etc/cmdline/module.param:"param[=val]"
247 ## first for CONFIG_MODPROBE_SMALL=n, next for script modprobe
252 echo "options ${x%%.*} ${x#*.}" >"/etc/modprobe.d/$y.conf"
253 echo "${x#*.}" >"/etc/cmdline/$y"
258 echo "options ${x%%.*} ${x#*.}" >"/etc/modprobe.d/${x%%/*}.conf"
259 echo "${x#*.}" >"/etc/cmdline/${x%%/*}"
264 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
266 REAL_ROOT="${FAKE_ROOT}"
269 # Set variables based on the value of REAL_ROOT
270 case "${REAL_ROOT}" in
272 ZFS_POOL=${REAL_ROOT#*=}
273 ZFS_POOL=${ZFS_POOL%%/*}
281 # Verify that it is safe to use ZFS
282 if [ "USE_ZFS" = "1" ]
284 if [ -x /sbin/zfs -a -x /sbin/zpool ]
286 MY_HWOPTS="${MY_HWOPTS} zfs"
290 [ -x /sbin/zfs ] || bad_msg '/sbin/zfs not found!'
291 [ -x /sbin/zpool ] || bad_msg '/sbin/zpool not found!'
292 bad_msg 'Aborting use of zfs!'
307 if [ "${KV_2_6_OR_GREATER}" ]
309 good_msg 'Activating mdev'
311 # Serialize hotplug events
314 # Setup hotplugging for firmware loading
315 echo /sbin/mdev > /proc/sys/kernel/hotplug
317 # Setup mdev netlink socket daemon
318 ( cd /sys && mdev -s ) || bad_msg "Failed to receive dynamic updates from mdev"
321 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
322 if [ -z "${DO_modules}" ]
324 good_msg 'Skipping module load; disabled via commandline'
325 elif [ -d "/lib/modules/${KV}" ]
327 good_msg 'Loading modules'
328 # Load appropriate kernel modules
329 if [ "${NODETECT}" != '1' ]
331 for modules in ${MY_HWOPTS}
333 modules_scan ${modules}
336 # Always eval doload=...
337 modules_load ${MDOLIST}
339 good_msg 'Skipping module load; no modules in the ramdisk!'
342 # Apply scan delay if specified
345 # Setup slow USB bits
350 # if doslowusb is passed, pause other 10 seconds here, after mdev load
351 [ "${DO_slowusb}" ] && sleep 10
354 if [ -e /bin/iscsistart ]
359 # Setup btrfs, see bug 303529
362 # Setup md device nodes if they dont exist
370 # Initialize LUKS root device except for livecd's
371 if [ "${CDROOT}" != 1 ]
374 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
376 case "${REAL_RESUME}" in
382 if [ ${retval} -ne 0 ]; then
383 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
387 if [ ${retval} -ne 0 ]; then
388 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
392 if [ ${retval} -ne 0 ]; then
393 RESUME_DEV=$(blkid -o device -l -t "${REAL_RESUME}")
397 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
398 good_msg "Detected real_resume=${RESUME_DEV}"
399 REAL_RESUME="${RESUME_DEV}"
408 mkdir -p "${NEW_ROOT}"
411 # Run debug shell if requested
414 if [ "${CDROOT}" = '1' ]
416 good_msg "Making tmpfs for ${NEW_ROOT}"
417 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
419 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
421 mkdir -p "${NEW_ROOT}/${i}"
422 chmod 755 "${NEW_ROOT}/${i}"
424 [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
425 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
426 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
428 # For SGI LiveCDs ...
429 if [ "${LOOPTYPE}" = "sgimips" ]
431 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
432 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
435 # Required for splash to work. Not an issue with the initrd as this
436 # device isn't created there and is not needed.
439 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
442 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
447 if [ "${REAL_ROOT}" = '' ]
449 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
452 while [ ${COUNTER} -lt 3 ]; do
455 let COUNTER=${COUNTER}+1
463 if [ "${REAL_ROOT}" = '' ]
466 umount "${NEW_ROOT}/dev" 2>/dev/null
467 umount "${NEW_ROOT}/sys" 2>/dev/null
468 umount /sys 2>/dev/null
471 rm -rf "${NEW_ROOT}/*"
473 bad_msg 'Could not find CD to boot, something else needed!'
478 # Determine root device
479 good_msg 'Determining root device...'
482 while [ "${got_good_root}" != '1' ]
484 case "${REAL_ROOT}" in
490 if [ ${retval} -ne 0 ]; then
491 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
495 if [ ${retval} -ne 0 ]; then
496 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
500 if [ ${retval} -ne 0 ]; then
501 ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
505 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
506 good_msg "Detected real_root=${ROOT_DEV}"
507 REAL_ROOT="${ROOT_DEV}"
509 prompt_user "REAL_ROOT" "root block device"
515 if [ "${USE_ZFS}" = '0' ]; then
516 prompt_user "REAL_ROOT" "root block device"
520 ROOT_DEV="${REAL_ROOT#*=}"
521 if [ "${ROOT_DEV}" != 'ZFS' ]
523 if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
526 REAL_ROOT=${ROOT_DEV}
529 bad_msg "${ROOT_DEV} is not a filesystem"
530 prompt_user "REAL_ROOT" "root block device"
535 BOOTFS=$(/sbin/zpool list -H -o bootfs)
536 if [ "${BOOTFS}" != '-' ]
542 zfs get type ${i} > /dev/null
545 if [ ${retval} -eq 0 ]; then
560 if [ ${got_good_root} -ne 1 ]; then
561 prompt_user "REAL_ROOT" "root block device"
569 if [ "${REAL_ROOT}" = '' ]
571 # No REAL_ROOT determined/specified. Prompt user for root block device.
572 prompt_user "REAL_ROOT" "root block device"
575 # Check for a block device or /dev/nfs
576 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
581 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
588 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
590 # CD already mounted; no further checks necessary
592 elif [ "${LOOPTYPE}" = "sgimips" ]
594 # sgimips mounts the livecd root partition directly
595 # there is no isofs filesystem to worry about
598 good_msg "Mounting $REAL_ROOT as root..."
600 if [ "${ROOTFSTYPE}" = 'zfs' ]
602 if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
606 MOUNT_STATE=rw,zfsutil
612 # Try to mount the device as ${NEW_ROOT}
613 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
616 # If $REAL_ROOT is a symlink
617 # Resolve it like util-linux mount does
618 [ -L ${REAL_ROOT} ] && REAL_ROOT=`readlink ${REAL_ROOT}`
619 # mount ro so fsck doesn't barf later
620 if [ "${REAL_ROOTFLAGS}" = '' ]; then
621 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
622 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
624 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
625 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
629 # If mount is successful break out of the loop
630 # else not a good root and start over.
633 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
637 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
642 bad_msg "Could not mount specified ROOT, try again"
648 # End determine root device
652 # If CD root is set determine the looptype to boot
653 if [ "${CDROOT}" = '1' ]
655 good_msg 'Determining looptype ...'
658 # Find loop and looptype
659 [ -z "${LOOP}" ] && find_loop
660 [ -z "${LOOPTYPE}" ] && find_looptype
664 # If encrypted, find key and mount, otherwise mount as usual
665 if [ -n "${CRYPT_ROOT}" ]
667 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
668 CRYPT_ROOT='/dev/loop0'
669 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
671 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
672 test_success 'Preparing loop filesystem'
681 MOUNTTYPE="${LOOPTYPE}"
684 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
685 test_success 'Mount filesystem'
686 FS_LOCATION='mnt/livecd'
687 # Setup the loopback mounts, if unencrypted
689 if [ "${LOOPTYPE}" = 'normal' ]
691 good_msg 'Mounting loop filesystem'
692 mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
693 test_success 'Mount filesystem'
694 FS_LOCATION='mnt/livecd'
695 elif [ "${LOOPTYPE}" = 'squashfs' ]
697 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
698 good_msg 'Mounting squashfs filesystem'
699 _CACHED_SQUASHFS_PATH="${NEW_ROOT}/mnt/${LOOP}"
700 _squashfs_path="${CDROOT_PATH}/${LOOPEXT}${LOOP}" # Default to uncached
701 # Upgrade to cached version if possible
702 [ "${DO_cache}" -a -f "${_CACHED_SQUASHFS_PATH}" ] \
703 && _squashfs_path=${_CACHED_SQUASHFS_PATH}
704 mount -t squashfs -o loop,ro "${_squashfs_path}" "${NEW_ROOT}/mnt/livecd" || {
705 bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
706 if [ -e /proc/filesystems ]; then
707 fgrep -q squashfs /proc/filesystems || \
708 bad_msg "HINT: Your kernel does not know filesystem \"squashfs\"."
713 good_msg 'Mounting squashfs & aufs filesystems'
715 test_success 'Mount filesystem'
717 FS_LOCATION='mnt/livecd'
718 elif [ "${LOOPTYPE}" = 'gcloop' ]
720 good_msg 'Mounting gcloop filesystem'
721 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
722 test_success 'losetup the loop device'
724 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
725 test_success 'Mount the losetup loop device'
726 FS_LOCATION='mnt/livecd'
727 elif [ "${LOOPTYPE}" = 'zisofs' ]
729 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
730 elif [ "${LOOPTYPE}" = 'noloop' ]
732 FS_LOCATION="${CDROOT_PATH/\/}"
733 elif [ "${LOOPTYPE}" = 'sgimips' ]
735 # getdvhoff finds the starting offset (in bytes) of the squashfs
736 # partition on the cdrom and returns this offset for losetup
738 # All currently supported SGI Systems use SCSI CD-ROMs, so
739 # so we know that the CD-ROM is usually going to be /dev/sr0.
741 # We use the value given to losetup to set /dev/loop0 to point
742 # to the liveCD root partition, and then mount /dev/loop0 as
744 good_msg 'Locating the SGI LiveCD Root Partition'
746 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
747 "${NEW_ROOT}${CDROOT_DEV}" \
748 "${NEW_ROOT}${REAL_ROOT}"
749 test_success 'losetup /dev/sr0 /dev/loop0'
751 good_msg 'Mounting the Root Partition'
752 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
753 test_success 'mount /dev/loop0 /'
754 FS_LOCATION='mnt/livecd'
760 # Unpacking additional packages from NFS mount
761 # This is useful for adding kernel modules to /lib
762 # We do this now, so that additional packages can add whereever they want.
763 if [ "${REAL_ROOT}" = '/dev/nfs' ]
765 if [ -e "${CDROOT_PATH}/add" ]
767 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
769 tarname=$(basename ${targz})
770 good_msg "Adding additional package ${tarname}"
771 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
777 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
779 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
781 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
783 good_msg "Copying read-write image contents to tmpfs"
784 # Copy over stuff that should be writable
785 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") || {
786 bad_msg "Copying failed, dropping into a shell."
790 # Now we do the links.
791 for x in ${ROOT_LINKS}
793 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
795 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
797 # List all subdirectories of x
798 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
800 # Strip the prefix of the FS_LOCATION
801 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
803 # Skip this directory if we already linked a parent directory
804 if [ "${current_parent}" != '' ]; then
805 var=$(echo "${directory}" | grep "^${current_parent}")
806 if [ "${var}" != '' ]; then
810 # Test if the directory exists already
811 if [ -e "/${NEW_ROOT}/${directory}" ]
813 # It does exist, link all the individual files
814 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
816 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
817 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
821 # It does not exist, make a link to the livecd
822 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
823 current_parent="${directory}"
829 mkdir initramfs proc tmp sys run 2>/dev/null
834 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
835 #if [ "${UML}" = 'UML' ]
838 # good_msg 'Updating for uml system'
841 # Let Init scripts know that we booted from CD
845 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
848 mount -t tmpfs tmpfs /union_changes
849 setup_unionfs /union_changes ${NEW_ROOT}
850 mkdir -p ${UNION}/tmp/.initrd
854 # Mount the additional things as required by udev & systemd
855 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
856 fslist=$(get_mounts_list)
861 for fs in $fslist; do
862 dev=$(get_mount_device $fs)
863 [ -z "${dev}" ] && continue
864 # Resolve it like util-linux mount does
865 [ -L ${dev} ] && dev=`readlink ${dev}`
866 # In this case, it's probably part of the filesystem
867 # and not a mountpoint
868 [ -z "$dev" ] && continue
869 fstype=$(get_mount_fstype $fs)
870 if get_mount_options $fs | fgrep -q bind ; then
872 dev=${NEW_ROOT}${dev}
874 # ro must be trailing, and the options will always contain at least 'defaults'
875 opts="$(get_mount_options $fs | strip_mount_options),ro"
878 cmd="mount -t $fstype -o $opts $dev $mnt"
879 good_msg "Mounting $dev as ${fs}: $cmd"
881 bad_msg "Unable to mount $dev for $fs"
885 # Execute script on the cdrom just before boot to update things if necessary
888 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
890 good_msg "Entering ${SUBDIR} to boot"
891 CHROOT="${CHROOT}/${SUBDIR}"
896 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
899 mkdir "${CHROOT}/proc" "${CHROOT}/sys" "${CHROOT}/run" 2>/dev/null
900 echo -ne "${BOLD}.${NORMAL}"
902 # If devtmpfs is mounted, try move it to the new root
903 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
904 for fs in /dev /sys /proc
906 if grep -qs "$fs" /proc/mounts
908 if ! mount --move $fs "${CHROOT}"$fs
910 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
915 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
917 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
918 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
920 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
923 echo -e "${BOLD}.${NORMAL}"
925 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
927 # If we get here, something bad has happened
930 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
931 echo "boot correctly. Trying to open a shell..."