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_SWAP_KEY=${x#*=}
196 CRYPT_SWAP_KEYDEV=${x#*=}
198 real_resume=*|resume=*)
208 REAL_ROOTFLAGS=${x#*=}
220 if [ ! -x /sbin/unionfs ]
223 bad_msg 'unionfs binary not found: aborting use of unionfs!'
232 # if [ ! -x /sbin/unionfs ]
234 # USE_UNIONFS_NORMAL=0
235 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
237 # USE_UNIONFS_NORMAL=1
238 # CMD_UNIONFS=${x#*=}
239 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
242 # UID=$(echo ${CMD_UNIONFS#*,})
243 # UNIONFS=$(echo ${CMD_UNIONFS%,*})
245 # UNIONFS=${CMD_UNIONFS}
252 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
254 REAL_ROOT="${FAKE_ROOT}"
264 # Setup hotplugging for firmware loading
267 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
268 if [ -z "${DO_modules}" ]
270 good_msg 'Skipping module load; disabled via commandline'
271 elif [ -d "/lib/modules/${KV}" ]
273 good_msg 'Loading modules'
274 # Load appropriate kernel modules
275 if [ "${NODETECT}" != '1' ]
277 for modules in ${MY_HWOPTS}
279 modules_scan ${modules}
282 # Always eval doload=...
283 modules_load ${MDOLIST}
285 good_msg 'Skipping module load; no modules in the ramdisk!'
288 # Apply scan delay if specified
291 # Setup slow USB bits
294 # Start device manager
297 # if doslowusb is passed, pause other 10 seconds here, after mdev load
298 [ "${DO_slowusb}" ] && sleep 10
301 if [ -e /bin/iscsistart ]
306 # Setup btrfs, see bug 303529
309 # Setup md device nodes if they dont exist
317 # Initialize LUKS root device except for livecd's
318 if [ "${CDROOT}" != 1 ]
321 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
323 case "${REAL_RESUME}" in
329 if [ ${retval} -ne 0 ]; then
330 RESUME_DEV=$(findfs "${REAL_RESUME}" 2>/dev/null)
334 if [ ${retval} -ne 0 ]; then
335 RESUME_DEV=$(busybox findfs "${REAL_RESUME}" 2>/dev/null)
339 if [ ${retval} -ne 0 ]; then
340 RESUME_DEV=$(blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null)
344 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
345 good_msg "Detected real_resume=${RESUME_DEV}"
346 REAL_RESUME="${RESUME_DEV}"
355 mkdir -p "${NEW_ROOT}"
358 # Run debug shell if requested
361 if [ "${CDROOT}" = '1' ]
363 good_msg "Making tmpfs for ${NEW_ROOT}"
364 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
366 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
368 mkdir -p "${NEW_ROOT}/${i}"
369 chmod 755 "${NEW_ROOT}/${i}"
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"
462 if [ "${REAL_ROOT}" = '' ]
464 # No REAL_ROOT determined/specified. Prompt user for root block device.
465 prompt_user "REAL_ROOT" "root block device"
468 # Check for a block device or /dev/nfs
469 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
474 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
481 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
483 # CD already mounted; no further checks necessary
485 elif [ "${LOOPTYPE}" = "sgimips" ]
487 # sgimips mounts the livecd root partition directly
488 # there is no isofs filesystem to worry about
491 good_msg "Mounting root..."
493 # Try to mount the device as ${NEW_ROOT}
494 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
497 # mount ro so fsck doesn't barf later
498 if [ "${REAL_ROOTFLAGS}" = '' ]; then
499 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
500 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
502 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
503 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
507 # If mount is successful break out of the loop
508 # else not a good root and start over.
511 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
515 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
520 bad_msg "Could not mount specified ROOT, try again"
526 # End determine root device
530 # If CD root is set determine the looptype to boot
531 if [ "${CDROOT}" = '1' ]
533 good_msg 'Determining looptype ...'
536 # Find loop and looptype
537 [ -z "${LOOP}" ] && find_loop
538 [ -z "${LOOPTYPE}" ] && find_looptype
542 # If encrypted, find key and mount, otherwise mount as usual
543 if [ -n "${CRYPT_ROOT}" ]
545 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
546 CRYPT_ROOT='/dev/loop0'
547 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
549 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
550 test_success 'Preparing loop filesystem'
559 MOUNTTYPE="${LOOPTYPE}"
562 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
563 test_success 'Mount filesystem'
564 FS_LOCATION='mnt/livecd'
565 # Setup the loopback mounts, if unencrypted
567 if [ "${LOOPTYPE}" = 'normal' ]
569 good_msg 'Mounting loop filesystem'
570 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
571 test_success 'Mount filesystem'
572 FS_LOCATION='mnt/livecd'
573 elif [ "${LOOPTYPE}" = 'squashfs' ]
575 if [ "${USE_AUFS_NORMAL}" != '1' ]; then
576 good_msg 'Mounting squashfs filesystem'
577 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
579 good_msg 'Mounting squashfs & aufs filesystems'
581 test_success 'Mount filesystem'
583 FS_LOCATION='mnt/livecd'
584 elif [ "${LOOPTYPE}" = 'gcloop' ]
586 good_msg 'Mounting gcloop filesystem'
587 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
588 test_success 'losetup the loop device'
590 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
591 test_success 'Mount the losetup loop device'
592 FS_LOCATION='mnt/livecd'
593 elif [ "${LOOPTYPE}" = 'zisofs' ]
595 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
596 elif [ "${LOOPTYPE}" = 'noloop' ]
598 FS_LOCATION='mnt/cdrom'
599 elif [ "${LOOPTYPE}" = 'sgimips' ]
601 # getdvhoff finds the starting offset (in bytes) of the squashfs
602 # partition on the cdrom and returns this offset for losetup
604 # All currently supported SGI Systems use SCSI CD-ROMs, so
605 # so we know that the CD-ROM is usually going to be /dev/sr0.
607 # We use the value given to losetup to set /dev/loop0 to point
608 # to the liveCD root partition, and then mount /dev/loop0 as
610 good_msg 'Locating the SGI LiveCD Root Partition'
612 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
613 "${NEW_ROOT}${CDROOT_DEV}" \
614 "${NEW_ROOT}${REAL_ROOT}"
615 test_success 'losetup /dev/sr0 /dev/loop0'
617 good_msg 'Mounting the Root Partition'
618 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
619 test_success 'mount /dev/loop0 /'
620 FS_LOCATION='mnt/livecd'
626 # Unpacking additional packages from NFS mount
627 # This is useful for adding kernel modules to /lib
628 # We do this now, so that additional packages can add whereever they want.
629 if [ "${REAL_ROOT}" = '/dev/nfs' ]
631 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
633 for targz in $(ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz)
635 tarname=$(basename ${targz})
636 good_msg "Adding additional package ${tarname}"
637 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
643 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
645 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
647 elif [ "${USE_AUFS_NORMAL}" != '1' ]; then
649 good_msg "Copying read-write image contents to tmpfs"
650 # Copy over stuff that should be writable
651 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
653 # Now we do the links.
654 for x in ${ROOT_LINKS}
656 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
658 ln -s "$(readlink ${NEW_ROOT}/${FS_LOCATION}/${x})" "${x}" 2>/dev/null
660 # List all subdirectories of x
661 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
663 # Strip the prefix of the FS_LOCATION
664 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
666 # Skip this directory if we already linked a parent directory
667 if [ "${current_parent}" != '' ]; then
668 var=$(echo "${directory}" | grep "^${current_parent}")
669 if [ "${var}" != '' ]; then
673 # Test if the directory exists already
674 if [ -e "/${NEW_ROOT}/${directory}" ]
676 # It does exist, link all the individual files
677 for file in $(ls /${NEW_ROOT}/${FS_LOCATION}/${directory})
679 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
680 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
684 # It does not exist, make a link to the livecd
685 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
686 current_parent="${directory}"
692 mkdir initramfs proc tmp sys 2>/dev/null
697 #UML=$(cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||')
698 #if [ "${UML}" = 'UML' ]
701 # good_msg 'Updating for uml system'
704 # Let Init scripts know that we booted from CD
708 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
711 mount -t tmpfs tmpfs /union_changes
712 setup_unionfs /union_changes ${NEW_ROOT}
713 mkdir -p ${UNION}/tmp/.initrd
717 # Execute script on the cdrom just before boot to update things if necessary
720 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
722 good_msg "Entering ${SUBDIR} to boot"
723 CHROOT="${CHROOT}/${SUBDIR}"
728 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
731 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
732 echo -ne "${BOLD}.${NORMAL}"
734 # If devtmpfs is mounted, try move it to the new root
735 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
736 for fs in /dev /sys /proc
738 if grep -qs "$fs" /proc/mounts
740 if ! mount --move $fs "${CHROOT}"$fs
742 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
747 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
749 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
750 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
752 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
755 echo -e "${BOLD}.${NORMAL}"
757 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
759 # If we get here, something bad has happened
762 echo 'A fatal error has probably occured since /sbin/init did not'
763 echo 'boot correctly. Trying to open a shell...'