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
35 ln -s /bin/lvm /bin/vgscan
36 ln -s /bin/lvm /bin/vgchange
42 CMDLINE=`cat /proc/cmdline`
43 # Scan CMDLINE for any specified real_root= or cdroot arguments
52 REAL_ROOT=`parse_opt "${x}"`
55 FAKE_ROOT=`parse_opt "${x}"`
58 SUBDIR=`parse_opt "${x}"`
61 REAL_INIT=`parse_opt "${x}"`
64 INIT_OPTS=`parse_opt "${x}"`
72 CDROOT_DEV=`parse_opt "${x}"`
75 CDROOT_TYPE=`parse_opt "${x}"`
77 # Start livecd loop, looptype options
79 LOOP=`parse_opt "${x}"`
82 LOOPTYPE=`parse_opt "${x}"`
84 # Start Volume manager options
89 bad_msg 'Using dolvm2 is deprecated, use dolvm, instead.'
99 DMRAID_OPTS=`parse_opt "${x}"`
106 bad_msg 'Using doevms2 is deprecated, use doevms, instead.'
115 SDELAY=`parse_opt "${x}"`
122 MDOLIST=`parse_opt "${x}"`
123 MDOLIST="`echo ${MDOLIST} | sed -e 's/,/ /g'`"
129 MLIST=`parse_opt "${x}"`
130 MLIST="`echo ${MLIST} | sed -e 's/,/ /g'`"
133 # Redirect output to a specific tty
134 CONSOLE\=*\|console\=*)
135 CONSOLE=`parse_opt "${x}"`
136 exec >${CONSOLE} <${CONSOLE} 2>&1
140 RAID_DEVICES="`parse_opt ${x}`"
141 RAID_DEVICES="`echo ${RAID_DEVICES} | sed -e 's/,/ /g'`"
144 MDPART=`parse_opt "${x}"`
148 IP=`parse_opt "${x}"`
151 NFSROOT=`parse_opt "${x}"`
154 CRYPT_ROOT=`parse_opt "${x}"`
157 CRYPT_SWAP=`parse_opt "${x}"`
160 CRYPT_ROOT_KEY=`parse_opt "${x}"`
163 CRYPT_ROOT_KEYDEV=`parse_opt "${x}"`
166 CRYPT_SWAP_KEY=`parse_opt "${x}"`
169 CRYPT_SWAP_KEYDEV=`parse_opt "${x}"`
172 REAL_RESUME=`parse_opt "${x}"`
181 REAL_ROOTFLAGS=`parse_opt "${x}"`
184 keymap=`parse_opt "${x}"`
189 if [ -z "${REAL_ROOT}" -a \( "${CDROOT}" -eq 0 \) -a \( "${FAKE_ROOT}" != "/dev/ram0" \) ]
191 REAL_ROOT="${FAKE_ROOT}"
202 # Setup hotplugging for firmware loading
205 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running kernel
206 if [ -z "${DO_modules}" ]
208 good_msg 'Skipping module load; disabled via commandline'
209 elif [ -d "/lib/modules/${KV}" ]
211 good_msg 'Loading modules'
212 # Load appropriate kernel modules
213 if [ "${NODETECT}" != '1' ]
215 for modules in ${MY_HWOPTS}
217 modules_scan ${modules}
220 # Always eval doload=...
221 modules_load ${MDOLIST}
223 good_msg 'Skipping module load; no modules in the ramdisk!'
226 # Delay if needed for USB hardware
229 # Start device manager
232 # Setup md device nodes if they dont exist
240 # Initialize LUKS root device except for livecd's
241 if [ "${CDROOT}" != 1 ]
244 if [ "${NORESUME}" != '1' ] && [ -n "${REAL_RESUME}" ]
252 mkdir -p "${NEW_ROOT}"
255 # Run debug shell if requested
258 if [ "${CDROOT}" = '1' ]
260 good_msg "Making tmpfs for ${NEW_ROOT}"
261 mount -t tmpfs tmpfs "${NEW_ROOT}"
263 for i in dev mnt mnt/cdrom mnt/livecd mnt/key tmp tmp/.initrd mnt/gentoo sys
265 mkdir -p "${NEW_ROOT}/${i}"
266 chmod 755 "${NEW_ROOT}/${i}"
268 [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3
269 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1
271 # For SGI LiveCDs ...
272 if [ "${LOOPTYPE}" = "sgimips" ]
274 [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0
275 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0
278 # Required for splash to work. Not an issue with the initrd as this
279 # device isn't created there and is not needed.
282 [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1
285 if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ]
290 if [ "${REAL_ROOT}" = '' ]
292 echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices"
295 while [ ${COUNTER} -lt 3 ]; do
298 let COUNTER=${COUNTER}+1
306 if [ "${REAL_ROOT}" = '' ]
309 umount "${NEW_ROOT}/dev" 2>/dev/null
310 umount "${NEW_ROOT}/sys" 2>/dev/null
311 umount /sys 2>/dev/null
314 rm -rf "${NEW_ROOT}/*"
316 bad_msg 'Could not find CD to boot, something else needed!'
321 # Determine root device
322 good_msg 'Determining root device...'
325 while [ "${got_good_root}" != '1' ]
327 case "${REAL_ROOT}" in
333 if [ "${retval}" -ne '0' ]; then
334 ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
338 if [ "$retval" -ne '0' ]; then
339 ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
343 if [ "${retval}" -ne '0' ]; then
344 ROOT_DEV=`blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
348 if [ "${retval}" -eq '0' ] && [ -n "${ROOT_DEV}" ]; then
349 good_msg "Detected real_root=${ROOT_DEV}"
350 REAL_ROOT="${ROOT_DEV}"
352 whereis "REAL_ROOT" "root block device"
359 if [ "${REAL_ROOT}" = '' ]
361 # No REAL_ROOT determined/specified. Prompt user for root block device.
362 whereis "REAL_ROOT" "root block device"
365 # Check for a block device or /dev/nfs
366 elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
371 bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
378 if [ "${CDROOT}" = 1 -a "${got_good_root}" = '1' -a "${REAL_ROOT}" != "/dev/nfs" ]
380 # CD already mounted; no further checks necessary
382 elif [ "${LOOPTYPE}" = "sgimips" ]
384 # sgimips mounts the livecd root partition directly
385 # there is no isofs filesystem to worry about
388 good_msg "Mounting root..."
390 # Try to mount the device as ${NEW_ROOT}
391 if [ "${REAL_ROOT}" = '/dev/nfs' ]; then
394 # mount ro so fsck doesn't barf later
395 if [ "${REAL_ROOTFLAGS}" = '' ]; then
396 mount -o ro ${REAL_ROOT} ${NEW_ROOT}
398 good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
399 mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
403 # If mount is successful break out of the loop
404 # else not a good root and start over.
407 if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ]
411 bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
416 bad_msg "Could not mount specified ROOT, try again"
422 # End determine root device
426 # If CD root is set determine the looptype to boot
427 if [ "${CDROOT}" = '1' ]
429 good_msg 'Determining looptype ...'
432 # Find loop and looptype
433 [ -z "${LOOP}" ] && find_loop
434 [ -z "${LOOPTYPE}" ] && find_looptype
438 # If encrypted, find key and mount, otherwise mount as usual
439 if [ -n "${CRYPT_ROOT}" ]
441 CRYPT_ROOT_KEY="$(head -n 1 ${NEW_ROOT}/mnt/cdrom/livecd)"
442 CRYPT_ROOT='/dev/loop0'
443 good_msg 'You booted an encrypted livecd' "${CRYPT_SILENT}"
445 losetup /dev/loop0 "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
446 test_success 'Preparing loop filesystem'
455 MOUNTTYPE="${LOOPTYPE}"
458 mount -t "${MOUNTTYPE}" -o ro /dev/mapper/root "${NEW_ROOT}/mnt/livecd"
459 test_success 'Mount filesystem'
460 FS_LOCATION='mnt/livecd'
461 # Setup the loopback mounts, if unencrypted
463 if [ "${LOOPTYPE}" = 'normal' ]
465 good_msg 'Mounting loop filesystem'
466 mount -t ext2 -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
467 test_success 'Mount filesystem'
468 FS_LOCATION='mnt/livecd'
469 elif [ "${LOOPTYPE}" = 'squashfs' ]
471 good_msg 'Mounting squashfs filesystem'
472 mount -t squashfs -o loop,ro "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}" "${NEW_ROOT}/mnt/livecd"
473 test_success 'Mount filesystem'
474 FS_LOCATION='mnt/livecd'
475 elif [ "${LOOPTYPE}" = 'gcloop' ]
477 good_msg 'Mounting gcloop filesystem'
478 echo ' ' | losetup -E 19 -e ucl-0 -p0 "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/cdrom/${LOOPEXT}${LOOP}"
479 test_success 'losetup the loop device'
481 mount -t ext2 -o ro "${NEW_ROOT}/dev/loop0" "${NEW_ROOT}/mnt/livecd"
482 test_success 'Mount the losetup loop device'
483 FS_LOCATION='mnt/livecd'
484 elif [ "${LOOPTYPE}" = 'zisofs' ]
486 FS_LOCATION="mnt/cdrom/${LOOPEXT}${LOOP}"
487 elif [ "${LOOPTYPE}" = 'noloop' ]
489 FS_LOCATION='mnt/cdrom'
490 elif [ "${LOOPTYPE}" = 'sgimips' ]
492 # getdvhoff finds the starting offset (in bytes) of the squashfs
493 # partition on the cdrom and returns this offset for losetup
495 # All currently supported SGI Systems use SCSI CD-ROMs, so
496 # so we know that the CD-ROM is usually going to be /dev/sr0.
498 # We use the value given to losetup to set /dev/loop0 to point
499 # to the liveCD root partition, and then mount /dev/loop0 as
501 good_msg 'Locating the SGI LiveCD Root Partition'
503 losetup -o $(getdvhoff "${NEW_ROOT}${REAL_ROOT}" 0) \
504 "${NEW_ROOT}${CDROOT_DEV}" \
505 "${NEW_ROOT}${REAL_ROOT}"
506 test_success 'losetup /dev/sr0 /dev/loop0'
508 good_msg 'Mounting the Root Partition'
509 mount -t squashfs -o ro "${NEW_ROOT}${CDROOT_DEV}" "${NEW_ROOT}/mnt/livecd"
510 test_success 'mount /dev/loop0 /'
511 FS_LOCATION='mnt/livecd'
515 # Unpacking additional packages from NFS mount
516 # This is useful for adding kernel modules to /lib
517 # We do this now, so that additional packages can add whereever they want.
518 if [ "${REAL_ROOT}" = '/dev/nfs' ]
520 if [ -e "${CHROOT}/mnt/cdrom/add" ]
522 for targz in `ls ${CHROOT}/mnt/cdrom/add/*.tar.gz`
524 tarname=`basename ${targz}`
525 good_msg "Adding additional package ${tarname}"
526 (cd ${CHROOT} ; /bin/tar -xzf ${targz})
532 good_msg "Copying read-write image contents to tmpfs"
533 # Copy over stuff that should be writable
534 (cd "${NEW_ROOT}/${FS_LOCATION}"; cp -a ${ROOT_TREES} "${NEW_ROOT}")
536 # Now we do the links.
537 for x in ${ROOT_LINKS}
539 if [ -L "${NEW_ROOT}/${FS_LOCATION}/${x}" ]
541 ln -s "`readlink ${NEW_ROOT}/${FS_LOCATION}/${x}`" "${x}" 2>/dev/null
543 # List all subdirectories of x
544 find "${NEW_ROOT}/${FS_LOCATION}/${x}" -type d 2>/dev/null | while read directory
546 # Strip the prefix of the FS_LOCATION
547 directory="${directory#${NEW_ROOT}/${FS_LOCATION}/}"
549 # Skip this directory if we already linked a parent directory
550 if [ "${curent_parrent}" != '' ]; then
551 var=`echo "${directory}" | grep "^${curent_parrent}"`
552 if [ "${var}" != '' ]; then
556 # Test if the directory exists already
557 if [ -e "/${NEW_ROOT}/${directory}" ]
559 # It does exist, link all the individual files
560 for file in `ls /${NEW_ROOT}/${FS_LOCATION}/${directory}`
562 if [ ! -d "/${NEW_ROOT}/${FS_LOCATION}/${directory}/${file}" ] && [ ! -e "${NEW_ROOT}/${directory}/${file}" ]; then
563 ln -s "/${FS_LOCATION}/${directory}/${file}" "${directory}/${file}" 2> /dev/null
567 # It does not exist, make a link to the livecd
568 ln -s "/${FS_LOCATION}/${directory}" "${directory}" 2>/dev/null
569 current_parent="${directory}"
575 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
579 mkdir initramfs proc tmp sys 2>/dev/null
582 #UML=`cat /proc/cpuinfo|grep UML|sed -e 's|model name.*: ||'`
583 #if [ "${UML}" = 'UML' ]
586 # good_msg 'Updating for uml system'
589 # Let Init scripts know that we booted from CD
593 if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ]
599 # Execute script on the cdrom just before boot to update things if necessary
602 if [ "${SUBDIR}" != '' -a -e "${CHROOT}/${SUBDIR}" ]
604 good_msg "Entering ${SUBDIR} to boot"
605 CHROOT="${CHROOT}/${SUBDIR}"
610 echo -ne "${GOOD}>>${NORMAL}${BOLD} Booting (initramfs)${NORMAL}"
611 if [ ! -e "${CHROOT}/dev/console" ] || [ ! -e "${CHROOT}/dev/null" ]
613 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your /dev is missing files required to boot (console and null)${NORMAL}"
614 elif [ -e /etc/initrd.splash -a ! -e "${CHROOT}/dev/tty1" ]
616 echo -ne "${BAD}>>${NORMAL}${BOLD} ERROR: your /dev is missing tty1, which is required for splash${NORMAL}"
620 mkdir "${CHROOT}/proc" "${CHROOT}/sys" 2>/dev/null
621 echo -ne "${BOLD}.${NORMAL}"
622 umount /sys || echo '*: Failed to unmount the ramdisk /sys!'
623 umount /proc || echo '*: Failed to unmount the ramdisk /proc!'
624 echo -e "${BOLD}.${NORMAL}"
626 exec switch_root -c "/dev/console" "${CHROOT}" "${REAL_INIT:-/sbin/init}" "${INIT_OPTS}"
628 # If we get here, something bad has happened
631 echo 'A fatal error has probably occured since /sbin/init did not'
632 echo 'boot correctly. Trying to open a shell...'