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.'
113 MDOLIST=$(echo ${MDOLIST} | sed -e 's/,/ /g')
120 MLIST="$(echo ${MLIST} | sed -e 's/,/ /g')"
123 # Redirect output to a specific tty
126 CONSOLE=$(basename ${CONSOLE})
127 # exec >${CONSOLE} <${CONSOLE} 2>&1
131 RAID_DEVICES="${x#*=}"
132 RAID_DEVICES="$(echo ${RAID_DEVICES} | sed -e 's/,/ /g')"
146 iscsi_initiatorname=*)
147 ISCSI_INITIATORNAME=${x#*=}
156 ISCSI_ADDRESS=${x#*=}
162 ISCSI_USERNAME=${x#*=}
165 ISCSI_PASSWORD=${x#*=}
168 ISCSI_USERNAME_IN=${x#*=}
171 ISCSI_PASSWORD_IN=${x#*=}
187 CRYPT_ROOT_KEY=${x#*=}
190 CRYPT_ROOT_KEYDEV=${x#*=}
193 CRYPT_ROOT_TRIM=${x#*=}
197 CRYPT_SWAP_KEY=${x#*=}
200 CRYPT_SWAP_KEYDEV=${x#*=}
202 real_resume=*|resume=*)
212 REAL_ROOTFLAGS=${x#*=}
224 if [ ! -x /sbin/unionfs ]
227 bad_msg 'unionfs binary not found: aborting use of unionfs!'
238 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
240 REAL_ROOT="${FAKE_ROOT}"
250 # Setup hotplugging for firmware loading
253 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
254 if [ -z "${DO_modules}" ]
256 good_msg 'Skipping module load; disabled via commandline'
257 elif [ -d "/lib/modules/${KV}" ]
259 good_msg 'Loading modules'
260 # Load appropriate kernel modules
261 if [ "${NODETECT}" != '1' ]
263 for modules in ${MY_HWOPTS}
265 modules_scan ${modules}
268 # Always eval doload=...
269 modules_load ${MDOLIST}
271 good_msg 'Skipping module load; no modules in the ramdisk!'
274 # Apply scan delay if specified
277 # Setup slow USB bits
280 # Start device manager
283 # if doslowusb is passed, pause other 10 seconds here, after mdev load
284 [ "${DO_slowusb}" ] && sleep 10
287 if [ -e /bin/iscsistart ]
292 # Setup btrfs, see bug 303529
295 # Setup md device nodes if they dont exist
303 # Initialize LUKS root device except for livecd's
304 if [ "${CDROOT}" != 1 ]
307 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
309 case "${REAL_RESUME}" in
315 if [ ${retval} -ne 0 ]; then
316 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
320 if [ ${retval} -ne 0 ]; then
321 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
325 if [ ${retval} -ne 0 ]; then
326 RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
330 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
331 good_msg "Detected real_resume=${RESUME_DEV}"
332 REAL_RESUME="${RESUME_DEV}"
341 mkdir -p "${NEW_ROOT}"
344 # Run debug shell if requested
347 if [ "${CDROOT}" = '1' ]
349 good_msg "Making tmpfs for ${NEW_ROOT}"
350 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
352 for i in dev mnt mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
354 mkdir -p "${NEW_ROOT}/${i}"
355 chmod 755 "${NEW_ROOT}/${i}"
357 [ ! -d "${CDROOT_PATH}" ] && mkdir -p "${CDROOT_PATH}"
358 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
359 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
361 # For SGI LiveCDs ...
362 if [ "${LOOPTYPE}" = "sgimips" ]
364 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
365 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
368 # Required for splash to work. Not an issue with the initrd as this
369 # device isn't created there and is not needed.
372 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
375 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
380 if [ "${REAL_ROOT}" = '' ]
382 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
385 while [ ${COUNTER} -lt 3 ]; do
388 let COUNTER=${COUNTER}+1
396 if [ "${REAL_ROOT}" = '' ]
399 umount "${NEW_ROOT}/dev" 2>/dev/null
400 umount "${NEW_ROOT}/sys" 2>/dev/null
401 umount /sys 2>/dev/null
404 rm -rf "${NEW_ROOT}/*"
406 bad_msg 'Could not find CD to boot, something else needed!'
411 # Determine root device
412 good_msg 'Determining root device...'
415 while [ "${got_good_root}" != '1' ]
417 case "${REAL_ROOT}" in
423 if [ ${retval} -ne 0 ]; then
424 ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
428 if [ ${retval} -ne 0 ]; then
429 ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
433 if [ ${retval} -ne 0 ]; then
434 ROOT_DEV=$(blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null)
438 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
439 good_msg "Detected real_root=${ROOT_DEV}"
440 REAL_ROOT="${ROOT_DEV}"
442 prompt_user "REAL_ROOT" "root block device"
449 if [ "${REAL_ROOT}" = '' ]
451 # No REAL_ROOT determined/specified. Prompt user for root block device.
452 prompt_user "REAL_ROOT" "root block device"
455 # Check for a block device or /dev/nfs
456 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
461 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
468 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
470 # CD already mounted; no further checks necessary
472 elif [ "${LOOPTYPE}" = "sgimips" ]
474 # sgimips mounts the livecd root partition directly
475 # there is no isofs filesystem to worry about
478 good_msg "Mounting root..."
480 # Try to mount the device as ${NEW_ROOT}
481 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
484 # mount ro so fsck doesn't barf later
485 if [ "${REAL_ROOTFLAGS}" = '' ]; then
486 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
487 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
489 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
490 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
494 # If mount is successful break out of the loop
495 # else not a good root and start over.
498 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
502 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
507 bad_msg "Could not mount specified ROOT, try again"
513 # End determine root device
517 # If CD root is set determine the looptype to boot
518 if [ "${CDROOT}" = '1' ]
520 good_msg 'Determining looptype ...'
523 # Find loop and looptype
524 [ -z "${LOOP}" ] && find_loop
525 [ -z "${LOOPTYPE}" ] && find_looptype
529 # If encrypted, find key and mount, otherwise mount as usual
530 if [ -n "${CRYPT_ROOT}" ]
532 CRYPT_ROOT_KEY="$(head -n 1 "${CDROOT_PATH}"/livecd)"
533 CRYPT_ROOT='/dev/loop0'
534 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
536 losetup /dev/loop0 "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
537 test_success 'Preparing loop filesystem'
546 MOUNTTYPE="${LOOPTYPE}"
549 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
550 test_success 'Mount filesystem'
551 FS_LOCATION='mnt/livecd'
552 # Setup the loopback mounts, if unencrypted
554 if [ "${LOOPTYPE}" = 'normal' ]
556 good_msg 'Mounting loop filesystem'
557 mount -t ext2 -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
558 test_success 'Mount filesystem'
559 FS_LOCATION='mnt/livecd'
560 elif [ "${LOOPTYPE}" = 'squashfs' ]
562 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
563 good_msg 'Mounting squashfs filesystem'
564 mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
566 good_msg 'Mounting squashfs & aufs filesystems'
568 test_success 'Mount filesystem'
570 FS_LOCATION='mnt/livecd'
571 elif [ "${LOOPTYPE}" = 'gcloop' ]
573 good_msg 'Mounting gcloop filesystem'
574 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${CDROOT_PATH}/${LOOPEXT}${LOOP}"
575 test_success 'losetup the loop device'
577 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
578 test_success 'Mount the losetup loop device'
579 FS_LOCATION='mnt/livecd'
580 elif [ "${LOOPTYPE}" = 'zisofs' ]
582 FS_LOCATION="${CDROOT_PATH/\/}/${LOOPEXT}${LOOP}"
583 elif [ "${LOOPTYPE}" = 'noloop' ]
585 FS_LOCATION="${CDROOT_PATH/\/}"
586 elif [ "${LOOPTYPE}" = 'sgimips' ]
588 # getdvhoff finds the starting offset (in bytes) of the squashfs
589 # partition on the cdrom and returns this offset for losetup
591 # All currently supported SGI Systems use SCSI CD-ROMs, so
592 # so we know that the CD-ROM is usually going to be /dev/sr0.
594 # We use the value given to losetup to set /dev/loop0 to point
595 # to the liveCD root partition, and then mount /dev/loop0 as
597 good_msg 'Locating the SGI LiveCD Root Partition'
599 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
600 "${NEW_ROOT}${CDROOT_DEV}" \
601 "${NEW_ROOT}${REAL_ROOT}"
602 test_success 'losetup /dev/sr0 /dev/loop0'
604 good_msg 'Mounting the Root Partition'
605 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
606 test_success 'mount /dev/loop0 /'
607 FS_LOCATION='mnt/livecd'
613 # Unpacking additional packages from NFS mount
614 # This is useful for adding kernel modules to /lib
615 # We do this now, so that additional packages can add whereever they want.
616 if [ "${REAL_ROOT}" = '/dev/nfs' ]
618 if [ -e "${CDROOT_PATH}/add" ]
620 for targz in $(ls ${CDROOT_PATH}/add/*.tar.gz)
622 tarname=$(basename ${targz})
623 good_msg "Adding additional package ${tarname}"
624 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
630 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
632 setup_unionfs ${NEW_ROOT} /${FS_LOCATION}
634 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
636 good_msg "Copying read-write image contents to tmpfs"
637 # Copy over stuff that should be writable
638 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
640 # Now we do the links.
641 for x in ${ROOT_LINKS}
643 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
645 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
647 # List all subdirectories of x
648 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
650 # Strip the prefix of the FS_LOCATION
651 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
653 # Skip this directory if we already linked a parent directory
654 if [ "${current_parent}" != '' ]; then
655 var=$(echo "${directory}" | grep "^${current_parent}")
656 if [ "${var}" != '' ]; then
660 # Test if the directory exists already
661 if [ -e "/${NEW_ROOT}/${directory}" ]
663 # It does exist, link all the individual files
664 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
666 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
667 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
671 # It does not exist, make a link to the livecd
672 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
673 current_parent="${directory}"
679 mkdir initramfs proc tmp sys 2>/dev/null
684 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
685 #if [ "${UML}" = 'UML' ]
688 # good_msg 'Updating for uml system'
691 # Let Init scripts know that we booted from CD
695 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
698 mount -t tmpfs tmpfs /union_changes
699 setup_unionfs /union_changes ${NEW_ROOT}
700 mkdir -p ${UNION}/tmp/.initrd
704 # Mount the additional things as required by udev & systemd
705 if [ -f ${NEW_ROOT}/etc/initramfs.mounts ]; then
706 fslist=$(get_mounts_list)
708 # Disabled until the new OpenRC is ready to go.
709 # Otherwise users will get /usr mounted RO, and it will NOT transition to
715 for fs in $fslist; do
716 dev=$(get_mount_device $fs)
717 # In this case, it's probably part of the filesystem
718 # and not a mountpoint
719 [ -z "$dev" ] && continue
720 opts="ro,$(get_mount_options \"$fs\")"
721 if ! mount -o ${opts} $dev ${NEW_ROOT}${fs}; then
722 rescue_shell "Unable to mount $dev on $fs"
726 # Execute script on the cdrom just before boot to update things if necessary
729 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
731 good_msg "Entering ${SUBDIR} to boot"
732 CHROOT="${CHROOT}/${SUBDIR}"
737 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
740 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
741 echo -ne "${BOLD}.${NORMAL}"
743 # If devtmpfs is mounted, try move it to the new root
744 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
745 for fs in /dev /sys /proc
747 if grep -qs "$fs" /proc/mounts
749 if ! mount --move $fs "${CHROOT}"$fs
751 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
756 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
758 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
759 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
761 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
764 echo -e "${BOLD}.${NORMAL}"
766 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
768 # If we get here, something bad has happened
771 echo "A fatal error has probably occured since ${REAL_INIT:-/sbin/init} did not"
772 echo "boot correctly. Trying to open a shell..."