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'`"
143 MDPART=`parse_opt "${x}"`
147 IP=`parse_opt "${x}"`
150 NFSROOT=`parse_opt "${x}"`
153 iscsi_initiatorname\=*)
154 ISCSI_INITIATORNAME=`parse_opt "${x}"`
157 ISCSI_TARGET=`parse_opt "${x}"`
160 ISCSI_TGPT=`parse_opt "${x}"`
163 ISCSI_ADDRESS=`parse_opt "${x}"`
166 ISCSI_PORT=`parse_opt "${x}"`
169 ISCSI_USERNAME=`parse_opt "${x}"`
172 ISCSI_PASSWORD=`parse_opt "${x}"`
174 iscsi_username_in\=*)
175 ISCSI_USERNAME_IN=`parse_opt "${x}"`
177 iscsi_password_in\=*)
178 ISCSI_PASSWORD_IN=`parse_opt "${x}"`
181 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 ROOTFSTYPE=`parse_opt "${x}"`
221 keymap=`parse_opt "${x}"`
224 if [ ! -x /sbin/unionfs ]
227 bad_msg 'unionfs binary not found: aborting use of unionfs!'
236 # if [ ! -x /sbin/unionfs ]
238 # USE_UNIONFS_NORMAL=0
239 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
241 # USE_UNIONFS_NORMAL=1
242 # CMD_UNIONFS=`parse_opt "${x}"`
243 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
246 # UID=`echo ${CMD_UNIONFS#*,}`
247 # UNIONFS=`echo ${CMD_UNIONFS%,*}`
249 # UNIONFS=${CMD_UNIONFS}
256 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
258 REAL_ROOT="${FAKE_ROOT}"
268 # Setup hotplugging for firmware loading
271 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
272 if [ -z "${DO_modules}" ]
274 good_msg 'Skipping module load; disabled via commandline'
275 elif [ -d "/lib/modules/${KV}" ]
277 good_msg 'Loading modules'
278 # Load appropriate kernel modules
279 if [ "${NODETECT}" != '1' ]
281 for modules in ${MY_HWOPTS}
283 modules_scan ${modules}
286 # Always eval doload=...
287 modules_load ${MDOLIST}
289 good_msg 'Skipping module load; no modules in the ramdisk!'
292 # Apply scan delay if specified
295 # Setup slow USB bits
298 # Start device manager
301 # if doslowusb is passed, pause other 10 seconds here, after mdev load
302 [ "${DO_slowusb}" ] && sleep 10
305 if [ -e /bin/iscsistart ]
310 # Setup btrfs, see bug 303529
313 # Setup md device nodes if they dont exist
321 # Initialize LUKS root device except for livecd's
322 if [ "${CDROOT}" != 1 ]
325 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
327 case "${REAL_RESUME}" in
333 if [ ${retval} -ne 0 ]; then
334 RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
338 if [ ${retval} -ne 0 ]; then
339 RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
343 if [ ${retval} -ne 0 ]; then
344 RESUME_DEV=`blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
348 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
349 good_msg "Detected real_resume=${RESUME_DEV}"
350 REAL_RESUME="${RESUME_DEV}"
359 mkdir -p "${NEW_ROOT}"
362 # Run debug shell if requested
365 if [ "${CDROOT}" = '1' ]
367 good_msg "Making tmpfs for ${NEW_ROOT}"
368 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
370 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
372 mkdir -p "${NEW_ROOT}/${i}"
373 chmod 755 "${NEW_ROOT}/${i}"
375 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
376 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
378 # For SGI LiveCDs ...
379 if [ "${LOOPTYPE}" = "sgimips" ]
381 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
382 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
385 # Required for splash to work. Not an issue with the initrd as this
386 # device isn't created there and is not needed.
389 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
392 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
397 if [ "${REAL_ROOT}" = '' ]
399 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
402 while [ ${COUNTER} -lt 3 ]; do
405 let COUNTER=${COUNTER}+1
413 if [ "${REAL_ROOT}" = '' ]
416 umount "${NEW_ROOT}/dev" 2>/dev/null
417 umount "${NEW_ROOT}/sys" 2>/dev/null
418 umount /sys 2>/dev/null
421 rm -rf "${NEW_ROOT}/*"
423 bad_msg 'Could not find CD to boot, something else needed!'
428 # Determine root device
429 good_msg 'Determining root device...'
432 while [ "${got_good_root}" != '1' ]
434 case "${REAL_ROOT}" in
440 if [ ${retval} -ne 0 ]; then
441 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
445 if [ ${retval} -ne 0 ]; then
446 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
450 if [ ${retval} -ne 0 ]; then
451 ROOT_DEV=`blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
455 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
456 good_msg "Detected real_root=${ROOT_DEV}"
457 REAL_ROOT="${ROOT_DEV}"
459 prompt_user "REAL_ROOT" "root block device"
466 if [ "${REAL_ROOT}" = '' ]
468 # No REAL_ROOT determined/specified. Prompt user for root block device.
469 prompt_user "REAL_ROOT" "root block device"
472 # Check for a block device or /dev/nfs
473 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
478 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
485 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
487 # CD already mounted; no further checks necessary
489 elif [ "${LOOPTYPE}" = "sgimips" ]
491 # sgimips mounts the livecd root partition directly
492 # there is no isofs filesystem to worry about
495 good_msg "Mounting root..."
497 # Try to mount the device as ${NEW_ROOT}
498 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
501 # mount ro so fsck doesn't barf later
502 if [ "${REAL_ROOTFLAGS}" = '' ]; then
503 good_msg "Using mount -t ${ROOTFSTYPE} -o ro"
504 mount -t ${ROOTFSTYPE} -o ro ${REAL_ROOT} ${NEW_ROOT}
506 good_msg "Using mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS}"
507 mount -t ${ROOTFSTYPE} -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
511 # If mount is successful break out of the loop
512 # else not a good root and start over.
515 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
519 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
524 bad_msg "Could not mount specified ROOT, try again"
530 # End determine root device
534 # If CD root is set determine the looptype to boot
535 if [ "${CDROOT}" = '1' ]
537 good_msg 'Determining looptype ...'
540 # Find loop and looptype
541 [ -z "${LOOP}" ] && find_loop
542 [ -z "${LOOPTYPE}" ] && find_looptype
546 # If encrypted, find key and mount, otherwise mount as usual
547 if [ -n "${CRYPT_ROOT}" ]
549 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
550 CRYPT_ROOT='/dev/loop0'
551 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
553 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
554 test_success 'Preparing loop filesystem'
563 MOUNTTYPE="${LOOPTYPE}"
566 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
567 test_success 'Mount filesystem'
568 FS_LOCATION='mnt/livecd'
569 # Setup the loopback mounts, if unencrypted
571 if [ "${LOOPTYPE}" = 'normal' ]
573 good_msg 'Mounting loop filesystem'
574 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
575 test_success 'Mount filesystem'
576 FS_LOCATION='mnt/livecd'
577 elif [ "${LOOPTYPE}" = 'squashfs' ]
579 good_msg 'Mounting squashfs filesystem'
580 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
581 test_success 'Mount filesystem'
582 FS_LOCATION='mnt/livecd'
583 elif [ "${LOOPTYPE}" = 'gcloop' ]
585 good_msg 'Mounting gcloop filesystem'
586 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
587 test_success 'losetup the loop device'
589 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
590 test_success 'Mount the losetup loop device'
591 FS_LOCATION='mnt/livecd'
592 elif [ "${LOOPTYPE}" = 'zisofs' ]
594 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
595 elif [ "${LOOPTYPE}" = 'noloop' ]
597 FS_LOCATION='mnt/cdrom'
598 elif [ "${LOOPTYPE}" = 'sgimips' ]
600 # getdvhoff finds the starting offset (in bytes) of the squashfs
601 # partition on the cdrom and returns this offset for losetup
603 # All currently supported SGI Systems use SCSI CD-ROMs, so
604 # so we know that the CD-ROM is usually going to be /dev/sr0.
606 # We use the value given to losetup to set /dev/loop0 to point
607 # to the liveCD root partition, and then mount /dev/loop0 as
609 good_msg 'Locating the SGI LiveCD Root Partition'
611 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
612 "${NEW_ROOT}${CDROOT_DEV}" \
613 "${NEW_ROOT}${REAL_ROOT}"
614 test_success 'losetup /dev/sr0 /dev/loop0'
616 good_msg 'Mounting the Root Partition'
617 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
618 test_success 'mount /dev/loop0 /'
619 FS_LOCATION='mnt/livecd'
625 # Unpacking additional packages from NFS mount
626 # This is useful for adding kernel modules to /lib
627 # We do this now, so that additional packages can add whereever they want.
628 if [ "${REAL_ROOT}" = '/dev/nfs' ]
630 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
632 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
634 tarname=`basename ${targz}`
635 good_msg "Adding additional package ${tarname}"
636 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
642 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
644 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
648 good_msg "Copying read-write image contents to tmpfs"
649 # Copy over stuff that should be writable
650 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
652 # Now we do the links.
653 for x in ${ROOT_LINKS}
655 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
657 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
659 # List all subdirectories of x
660 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
662 # Strip the prefix of the FS_LOCATION
663 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
665 # Skip this directory if we already linked a parent directory
666 if [ "${current_parent}" != '' ]; then
667 var=`echo "${directory}" | grep "^${current_parent}"`
668 if [ "${var}" != '' ]; then
672 # Test if the directory exists already
673 if [ -e "/${NEW_ROOT}/${directory}" ]
675 # It does exist, link all the individual files
676 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
678 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
679 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
683 # It does not exist, make a link to the livecd
684 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
685 current_parent="${directory}"
691 mkdir initramfs proc tmp sys 2>/dev/null
696 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
697 #if [ "${UML}" = 'UML' ]
700 # good_msg 'Updating for uml system'
703 # Let Init scripts know that we booted from CD
707 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
710 mount -t tmpfs tmpfs /union_changes
711 setup_unionfs /union_changes ${NEW_ROOT}
712 mkdir -p ${UNION}/tmp/.initrd
716 # Execute script on the cdrom just before boot to update things if necessary
719 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
721 good_msg "Entering ${SUBDIR} to boot"
722 CHROOT="${CHROOT}/${SUBDIR}"
727 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
728 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
730 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
731 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
733 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
737 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
738 echo -ne "${BOLD}.${NORMAL}"
740 # If devtmpfs is mounted, try move it to the new root
741 # If that fails, try to unmount all possible mounts of devtmpfs as stuff breaks otherwise
742 for fs in /dev /sys /proc
744 if grep -qs "$fs" /proc/mounts
746 if ! mount --move $fs "${CHROOT}"$fs
748 umount $fs || echo '*: Failed to move and unmount the ramdisk $fs!'
753 echo -e "${BOLD}.${NORMAL}"
755 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
757 # If we get here, something bad has happened
760 echo 'A fatal error has probably occured since /sbin/init did not'
761 echo 'boot correctly. Trying to open a shell...'