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.'
100 if [ ! -x /sbin/zfs ]; then
102 bad_msg 'zfs binary not found: aborting use of zfs!'
105 MY_HWOPTS="${MY_HWOPTS} zfs"
106 if [ "${x#*=}" = 'force' ]
126 MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g')
133 MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
136 # Redirect output to a specific tty
139 CONSOLE=$(basename ${CONSOLE})
140 # exec >${CONSOLE} <${CONSOLE} 2>&1
144 RAID_DEVICES="${x#*=}"
145 RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
159 iscsi_initiatorname=*)
160 ISCSI_INITIATORNAME=${x#*=}
169 ISCSI_ADDRESS=${x#*=}
175 ISCSI_USERNAME=${x#*=}
178 ISCSI_PASSWORD=${x#*=}
181 ISCSI_USERNAME_IN=${x#*=}
184 ISCSI_PASSWORD_IN=${x#*=}
200 CRYPT_ROOT_KEY=${x#*=}
203 CRYPT_ROOT_KEYDEV=${x#*=}
206 CRYPT_ROOT_TRIM=${x#*=}
210 CRYPT_SWAP_KEY=${x#*=}
213 CRYPT_SWAP_KEYDEV=${x#*=}
215 real_resume=*|resume=*)
225 REAL_ROOTFLAGS=${x#*=}
237 if [ ! -x /sbin/unionfs ]
240 bad_msg 'unionfs binary not found: aborting use of unionfs!'
251 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
253 REAL_ROOT="${FAKE_ROOT}"
263 # Setup hotplugging for firmware loading
266 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
267 if [ -z "${DO_modules}" ]
269 good_msg 'Skipping module load; disabled via commandline'
270 elif [ -d "/lib/modules/${KV}" ]
272 good_msg 'Loading modules'
273 # Load appropriate kernel modules
274 if [ "${NODETECT}" != '1' ]
276 for modules in ${MY_HWOPTS}
278 modules_scan ${modules}
281 # Always eval doload=...
282 modules_load ${MDOLIST}
284 good_msg 'Skipping module load; no modules in the ramdisk!'
287 # Apply scan delay if specified
290 # Setup slow USB bits
293 # Start device manager
296 # if doslowusb is passed, pause other 10 seconds here, after mdev load
297 [ "${DO_slowusb}" ] && sleep 10
300 if [ -e /bin/iscsistart ]
305 # Setup btrfs, see bug 303529
308 # Setup md device nodes if they dont exist
316 # Initialize LUKS root device except for livecd's
317 if [ "${CDROOT}" != 1 ]
320 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
322 case "${REAL_RESUME}" in
328 if [ ${retval} -ne 0 ]; then
329 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
333 if [ ${retval} -ne 0 ]; then
334 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
338 if [ ${retval} -ne 0 ]; then
339 RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
343 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
344 good_msg "Detected real_resume=${RESUME_DEV}"
345 REAL_RESUME="${RESUME_DEV}"
354 mkdir -p "${NEW_ROOT}"
357 # Run debug shell if requested
360 if [ "${CDROOT}" = '1' ]
362 good_msg "Making tmpfs for ${NEW_ROOT}"
363 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
365 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
367 mkdir -p "${NEW_ROOT}/${i}"
368 chmod 755 "${NEW_ROOT}/${i}"
370 [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
371 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
372 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
374 # For SGI LiveCDs ...
375 if [ "${LOOPTYPE}" = "sgimips" ]
377 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
378 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
381 # Required for splash to work. Not an issue with the initrd as this
382 # device isn't created there and is not needed.
385 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
388 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
393 if [ "${REAL_ROOT}" = '' ]
395 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
398 while [ ${COUNTER} -lt 3 ]; do
401 let COUNTER=${COUNTER}+1
409 if [ "${REAL_ROOT}" = '' ]
412 umount "${NEW_ROOT}/dev" 2>/dev/null
413 umount "${NEW_ROOT}/sys" 2>/dev/null
414 umount /sys 2>/dev/null
417 rm -rf "${NEW_ROOT}/*"
419 bad_msg 'Could not find CD to boot, something else needed!'
424 # Determine root device
425 good_msg 'Determining root device...'
428 while [ "${got_good_root}" != '1' ]
430 case "${REAL_ROOT}" in
436 if [ ${retval} -ne 0 ]; then
437 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
441 if [ ${retval} -ne 0 ]; then
442 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
446 if [ ${retval} -ne 0 ]; then
447 ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
451 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
452 good_msg "Detected real_root=${ROOT_DEV}"
453 REAL_ROOT="${ROOT_DEV}"
455 prompt_user "REAL_ROOT" "root block device"
461 ROOT_DEV="${REAL_ROOT#*=}"
462 if [ "${ROOT_DEV}" != 'ZFS' ]
464 zfs get type ${ROOT_DEV} > /dev/null
469 REAL_ROOT=${ROOT_DEV}
473 BOOTFS=$(/sbin/zpool list -H -o bootfs)
474 if [ "${BOOTFS}" != '-' ]
480 zfs get type ${i} > /dev/null
483 if [ ${retval} -eq 0 ]; then
496 if [ ${got_good_root} -ne 1 ]; then
497 prompt_user "REAL_ROOT" "root block device"
505 if [ "${REAL_ROOT}" = '' ]
507 # No REAL_ROOT determined/specified. Prompt user for root block device.
508 prompt_user "REAL_ROOT" "root block device"
511 # Check for a block device or /dev/nfs
512 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
517 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
524 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
526 # CD already mounted; no further checks necessary
528 elif [ "${LOOPTYPE}" = "sgimips" ]
530 # sgimips mounts the livecd root partition directly
531 # there is no isofs filesystem to worry about
534 good_msg "Mounting $REAL_ROOT as root..."
536 if [ "${ROOTFSTYPE}" = 'zfs' ]
543 # Try to mount the device as ${NEW_ROOT}
544 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
547 # If $REAL_ROOT is a symlink
548 # Resolve it like util-linux mount does
549 [ -L ${REAL_ROOT} ] && REAL_ROOT=`readlink ${REAL_ROOT}`
550 # mount ro so fsck doesn't barf later
551 if [ "${REAL_ROOTFLAGS}" = '' ]; then
552 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
553 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
555 good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
556 mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
560 # If mount is successful break out of the loop
561 # else not a good root and start over.
564 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
568 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
573 bad_msg "Could not mount specified ROOT, try again"
579 # End determine root device
583 # If CD root is set determine the looptype to boot
584 if [ "${CDROOT}" = '1' ]
586 good_msg 'Determining looptype ...'
589 # Find loop and looptype
590 [ -z "${LOOP}" ] && find_loop
591 [ -z "${LOOPTYPE}" ] && find_looptype
595 # If encrypted, find key and mount, otherwise mount as usual
596 if [ -n "${CRYPT_ROOT}" ]
598 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
599 CRYPT_ROOT='/dev/loop0'
600 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
602 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
603 test_success 'Preparing loop filesystem'
612 MOUNTTYPE="${LOOPTYPE}"
615 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
616 test_success 'Mount filesystem'
617 FS_LOCATION='mnt/livecd'
618 # Setup the loopback mounts, if unencrypted
620 if [ "${LOOPTYPE}" = 'normal' ]
622 good_msg 'Mounting loop filesystem'
623 mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
624 test_success 'Mount filesystem'
625 FS_LOCATION='mnt/livecd'
626 elif [ "${LOOPTYPE}" = 'squashfs' ]
628 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
629 good_msg 'Mounting squashfs filesystem'
630 mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd" || {
631 bad_msg "Squashfs filesystem could not be mounted, dropping into shell."
632 if [ -e /proc/filesystems ]; then
633 fgrep -q squashfs /proc/filesystems || \
634 bad_msg "HINT: Your kernel does not know filesystem \"squashfs\"."
639 good_msg 'Mounting squashfs & aufs filesystems'
641 test_success 'Mount filesystem'
643 FS_LOCATION='mnt/livecd'
644 elif [ "${LOOPTYPE}" = 'gcloop' ]
646 good_msg 'Mounting gcloop filesystem'
647 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
648 test_success 'losetup the loop device'
650 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
651 test_success 'Mount the losetup loop device'
652 FS_LOCATION='mnt/livecd'
653 elif [ "${LOOPTYPE}" = 'zisofs' ]
655 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
656 elif [ "${LOOPTYPE}" = 'noloop' ]
658 FS_LOCATION="${CDROOT_PATH/\/}"
659 elif [ "${LOOPTYPE}" = 'sgimips' ]
661 # getdvhoff finds the starting offset (in bytes) of the squashfs
662 # partition on the cdrom and returns this offset for losetup
664 # All currently supported SGI Systems use SCSI CD-ROMs, so
665 # so we know that the CD-ROM is usually going to be /dev/sr0.
667 # We use the value given to losetup to set /dev/loop0 to point
668 # to the liveCD root partition, and then mount /dev/loop0 as
670 good_msg 'Locating the SGI LiveCD Root Partition'
672 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
673 "${NEW_ROOT}${CDROOT_DEV}" \
674 "${NEW_ROOT}${REAL_ROOT}"
675 test_success 'losetup /dev/sr0 /dev/loop0'
677 good_msg 'Mounting the Root Partition'
678 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
679 test_success 'mount /dev/loop0 /'
680 FS_LOCATION='mnt/livecd'
686 # Unpacking additional packages from NFS mount
687 # This is useful for adding kernel modules to /lib
688 # We do this now, so that additional packages can add whereever they want.
689 if [ "${REAL_ROOT}" = '/dev/nfs' ]
691 if [ -e "${CDROOT_PATH}/add" ]
693 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
695 tarname=$(basename ${targz})
696 good_msg "Adding additional package ${tarname}"
697 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
703 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
705 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
707 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
709 good_msg "Copying read-write image contents to tmpfs"
710 # Copy over stuff that should be writable
711 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}") || {
712 bad_msg "Copying failed, dropping into a shell."
716 # Now we do the links.
717 for x in ${ROOT_LINKS}
719 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
721 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
723 # List all subdirectories of x
724 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
726 # Strip the prefix of the FS_LOCATION
727 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
729 # Skip this directory if we already linked a parent directory
730 if [ "${current_parent}" != '' ]; then
731 var=$(echo "${directory}" | grep "^${current_parent}")
732 if [ "${var}" != '' ]; then
736 # Test if the directory exists already
737 if [ -e "/${NEW_ROOT}/${directory}" ]
739 # It does exist, link all the individual files
740 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
742 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
743 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
747 # It does not exist, make a link to the livecd
748 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
749 current_parent="${directory}"
755 mkdir initramfs proc tmp sys 2>/dev/null
760 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
761 #if [ "${UML}" = 'UML' ]
764 # good_msg 'Updating for uml system'
767 # Let Init scripts know that we booted from CD
771 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
774 mount -t tmpfs tmpfs /union_changes
775 setup_unionfs /union_changes ${NEW_ROOT}
776 mkdir -p ${UNION}/tmp/.initrd
780 # Mount the additional things as required by udev & systemd
781 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
782 fslist=$(get_mounts_list)
787 for fs in $fslist; do
788 dev=$(get_mount_device $fs)
789 [ -z "${dev}" ] && continue
790 # Resolve it like util-linux mount does
791 [ -L ${dev} ] && dev=`readlink ${dev}`
792 # In this case, it's probably part of the filesystem
793 # and not a mountpoint
794 [ -z "$dev" ] && continue
795 fstype=$(get_mount_fstype $fs)
796 # ro must be trailing, and the options will always contain at least 'defaults'
797 opts="$(get_mount_options $fs | strip_mount_options),ro"
799 cmd="mount -t $fstype -o $opts $dev $mnt"
800 good_msg "Mounting $dev as ${fs}: $cmd"
802 bad_msg "Unable to mount $dev for $fs"
806 # Execute script on the cdrom just before boot to update things if necessary
809 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
811 good_msg "Entering ${SUBDIR} to boot"
812 CHROOT="${CHROOT}/${SUBDIR}"
817 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
820 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
821 echo -ne "${BOLD}.${NORMAL}"
823 # If devtmpfs is mounted, try move it to the new root
824 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
825 for fs in /dev /sys /proc
827 if grep -qs "$fs" /proc/mounts
829 if ! mount --move $fs "${CHROOT}"$fs
831 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
836 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
838 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
839 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
841 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
844 echo -e "${BOLD}.${NORMAL}"
846 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
848 # If we get here, something bad has happened
851 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
852 echo "boot correctly. Trying to open a shell..."