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 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 [ -e /bin/vgscan ] || ln -s /bin/lvm /bin/vgscan
37 [ -e /bin/vgchange ] || ln -s /bin/lvm /bin/vgchange
42 CMDLINE=`cat /proc/cmdline`
43 # Scan CMDLINE for any specified real_root= or cdroot arguments
51 REAL_ROOT=`parse_opt "${x}"`
54 FAKE_ROOT=`parse_opt "${x}"`
57 SUBDIR=`parse_opt "${x}"`
60 REAL_INIT=`parse_opt "${x}"`
63 INIT_OPTS=`parse_opt "${x}"`
71 CDROOT_DEV=`parse_opt "${x}"`
74 CDROOT_TYPE=`parse_opt "${x}"`
76 # Start livecd loop, looptype options
78 LOOP=`parse_opt "${x}"`
81 LOOPTYPE=`parse_opt "${x}"`
84 ISOBOOT=`parse_opt "${x}"`
86 # Start Volume manager options
91 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
101 DMRAID_OPTS=`parse_opt "${x}"`
108 bad_msg 'Using doevms2 is deprecated, use doevms, instead.'
117 SDELAY=`parse_opt "${x}"`
124 MDOLIST=`parse_opt "${x}"`
125 MDOLIST="`echo ${MDOLIST} | sed -e 's/,/ /g'`"
131 MLIST=`parse_opt "${x}"`
132 MLIST="`echo ${MLIST} | sed -e 's/,/ /g'`"
135 # Redirect output to a specific tty
136 CONSOLE\=*|console\=*)
137 CONSOLE=`parse_opt "${x}"`
138 # exec >${CONSOLE} <${CONSOLE} 2>&1
142 RAID_DEVICES="`parse_opt ${x}`"
143 RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
146 MDPART=`parse_opt "${x}"`
150 IP=`parse_opt "${x}"`
153 NFSROOT=`parse_opt "${x}"`
156 iscsi_initiatorname\=*)
157 ISCSI_INITIATORNAME=`parse_opt "${x}"`
160 ISCSI_TARGET=`parse_opt "${x}"`
163 ISCSI_TGPT=`parse_opt "${x}"`
166 ISCSI_ADDRESS=`parse_opt "${x}"`
169 ISCSI_PORT=`parse_opt "${x}"`
172 ISCSI_USERNAME=`parse_opt "${x}"`
175 ISCSI_PASSWORD=`parse_opt "${x}"`
177 iscsi_username_in\=*)
178 ISCSI_USERNAME_IN=`parse_opt "${x}"`
180 iscsi_password_in\=*)
181 ISCSI_PASSWORD_IN=`parse_opt "${x}"`
184 ISCSI_DEBUG=`parse_opt "${x}"`
188 CRYPT_ROOT=`parse_opt "${x}"`
191 CRYPT_SWAP=`parse_opt "${x}"`
194 CRYPT_ROOT_KEY=`parse_opt "${x}"`
197 CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
200 CRYPT_SWAP_KEY=`parse_opt "${x}"`
203 CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
205 real_resume\=*|resume\=*)
206 REAL_RESUME=`parse_opt "${x}"`
215 REAL_ROOTFLAGS=`parse_opt "${x}"`
218 keymap=`parse_opt "${x}"`
221 if [ ! -x /sbin/unionfs ]
224 bad_msg 'unionfs binary not found: aborting use of unionfs!'
233 # if [ ! -x /sbin/unionfs ]
235 # USE_UNIONFS_NORMAL=0
236 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
238 # USE_UNIONFS_NORMAL=1
239 # CMD_UNIONFS=`parse_opt "${x}"`
240 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
243 # UID=`echo ${CMD_UNIONFS#*,}`
244 # UNIONFS=`echo ${CMD_UNIONFS%,*}`
246 # UNIONFS=${CMD_UNIONFS}
253 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
255 REAL_ROOT="${FAKE_ROOT}"
265 # Setup hotplugging for firmware loading
268 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
269 if [ -z "${DO_modules}" ]
271 good_msg 'Skipping module load; disabled via commandline'
272 elif [ -d "/lib/modules/${KV}" ]
274 good_msg 'Loading modules'
275 # Load appropriate kernel modules
276 if [ "${NODETECT}" != '1' ]
278 for modules in ${MY_HWOPTS}
280 modules_scan ${modules}
283 # Always eval doload=...
284 modules_load ${MDOLIST}
286 good_msg 'Skipping module load; no modules in the ramdisk!'
289 # Delay if needed for USB hardware
292 # Start device manager
298 # let iscsid settle - otherwise mounting the iSCSI-disk will fail (very rarely, though)
301 # Setup md device nodes if they dont exist
309 # Initialize LUKS root device except for livecd's
310 if [ "${CDROOT}" != 1 ]
313 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
315 case "${REAL_RESUME}" in
321 if [ ${retval} -ne 0 ]; then
322 RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
326 if [ ${retval} -ne 0 ]; then
327 RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
331 if [ ${retval} -ne 0 ]; then
332 RESUME_DEV=`blkid -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
336 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
337 good_msg "Detected real_resume=${RESUME_DEV}"
338 REAL_RESUME="${RESUME_DEV}"
347 mkdir -p "${NEW_ROOT}"
350 # Run debug shell if requested
353 if [ "${CDROOT}" = '1' ]
355 good_msg "Making tmpfs for ${NEW_ROOT}"
356 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
358 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
360 mkdir -p "${NEW_ROOT}/${i}"
361 chmod 755 "${NEW_ROOT}/${i}"
363 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
364 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
366 # For SGI LiveCDs ...
367 if [ "${LOOPTYPE}" = "sgimips" ]
369 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
370 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
373 # Required for splash to work. Not an issue with the initrd as this
374 # device isn't created there and is not needed.
377 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
380 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
385 if [ "${REAL_ROOT}" = '' ]
387 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
390 while [ ${COUNTER} -lt 3 ]; do
393 let COUNTER=${COUNTER}+1
401 if [ "${REAL_ROOT}" = '' ]
404 umount "${NEW_ROOT}/dev" 2>/dev/null
405 umount "${NEW_ROOT}/sys" 2>/dev/null
406 umount /sys 2>/dev/null
409 rm -rf "${NEW_ROOT}/*"
411 bad_msg 'Could not find CD to boot, something else needed!'
416 # Determine root device
417 good_msg 'Determining root device...'
420 while [ "${got_good_root}" != '1' ]
422 case "${REAL_ROOT}" in
428 if [ ${retval} -ne 0 ]; then
429 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
433 if [ ${retval} -ne 0 ]; then
434 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
438 if [ ${retval} -ne 0 ]; then
439 ROOT_DEV=`blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
443 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
444 good_msg "Detected real_root=${ROOT_DEV}"
445 REAL_ROOT="${ROOT_DEV}"
447 whereis "REAL_ROOT" "root block device"
454 if [ "${REAL_ROOT}" = '' ]
456 # No REAL_ROOT determined/specified. Prompt user for root block device.
457 whereis "REAL_ROOT" "root block device"
460 # Check for a block device or /dev/nfs
461 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
466 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
473 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
475 # CD already mounted; no further checks necessary
477 elif [ "${LOOPTYPE}" = "sgimips" ]
479 # sgimips mounts the livecd root partition directly
480 # there is no isofs filesystem to worry about
483 good_msg "Mounting root..."
485 # Try to mount the device as ${NEW_ROOT}
486 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
489 # mount ro so fsck doesn't barf later
490 if [ "${REAL_ROOTFLAGS}" = '' ]; then
491 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
493 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
494 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
498 # If mount is successful break out of the loop
499 # else not a good root and start over.
502 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
506 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
511 bad_msg "Could not mount specified ROOT, try again"
517 # End determine root device
521 # If CD root is set determine the looptype to boot
522 if [ "${CDROOT}" = '1' ]
524 good_msg 'Determining looptype ...'
527 # Find loop and looptype
528 [ -z "${LOOP}" ] && find_loop
529 [ -z "${LOOPTYPE}" ] && find_looptype
533 # If encrypted, find key and mount, otherwise mount as usual
534 if [ -n "${CRYPT_ROOT}" ]
536 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
537 CRYPT_ROOT='/dev/loop0'
538 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
540 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
541 test_success 'Preparing loop filesystem'
550 MOUNTTYPE="${LOOPTYPE}"
553 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
554 test_success 'Mount filesystem'
555 FS_LOCATION='mnt/livecd'
556 # Setup the loopback mounts, if unencrypted
558 if [ "${LOOPTYPE}" = 'normal' ]
560 good_msg 'Mounting loop filesystem'
561 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
562 test_success 'Mount filesystem'
563 FS_LOCATION='mnt/livecd'
564 elif [ "${LOOPTYPE}" = 'squashfs' ]
566 good_msg 'Mounting squashfs filesystem'
567 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
568 test_success 'Mount filesystem'
569 FS_LOCATION='mnt/livecd'
570 elif [ "${LOOPTYPE}" = 'gcloop' ]
572 good_msg 'Mounting gcloop filesystem'
573 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
574 test_success 'losetup the loop device'
576 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
577 test_success 'Mount the losetup loop device'
578 FS_LOCATION='mnt/livecd'
579 elif [ "${LOOPTYPE}" = 'zisofs' ]
581 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
582 elif [ "${LOOPTYPE}" = 'noloop' ]
584 FS_LOCATION='mnt/cdrom'
585 elif [ "${LOOPTYPE}" = 'sgimips' ]
587 # getdvhoff finds the starting offset (in bytes) of the squashfs
588 # partition on the cdrom and returns this offset for losetup
590 # All currently supported SGI Systems use SCSI CD-ROMs, so
591 # so we know that the CD-ROM is usually going to be /dev/sr0.
593 # We use the value given to losetup to set /dev/loop0 to point
594 # to the liveCD root partition, and then mount /dev/loop0 as
596 good_msg 'Locating the SGI LiveCD Root Partition'
598 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
599 "${NEW_ROOT}${CDROOT_DEV}" \
600 "${NEW_ROOT}${REAL_ROOT}"
601 test_success 'losetup /dev/sr0 /dev/loop0'
603 good_msg 'Mounting the Root Partition'
604 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
605 test_success 'mount /dev/loop0 /'
606 FS_LOCATION='mnt/livecd'
612 # Unpacking additional packages from NFS mount
613 # This is useful for adding kernel modules to /lib
614 # We do this now, so that additional packages can add whereever they want.
615 if [ "${REAL_ROOT}" = '/dev/nfs' ]
617 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
619 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
621 tarname=`basename ${targz}`
622 good_msg "Adding additional package ${tarname}"
623 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
629 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
631 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
635 good_msg "Copying read-write image contents to tmpfs"
636 # Copy over stuff that should be writable
637 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
639 # Now we do the links.
640 for x in ${ROOT_LINKS}
642 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
644 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
646 # List all subdirectories of x
647 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
649 # Strip the prefix of the FS_LOCATION
650 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
652 # Skip this directory if we already linked a parent directory
653 if [ "${current_parent}" != '' ]; then
654 var=`echo "${directory}" | grep "^${current_parent}"`
655 if [ "${var}" != '' ]; then
659 # Test if the directory exists already
660 if [ -e "/${NEW_ROOT}/${directory}" ]
662 # It does exist, link all the individual files
663 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
665 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
666 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
670 # It does not exist, make a link to the livecd
671 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
672 current_parent="${directory}"
678 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
682 mkdir initramfs proc tmp sys 2>/dev/null
687 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
688 #if [ "${UML}" = 'UML' ]
691 # good_msg 'Updating for uml system'
694 # Let Init scripts know that we booted from CD
698 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
703 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
706 mount -t tmpfs tmpfs /union_changes
707 setup_unionfs /union_changes ${NEW_ROOT}
708 mkdir -p ${UNION}/tmp/.initrd
712 # Execute script on the cdrom just before boot to update things if necessary
715 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
717 good_msg "Entering ${SUBDIR} to boot"
718 CHROOT="${CHROOT}/${SUBDIR}"
723 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
724 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
726 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
727 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
729 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
733 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
734 echo -ne "${BOLD}.${NORMAL}"
735 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
736 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
737 echo -e "${BOLD}.${NORMAL}"
739 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
741 # If we get here, something bad has happened
744 echo 'A fatal error has probably occured since /sbin/init did not'
745 echo 'boot correctly. Trying to open a shell...'