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
46 REAL_ROOT=`parse_opt "${x}"`
49 FAKE_ROOT=`parse_opt "${x}"`
52 SUBDIR=`parse_opt "${x}"`
55 REAL_INIT=`parse_opt "${x}"`
58 INIT_OPTS=`parse_opt "${x}"`
66 CDROOT_DEV=`parse_opt "${x}"`
69 CDROOT_TYPE=`parse_opt "${x}"`
71 # Start livecd loop, looptype options
73 LOOP=`parse_opt "${x}"`
76 LOOPTYPE=`parse_opt "${x}"`
79 ISOBOOT=`parse_opt "${x}"`
81 # Start Volume manager options
86 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
96 DMRAID_OPTS=`parse_opt "${x}"`
103 bad_msg 'Using doevms2 is deprecated, use doevms, instead.'
112 SDELAY=`parse_opt "${x}"`
119 MDOLIST=`parse_opt "${x}"`
120 MDOLIST="`echo ${MDOLIST} | sed -e 's/,/ /g'`"
126 MLIST=`parse_opt "${x}"`
127 MLIST="`echo ${MLIST} | sed -e 's/,/ /g'`"
130 # Redirect output to a specific tty
131 CONSOLE\=*|console\=*)
132 CONSOLE=`parse_opt "${x}"`
133 CONSOLE=`basename ${CONSOLE}`
134 # exec >${CONSOLE} <${CONSOLE} 2>&1
138 RAID_DEVICES="`parse_opt ${x}`"
139 RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
142 MDPART=`parse_opt "${x}"`
146 IP=`parse_opt "${x}"`
149 NFSROOT=`parse_opt "${x}"`
152 iscsi_initiatorname\=*)
153 ISCSI_INITIATORNAME=`parse_opt "${x}"`
156 ISCSI_TARGET=`parse_opt "${x}"`
159 ISCSI_TGPT=`parse_opt "${x}"`
162 ISCSI_ADDRESS=`parse_opt "${x}"`
165 ISCSI_PORT=`parse_opt "${x}"`
168 ISCSI_USERNAME=`parse_opt "${x}"`
171 ISCSI_PASSWORD=`parse_opt "${x}"`
173 iscsi_username_in\=*)
174 ISCSI_USERNAME_IN=`parse_opt "${x}"`
176 iscsi_password_in\=*)
177 ISCSI_PASSWORD_IN=`parse_opt "${x}"`
180 ISCSI_DEBUG=`parse_opt "${x}"`
187 CRYPT_ROOT=`parse_opt "${x}"`
190 CRYPT_SWAP=`parse_opt "${x}"`
193 CRYPT_ROOT_KEY=`parse_opt "${x}"`
196 CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
199 CRYPT_SWAP_KEY=`parse_opt "${x}"`
202 CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
204 real_resume\=*|resume\=*)
205 REAL_RESUME=`parse_opt "${x}"`
214 REAL_ROOTFLAGS=`parse_opt "${x}"`
217 ROOTFSTYPE=`parse_opt "${x}"`
220 keymap=`parse_opt "${x}"`
223 if [ ! -x /sbin/unionfs ]
226 bad_msg 'unionfs binary not found: aborting use of unionfs!'
235 # if [ ! -x /sbin/unionfs ]
237 # USE_UNIONFS_NORMAL=0
238 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
240 # USE_UNIONFS_NORMAL=1
241 # CMD_UNIONFS=`parse_opt "${x}"`
242 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
245 # UID=`echo ${CMD_UNIONFS#*,}`
246 # UNIONFS=`echo ${CMD_UNIONFS%,*}`
248 # UNIONFS=${CMD_UNIONFS}
255 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
257 REAL_ROOT="${FAKE_ROOT}"
267 # Setup hotplugging for firmware loading
270 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
271 if [ -z "${DO_modules}" ]
273 good_msg 'Skipping module load; disabled via commandline'
274 elif [ -d "/lib/modules/${KV}" ]
276 good_msg 'Loading modules'
277 # Load appropriate kernel modules
278 if [ "${NODETECT}" != '1' ]
280 for modules in ${MY_HWOPTS}
282 modules_scan ${modules}
285 # Always eval doload=...
286 modules_load ${MDOLIST}
288 good_msg 'Skipping module load; no modules in the ramdisk!'
291 # Apply scan delay if specified
294 # Setup slow USB bits
297 # Start device manager
300 # if doslowusb is passed, pause other 10 seconds here, after mdev load
301 [ "${DO_slowusb}" ] && sleep 10
304 if [ -e /bin/iscsistart ]
309 # Setup btrfs, see bug 303529
312 # Setup md device nodes if they dont exist
320 # Initialize LUKS root device except for livecd's
321 if [ "${CDROOT}" != 1 ]
324 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
326 case "${REAL_RESUME}" in
332 if [ ${retval} -ne 0 ]; then
333 RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
337 if [ ${retval} -ne 0 ]; then
338 RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
342 if [ ${retval} -ne 0 ]; then
343 RESUME_DEV=`blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
347 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
348 good_msg "Detected real_resume=${RESUME_DEV}"
349 REAL_RESUME="${RESUME_DEV}"
358 mkdir -p "${NEW_ROOT}"
361 # Run debug shell if requested
364 if [ "${CDROOT}" = '1' ]
366 good_msg "Making tmpfs for ${NEW_ROOT}"
367 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
369 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
371 mkdir -p "${NEW_ROOT}/${i}"
372 chmod 755 "${NEW_ROOT}/${i}"
374 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
375 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
377 # For SGI LiveCDs ...
378 if [ "${LOOPTYPE}" = "sgimips" ]
380 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
381 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
384 # Required for splash to work. Not an issue with the initrd as this
385 # device isn't created there and is not needed.
388 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
391 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
396 if [ "${REAL_ROOT}" = '' ]
398 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
401 while [ ${COUNTER} -lt 3 ]; do
404 let COUNTER=${COUNTER}+1
412 if [ "${REAL_ROOT}" = '' ]
415 umount "${NEW_ROOT}/dev" 2>/dev/null
416 umount "${NEW_ROOT}/sys" 2>/dev/null
417 umount /sys 2>/dev/null
420 rm -rf "${NEW_ROOT}/*"
422 bad_msg 'Could not find CD to boot, something else needed!'
427 # Determine root device
428 good_msg 'Determining root device...'
431 while [ "${got_good_root}" != '1' ]
433 case "${REAL_ROOT}" in
439 if [ ${retval} -ne 0 ]; then
440 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
444 if [ ${retval} -ne 0 ]; then
445 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
449 if [ ${retval} -ne 0 ]; then
450 ROOT_DEV=`blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
454 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
455 good_msg "Detected real_root=${ROOT_DEV}"
456 REAL_ROOT="${ROOT_DEV}"
458 prompt_user "REAL_ROOT" "root block device"
465 if [ "${REAL_ROOT}" = '' ]
467 # No REAL_ROOT determined/specified. Prompt user for root block device.
468 prompt_user "REAL_ROOT" "root block device"
471 # Check for a block device or /dev/nfs
472 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
477 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
484 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
486 # CD already mounted; no further checks necessary
488 elif [ "${LOOPTYPE}" = "sgimips" ]
490 # sgimips mounts the livecd root partition directly
491 # there is no isofs filesystem to worry about
494 good_msg "Mounting root..."
496 # Try to mount the device as ${NEW_ROOT}
497 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
500 # mount ro so fsck doesn't barf later
501 if [ "${REAL_ROOTFLAGS}" = '' ]; then
502 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
503 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
505 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
506 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
510 # If mount is successful break out of the loop
511 # else not a good root and start over.
514 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
518 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
523 bad_msg "Could not mount specified ROOT, try again"
529 # End determine root device
533 # If CD root is set determine the looptype to boot
534 if [ "${CDROOT}" = '1' ]
536 good_msg 'Determining looptype ...'
539 # Find loop and looptype
540 [ -z "${LOOP}" ] && find_loop
541 [ -z "${LOOPTYPE}" ] && find_looptype
545 # If encrypted, find key and mount, otherwise mount as usual
546 if [ -n "${CRYPT_ROOT}" ]
548 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
549 CRYPT_ROOT='/dev/loop0'
550 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
552 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
553 test_success 'Preparing loop filesystem'
562 MOUNTTYPE="${LOOPTYPE}"
565 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
566 test_success 'Mount filesystem'
567 FS_LOCATION='mnt/livecd'
568 # Setup the loopback mounts, if unencrypted
570 if [ "${LOOPTYPE}" = 'normal' ]
572 good_msg 'Mounting loop filesystem'
573 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
574 test_success 'Mount filesystem'
575 FS_LOCATION='mnt/livecd'
576 elif [ "${LOOPTYPE}" = 'squashfs' ]
578 good_msg 'Mounting squashfs filesystem'
579 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
580 test_success 'Mount filesystem'
581 FS_LOCATION='mnt/livecd'
582 elif [ "${LOOPTYPE}" = 'gcloop' ]
584 good_msg 'Mounting gcloop filesystem'
585 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
586 test_success 'losetup the loop device'
588 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
589 test_success 'Mount the losetup loop device'
590 FS_LOCATION='mnt/livecd'
591 elif [ "${LOOPTYPE}" = 'zisofs' ]
593 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
594 elif [ "${LOOPTYPE}" = 'noloop' ]
596 FS_LOCATION='mnt/cdrom'
597 elif [ "${LOOPTYPE}" = 'sgimips' ]
599 # getdvhoff finds the starting offset (in bytes) of the squashfs
600 # partition on the cdrom and returns this offset for losetup
602 # All currently supported SGI Systems use SCSI CD-ROMs, so
603 # so we know that the CD-ROM is usually going to be /dev/sr0.
605 # We use the value given to losetup to set /dev/loop0 to point
606 # to the liveCD root partition, and then mount /dev/loop0 as
608 good_msg 'Locating the SGI LiveCD Root Partition'
610 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
611 "${NEW_ROOT}${CDROOT_DEV}" \
612 "${NEW_ROOT}${REAL_ROOT}"
613 test_success 'losetup /dev/sr0 /dev/loop0'
615 good_msg 'Mounting the Root Partition'
616 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
617 test_success 'mount /dev/loop0 /'
618 FS_LOCATION='mnt/livecd'
624 # Unpacking additional packages from NFS mount
625 # This is useful for adding kernel modules to /lib
626 # We do this now, so that additional packages can add whereever they want.
627 if [ "${REAL_ROOT}" = '/dev/nfs' ]
629 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
631 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
633 tarname=`basename ${targz}`
634 good_msg "Adding additional package ${tarname}"
635 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
641 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
643 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
647 good_msg "Copying read-write image contents to tmpfs"
648 # Copy over stuff that should be writable
649 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
651 # Now we do the links.
652 for x in ${ROOT_LINKS}
654 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
656 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
658 # List all subdirectories of x
659 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
661 # Strip the prefix of the FS_LOCATION
662 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
664 # Skip this directory if we already linked a parent directory
665 if [ "${current_parent}" != '' ]; then
666 var=`echo "${directory}" | grep "^${current_parent}"`
667 if [ "${var}" != '' ]; then
671 # Test if the directory exists already
672 if [ -e "/${NEW_ROOT}/${directory}" ]
674 # It does exist, link all the individual files
675 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
677 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
678 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
682 # It does not exist, make a link to the livecd
683 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
684 current_parent="${directory}"
690 mkdir initramfs proc tmp sys 2>/dev/null
695 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
696 #if [ "${UML}" = 'UML' ]
699 # good_msg 'Updating for uml system'
702 # Let Init scripts know that we booted from CD
706 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
709 mount -t tmpfs tmpfs /union_changes
710 setup_unionfs /union_changes ${NEW_ROOT}
711 mkdir -p ${UNION}/tmp/.initrd
715 # Execute script on the cdrom just before boot to update things if necessary
718 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
720 good_msg "Entering ${SUBDIR} to boot"
721 CHROOT="${CHROOT}/${SUBDIR}"
726 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
727 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
729 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
730 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
732 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
736 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
737 echo -ne "${BOLD}.${NORMAL}"
739 # If devtmpfs is mounted, try move it to the new root
740 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
741 for fs in /dev /sys /proc
743 if grep -qs "$fs" /proc/mounts
745 if ! mount --move $fs "${CHROOT}"$fs
747 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
752 echo -e "${BOLD}.${NORMAL}"
754 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
756 # If we get here, something bad has happened
759 echo 'A fatal error has probably occured since /sbin/init did not'
760 echo 'boot correctly. Trying to open a shell...'