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 CONSOLE=`basename ${CONSOLE}`
139 # exec >${CONSOLE} <${CONSOLE} 2>&1
143 RAID_DEVICES="`parse_opt ${x}`"
144 RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
147 MDPART=`parse_opt "${x}"`
151 IP=`parse_opt "${x}"`
154 NFSROOT=`parse_opt "${x}"`
157 iscsi_initiatorname\=*)
158 ISCSI_INITIATORNAME=`parse_opt "${x}"`
161 ISCSI_TARGET=`parse_opt "${x}"`
164 ISCSI_TGPT=`parse_opt "${x}"`
167 ISCSI_ADDRESS=`parse_opt "${x}"`
170 ISCSI_PORT=`parse_opt "${x}"`
173 ISCSI_USERNAME=`parse_opt "${x}"`
176 ISCSI_PASSWORD=`parse_opt "${x}"`
178 iscsi_username_in\=*)
179 ISCSI_USERNAME_IN=`parse_opt "${x}"`
181 iscsi_password_in\=*)
182 ISCSI_PASSWORD_IN=`parse_opt "${x}"`
185 ISCSI_DEBUG=`parse_opt "${x}"`
189 CRYPT_ROOT=`parse_opt "${x}"`
192 CRYPT_SWAP=`parse_opt "${x}"`
195 CRYPT_ROOT_KEY=`parse_opt "${x}"`
198 CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
201 CRYPT_SWAP_KEY=`parse_opt "${x}"`
204 CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
206 real_resume\=*|resume\=*)
207 REAL_RESUME=`parse_opt "${x}"`
216 REAL_ROOTFLAGS=`parse_opt "${x}"`
219 keymap=`parse_opt "${x}"`
222 if [ ! -x /sbin/unionfs ]
225 bad_msg 'unionfs binary not found: aborting use of unionfs!'
234 # if [ ! -x /sbin/unionfs ]
236 # USE_UNIONFS_NORMAL=0
237 # bad_msg 'unionfs binary not found: aborting use of unionfs!'
239 # USE_UNIONFS_NORMAL=1
240 # CMD_UNIONFS=`parse_opt "${x}"`
241 # echo ${CMD_UNIONFS}|grep , >/dev/null 2>&1
244 # UID=`echo ${CMD_UNIONFS#*,}`
245 # UNIONFS=`echo ${CMD_UNIONFS%,*}`
247 # UNIONFS=${CMD_UNIONFS}
254 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" = '0' \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
256 REAL_ROOT="${FAKE_ROOT}"
266 # Setup hotplugging for firmware loading
269 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
270 if [ -z "${DO_modules}" ]
272 good_msg 'Skipping module load; disabled via commandline'
273 elif [ -d "/lib/modules/${KV}" ]
275 good_msg 'Loading modules'
276 # Load appropriate kernel modules
277 if [ "${NODETECT}" != '1' ]
279 for modules in ${MY_HWOPTS}
281 modules_scan ${modules}
284 # Always eval doload=...
285 modules_load ${MDOLIST}
287 good_msg 'Skipping module load; no modules in the ramdisk!'
290 # Apply scan delay if specified
293 # Setup slow USB bits
296 # Start device manager
299 # if doslowusb is passed, pause other 10 seconds here, after mdev load
300 [ "${DO_slowusb}" ] && sleep 10
305 # Setup btrfs, see bug 303529
308 # Setup md device nodes if they dont exist
316 # Initialize LUKS root device except for livecd's
317 if [ "${CDROOT}" != 1 ]
320 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
322 case "${REAL_RESUME}" in
328 if [ ${retval} -ne 0 ]; then
329 RESUME_DEV=`findfs "${REAL_RESUME}" 2>/dev/null`
333 if [ ${retval} -ne 0 ]; then
334 RESUME_DEV=`busybox findfs "${REAL_RESUME}" 2>/dev/null`
338 if [ ${retval} -ne 0 ]; then
339 RESUME_DEV=`blkid -l -t "${REAL_RESUME}" | cut -d ":" -f 1 2>/dev/null`
343 if [ ${retval} -eq 0 ] && [ -n "${RESUME_DEV}" ]; then
344 good_msg "Detected real_resume=${RESUME_DEV}"
345 REAL_RESUME="${RESUME_DEV}"
354 mkdir -p "${NEW_ROOT}"
357 # Run debug shell if requested
360 if [ "${CDROOT}" = '1' ]
362 good_msg "Making tmpfs for ${NEW_ROOT}"
363 mount -n -t tmpfs tmpfs "${NEW_ROOT}"
365 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
367 mkdir -p "${NEW_ROOT}/${i}"
368 chmod 755 "${NEW_ROOT}/${i}"
370 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
371 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
373 # For SGI LiveCDs ...
374 if [ "${LOOPTYPE}" = "sgimips" ]
376 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
377 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
380 # Required for splash to work. Not an issue with the initrd as this
381 # device isn't created there and is not needed.
384 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
387 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
392 if [ "${REAL_ROOT}" = '' ]
394 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
397 while [ ${COUNTER} -lt 3 ]; do
400 let COUNTER=${COUNTER}+1
408 if [ "${REAL_ROOT}" = '' ]
411 umount "${NEW_ROOT}/dev" 2>/dev/null
412 umount "${NEW_ROOT}/sys" 2>/dev/null
413 umount /sys 2>/dev/null
416 rm -rf "${NEW_ROOT}/*"
418 bad_msg 'Could not find CD to boot, something else needed!'
423 # Determine root device
424 good_msg 'Determining root device...'
427 while [ "${got_good_root}" != '1' ]
429 case "${REAL_ROOT}" in
435 if [ ${retval} -ne 0 ]; then
436 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
440 if [ ${retval} -ne 0 ]; then
441 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
445 if [ ${retval} -ne 0 ]; then
446 ROOT_DEV=`blkid -l -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
450 if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
451 good_msg "Detected real_root=${ROOT_DEV}"
452 REAL_ROOT="${ROOT_DEV}"
454 whereis "REAL_ROOT" "root block device"
461 if [ "${REAL_ROOT}" = '' ]
463 # No REAL_ROOT determined/specified. Prompt user for root block device.
464 whereis "REAL_ROOT" "root block device"
467 # Check for a block device or /dev/nfs
468 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
473 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
480 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
482 # CD already mounted; no further checks necessary
484 elif [ "${LOOPTYPE}" = "sgimips" ]
486 # sgimips mounts the livecd root partition directly
487 # there is no isofs filesystem to worry about
490 good_msg "Mounting root..."
492 # Try to mount the device as ${NEW_ROOT}
493 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
496 # mount ro so fsck doesn't barf later
497 if [ "${REAL_ROOTFLAGS}" = '' ]; then
498 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
500 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
501 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
505 # If mount is successful break out of the loop
506 # else not a good root and start over.
509 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
513 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
518 bad_msg "Could not mount specified ROOT, try again"
524 # End determine root device
528 # If CD root is set determine the looptype to boot
529 if [ "${CDROOT}" = '1' ]
531 good_msg 'Determining looptype ...'
534 # Find loop and looptype
535 [ -z "${LOOP}" ] && find_loop
536 [ -z "${LOOPTYPE}" ] && find_looptype
540 # If encrypted, find key and mount, otherwise mount as usual
541 if [ -n "${CRYPT_ROOT}" ]
543 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
544 CRYPT_ROOT='/dev/loop0'
545 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
547 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
548 test_success 'Preparing loop filesystem'
557 MOUNTTYPE="${LOOPTYPE}"
560 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
561 test_success 'Mount filesystem'
562 FS_LOCATION='mnt/livecd'
563 # Setup the loopback mounts, if unencrypted
565 if [ "${LOOPTYPE}" = 'normal' ]
567 good_msg 'Mounting loop filesystem'
568 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
569 test_success 'Mount filesystem'
570 FS_LOCATION='mnt/livecd'
571 elif [ "${LOOPTYPE}" = 'squashfs' ]
573 good_msg 'Mounting squashfs filesystem'
574 mount -t squashfs -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}" = 'gcloop' ]
579 good_msg 'Mounting gcloop filesystem'
580 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
581 test_success 'losetup the loop device'
583 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
584 test_success 'Mount the losetup loop device'
585 FS_LOCATION='mnt/livecd'
586 elif [ "${LOOPTYPE}" = 'zisofs' ]
588 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
589 elif [ "${LOOPTYPE}" = 'noloop' ]
591 FS_LOCATION='mnt/cdrom'
592 elif [ "${LOOPTYPE}" = 'sgimips' ]
594 # getdvhoff finds the starting offset (in bytes) of the squashfs
595 # partition on the cdrom and returns this offset for losetup
597 # All currently supported SGI Systems use SCSI CD-ROMs, so
598 # so we know that the CD-ROM is usually going to be /dev/sr0.
600 # We use the value given to losetup to set /dev/loop0 to point
601 # to the liveCD root partition, and then mount /dev/loop0 as
603 good_msg 'Locating the SGI LiveCD Root Partition'
605 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
606 "${NEW_ROOT}${CDROOT_DEV}" \
607 "${NEW_ROOT}${REAL_ROOT}"
608 test_success 'losetup /dev/sr0 /dev/loop0'
610 good_msg 'Mounting the Root Partition'
611 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
612 test_success 'mount /dev/loop0 /'
613 FS_LOCATION='mnt/livecd'
619 # Unpacking additional packages from NFS mount
620 # This is useful for adding kernel modules to /lib
621 # We do this now, so that additional packages can add whereever they want.
622 if [ "${REAL_ROOT}" = '/dev/nfs' ]
624 if [ -e "${NEW_ROOT}/mnt/cdrom/add" ]
626 for targz in `ls ${NEW_ROOT}/mnt/cdrom/add/*.tar.gz`
628 tarname=`basename ${targz}`
629 good_msg "Adding additional package ${tarname}"
630 (cd ${NEW_ROOT} ; /bin/tar -xzf ${targz})
636 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
638 setup_unionfs ${NEW_ROOT} ${NEW_ROOT}/${FS_LOCATION}
642 good_msg "Copying read-write image contents to tmpfs"
643 # Copy over stuff that should be writable
644 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
646 # Now we do the links.
647 for x in ${ROOT_LINKS}
649 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
651 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
653 # List all subdirectories of x
654 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
656 # Strip the prefix of the FS_LOCATION
657 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
659 # Skip this directory if we already linked a parent directory
660 if [ "${current_parent}" != '' ]; then
661 var=`echo "${directory}" | grep "^${current_parent}"`
662 if [ "${var}" != '' ]; then
666 # Test if the directory exists already
667 if [ -e "/${NEW_ROOT}/${directory}" ]
669 # It does exist, link all the individual files
670 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
672 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
673 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
677 # It does not exist, make a link to the livecd
678 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
679 current_parent="${directory}"
685 mkdir initramfs proc tmp sys 2>/dev/null
690 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
691 #if [ "${UML}" = 'UML' ]
694 # good_msg 'Updating for uml system'
697 # Let Init scripts know that we booted from CD
701 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
704 mount -t tmpfs tmpfs /union_changes
705 setup_unionfs /union_changes ${NEW_ROOT}
706 mkdir -p ${UNION}/tmp/.initrd
710 # Execute script on the cdrom just before boot to update things if necessary
713 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
715 good_msg "Entering ${SUBDIR} to boot"
716 CHROOT="${CHROOT}/${SUBDIR}"
721 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
722 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
724 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing files required to boot (console and null)${NORMAL}"
725 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
727 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your real /dev is missing tty1, which is required for splash${NORMAL}"
731 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
732 echo -ne "${BOLD}.${NORMAL}"
733 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
734 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
735 echo -e "${BOLD}.${NORMAL}"
737 exec /sbin/switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
739 # If we get here, something bad has happened
742 echo 'A fatal error has probably occured since /sbin/init did not'
743 echo 'boot correctly. Trying to open a shell...'