6 echo -ne "\033[0G\033[0K"
12 echo ${module} >> /etc/modules/extra_load
15 modules_scan extra_load
20 [ -d "/etc/modules/${1}" ] || touch /etc/modules/${1}
22 [ -f "/etc/modules/${1}" ] && MODS=`cat /etc/modules/${1}`
25 MLOAD=`echo ${MLIST} | sed -e "s/.*${x}.*/${x}/"`
26 if [ "${MLOAD}" = "${x}" ] # Only module to no-load
28 echo -e "${BOLD} ::${NORMAL} Skipping ${x}..."
29 elif [ "${MLOAD}" = "${MLIST}" ] # == No change == No specified no-load
31 [ -n "${DEBUG}" ] && echo -ne "${BOLD} ::${NORMAL} Checking for ${x}..."
32 # find -name does not work since the return status is always zero
33 if find /lib/modules/${KV} | grep /"${x}${KSUFF}" >/dev/null 2>&1
35 echo -ne "${BOLD} ::${NORMAL} Scanning for ${x}..."
41 echo -e "${BOLD} ::${NORMAL} Skipping ${x}..."
48 echo $1 | tr 'a-z' 'A-Z'
53 # $1 = mount dir name / media name
54 # $2 = recognition file
55 # $3 = variable to have the device path
56 # $4 = actual mount dir path (full path)
57 # args remaining are possible devices
59 local media=$1 recon=$2 vrbl=$3 mntdir=$4
62 good_msg "Looking for the ${media}" ${CRYPT_SILENT}
66 [ ! -d "${mntdir}" ] && mkdir -p ${mntdir} 2>/dev/null >/dev/null
67 if [ -n "${ISOBOOT}" ]
69 mntcddir="${mntdir%${media}}iso"
70 if [ ! -f ${mntcddir} ]
80 # Check for a block device to mount
86 # If disk and it has at least one partition, skip.
87 # We use /sys/block/${bsn}/${bsn}[0-9]* to make sure that we
88 # don't skip device mapper devices. Even the craziest scenario
89 # deserves a fair chance.
91 for part in `ls /sys/block/${bsn}/${bsn}*[0-9]* 2>/dev/null`
100 good_msg "Attempting to mount media: ${x}" ${CRYPT_SILENT}
102 mount -r -t ${CDROOT_TYPE} ${x} ${mntcddir} >/dev/null 2>&1
105 if [ -n "${ISOBOOT}" ]; then
106 if [ -f ${mntcddir}/${ISOBOOT} ]; then
107 mount -o loop ${mntcddir}/${ISOBOOT} ${mntdir}
108 if [ "$?" = "0" ]; then
109 good_msg "iso mounted on ${mntdir}"
114 # Check for the media
115 if [ -f "${mntdir}/${recon}" ]
117 #set REAL_ROOT, CRYPT_ROOT_KEYDEV or whatever ${vrbl} is
118 eval ${vrbl}'='"${x}"
119 good_msg "Media found on ${x}" ${CRYPT_SILENT}
129 eval local result='$'${vrbl}
131 [ -n "${result}" ] || bad_msg "Media not found" ${CRYPT_SILENT}
135 # Locate the cdrom device with our media on it.
137 local DEVICES="/dev/cdroms/* /dev/ide/cd/* /dev/sr*"
138 # USB Keychain/Storage
139 DEVICES="$DEVICES /dev/sd*"
141 DEVICES="$DEVICES /dev/hd*"
143 DEVICES="$DEVICES /dev/vd*"
144 # USB using the USB Block Driver
145 DEVICES="$DEVICES /dev/ubd* /dev/ubd/*"
147 DEVICES="$DEVICES /dev/iseries/vcd*"
148 # builtin mmc/sd card reader devices
149 DEVICES="$DEVICES /dev/mmcblk* /dev/mmcblk*/*"
150 # fallback scanning, this might scan something twice, but it's better than
152 [ -e /proc/partitions ] && DEVICES="${DEVICES} $(awk '/([0-9]+[[:space:]]+)/{print "/dev/" $4}' /proc/partitions)"
157 local DEVICES=`devicelist`
158 # The device was specified on the command line, so there's no need to scan
159 # a bunch of extra devices
160 [ -n "${CDROOT_DEV}" ] && DEVICES="${CDROOT_DEV}"
162 findmediamount "cdrom" "${SUBDIR}/livecd" "REAL_ROOT" "${CDROOT_PATH}" ${DEVICES}
167 local KEYDEVS=`devicelist`
168 eval local keyloc='"${CRYPT_'${1}'_KEY}"'
170 findmediamount "key" "${keyloc}" "CRYPT_${1}_KEYDEV" "/mnt/key" ${KEYDEVS}
173 cache_cd_contents() {
174 # Check loop file exists and cache to ramdisk if DO_cache is enabled
175 if [ "${LOOPTYPE}" != "noloop" ] && [ "${LOOPTYPE}" != "sgimips" ]
180 # TODO: Check the size of the image versus the size of our tmpfs
181 # along with the amount of available RAM and increase tmpfs size
182 # if necessary. (Not having awk sucks...)
184 # for i in $(cat /proc/meminfo | grep -e ^MemFree -e ^Cached | \
185 # cut -d: -f2 | cut -dk -f1 | sed -e "s/^\s*//") ; do
186 # z=$(($z + $i)) ; done
188 good_msg "Copying loop file for caching..."
189 # Verify that the needed directory exists
190 mkdir -p "$(dirname ${NEW_ROOT}/mnt/${LOOP})"
191 cp -a ${CDROOT_PATH}/${LOOP} ${NEW_ROOT}/mnt/${LOOP}
194 warn_msg "Failed to cache the loop file! Lack of RAM?"
195 rm -rf ${NEW_ROOT}/mnt/${LOOP} 2>/dev/null
196 rm -rf ${NEW_ROOT}/mnt/livecd.* 2>/dev/null
197 rm -rf ${NEW_ROOT}/mnt/image.* 2>/dev/null
198 rm -rf ${NEW_ROOT}/mnt/zisofs 2>/dev/null
205 mount -t sysfs sysfs /sys -o noexec,nosuid,nodev >/dev/null 2>&1
207 [ ${ret} -eq 0 ] || bad_msg "Failed to mount /sys!"
211 if [ "${IP}" != '' ] || busybox udhcpc -n -T 15 -q
213 [ -e /rootpath ] && NFSROOT=`cat /rootpath`
215 if [ "${NFSROOT}" = '' ]
218 OPTIONS=`busybox dmesg | grep rootserver | sed -e "s/,/ /g"`
219 for OPTION in $OPTIONS
221 if [ `echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1` = 'rootserver' ]
223 NFSIP=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`
228 OPTIONS=`busybox dmesg | grep rootpath | sed -e "s/,/ /g"`
229 for OPTION in $OPTIONS
231 if [ `echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 1` = 'rootpath' ]
233 NFSPATH=`echo $OPTION | sed -e "s/=/ /g" | cut -d " " -f 2`
238 if [ "${NFSIP}" != '' ] && [ "$NFSPATH" != '' ]
240 NFSROOT="${NFSIP}:${NFSPATH}"
242 bad_msg "The DHCP Server did not send a valid root-path."
243 bad_msg "Please check your DHCP setup, or provide a nfsroot=<...> parameter."
247 if [ "${NFSROOT}" != '' ]
249 NFSOPTIONS=${NFSROOT#*,}
250 NFSROOT=${NFSROOT%%,*}
251 if [ "${NFSOPTIONS}" = "${NFSROOT}" ]
253 NFSOPTIONS=$DEFAULT_NFSOPTIONS
255 NFSOPTIONS="${DEFAULT_NFSOPTIONS},${NFSOPTIONS}"
258 if [ "${CDROOT}" != '0' ]
260 good_msg "Attempting to mount NFS CD image on ${NFSROOT} with options ${NFSOPTIONS}"
261 mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${CDROOT_PATH}
266 bad_msg "NFS Mounting failed. Is the path corrent ?"
269 good_msg "Attempting to mount NFS root on ${NFSROOT} with options ${NFSOPTIONS}"
270 mount -t nfs -o ${NFSOPTIONS} ${NFSROOT} ${NEW_ROOT}
275 bad_msg "NFS Mounting failed. Is the path correct ?"
277 # FIXME: Need to start portmap and the other rpc daemons in
278 # order to remount rw.
286 if [ "${LOOP}" = '' -o ! -e "${CDROOT_PATH}/${LOOP}" ]
289 bad_msg "Invalid loop location: ${LOOP}"
290 bad_msg 'Please export LOOP with a valid location, or reboot and pass a proper loop=...'
291 bad_msg 'kernel command line!'
303 cut -d ' ' -f 3 < /proc/mounts | fgrep -q "${fs_type}"
307 # Use devtmpfs if enabled in kernel,
308 # else tmpfs. Always run mdev just in case
310 if grep -qs devtmpfs /proc/filesystems ; then
314 # Options copied from /etc/init.d/udev-mount, should probably be kept in sync
315 if ! fs_type_in_use devtmpfs; then
316 mount -t $devfs -o "exec,nosuid,mode=0755,size=10M" udev /dev \
317 || bad_msg "Failed to mount /dev as ${devfs}"
320 # http://git.busybox.net/busybox/plain/docs/mdev.txt
321 if ! fs_type_in_use devpts; then
322 mkdir -m 0755 /dev/pts
323 mount -t devpts -o gid=5,mode=0620 devpts /dev/pts || bad_msg "Failed to mount /dev/pts"
329 # If last command failed send error message and fall back to a shell
330 if [ "$retcode" != '0' ]
333 error_string="${error_string:-run command}"
334 bad_msg 'Failed to $1; failing back to the shell...'
340 # msg functions arguments
346 msg_string="${msg_string:-...}"
347 [ "$2" != 1 ] && echo -e "${GOOD}>>${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
352 msg_string="${msg_string:-...}"
355 splash 'verbose' > /dev/null &
356 echo -e "${BAD}!!${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
362 msg_string="${msg_string:-...}"
363 [ "$2" != 1 ] && echo -e "${WARN}**${NORMAL}${BOLD} ${msg_string} ${NORMAL}"
367 if [ "${CRYPT_SILENT}" = '1' ]
369 eval $1 >/dev/null 2>/dev/null
371 splash 'verbose' > /dev/null &
376 splash set_msg 'Disk unlocked.'
383 # $1 = variable whose value is the path (examples: "REAL_ROOT",
386 # $3 = optional explanations for failure
388 eval local oldvalue='$'${1}
390 [ \( $# != 2 \) -a \( $# != 3 \) ] && \
391 bad_msg "Bad invocation of function prompt_user, please file a bug \
392 report with this message" && exit 1
393 [ -n "${3}" ] && local explnt=" or : ${3}" || local explnt="."
395 bad_msg "Could not find the ${2} in ${oldvalue}${explnt}"
396 echo ' Please specify another value or: press Enter for the same, type "shell" for a shell, or "q" to skip...'
397 echo -n "${2}(${oldvalue}) :: "
399 case `eval echo '$'${1}` in
401 eval ${1}'='${oldvalue}
402 warn_msg "Skipping step, this will likely cause a boot failure."
406 eval ${1}'='${oldvalue}
407 echo "To leave and try again just press <Ctrl>+D"
411 eval ${1}'='${oldvalue}
417 # This function removes unset DO_slowusb if there is no usb-storage attached.
418 # If noslowusb is set, skip this function
419 [ "${DO_slowusb}" ] || return
421 # Unset DO_slowusb, so we can set it again if usb-storage has something attached
424 local usb_storage_dir="/sys/bus/usb/drivers/usb-storage"
425 if [ ! -d "${usb_storage_dir}" ]
427 # no automated slowusb required. no usb-storage devices attached.
430 for x in "${usb_storage_dir}"/*
432 [ -d "${x}" ] && [ "${x}" != "${usb_storage_dir}/module" ] \
433 && { DO_slowusb="1" ; break ; }
438 # Scan CMDLINE for any "doscsi" or "noscsi"-type arguments
446 if [ "${y}" = "do${x}" ]
448 MY_HWOPTS="${MY_HWOPTS} $x"
449 elif [ "${y}" = "no${x}" ]
451 MY_HWOPTS="`echo ${MY_HWOPTS} | sed -e \"s/${x}//g\" -`"
453 if [ "$(echo ${y} | cut -b -7)" = "keymap=" ]
455 MY_HWOPTS="${MY_HWOPTS} keymap"
460 # Shouldnt need to sort this as the following loop should figure out the
461 # duplicates and strip them out
462 #MY_HWOPTS=`echo ${MY_HWOPTS}| sort`
464 for x in ${MY_HWOPTS}
467 for y in ${TMP_HWOPTS}
469 if [ "${y}" = "${x}" ]
474 TMP_HWOPTS="${TMP_HWOPTS} ${x}"
475 eval DO_`echo ${x} | sed 's/-//'`=1
478 MY_HWOPTS=${TMP_HWOPTS}
482 # Load modules listed in MY_HWOPTS if /lib/modules exists for the running
484 if [ -d "/lib/modules/${KV}" ]
486 good_msg 'Loading modules'
487 # Load appropriate kernel modules
488 for modules in $MY_HWOPTS
490 modules_scan $modules
493 good_msg 'Skipping module load; no modules in the ramdisk!'
498 if [ "${DO_keymap}" ]
500 if [ ! -e /dev/vc/0 -a ! -e /dev/tty0 ]
503 mount -o bind ${NEW_ROOT}/dev /dev
505 [ ! -e /dev/tty0 ] && ln -s /dev/tty1 /dev/tty0
507 [ -f /lib/keymaps/keymapList ] && chooseKeymap
509 [ "${DEVBIND}" = '1' ] && umount /dev
511 if [ -e /etc/sysconfig/keyboard -a "${CDROOT}" = '1' ]
513 mkdir -p ${NEW_ROOT}/etc/sysconfig/
514 cp /etc/sysconfig/keyboard ${NEW_ROOT}/etc/sysconfig/keyboard
520 good_msg "Loading keymaps"
521 if [ -z "${keymap}" ]
523 splash 'verbose' > /dev/null &
524 cat /lib/keymaps/keymapList
525 read -t 10 -p '<< Load keymap (Enter for default): ' keymap
527 1|azerty) keymap=azerty ;;
530 4|br-a) keymap=br-a ;;
531 5|br-l) keymap=br-l ;;
534 8|croat) keymap=croat ;;
538 12|dvorak) keymap=dvorak ;;
560 34|sk-y) keymap=sk-y ;;
561 35|sk-z) keymap=sk-z ;;
562 36|slovene) keymap=slovene ;;
563 37|trf) keymap=trf ;;
564 38|trq) keymap=trq ;;
568 42|wangbe) keymap=wangbe ;;
569 43|sf|ch*) keymap=sf ;;
572 if [ -e /lib/keymaps/${keymap}.map ]
574 good_msg "Loading the ''${keymap}'' keymap"
575 loadkmap < /lib/keymaps/${keymap}.map
577 # echo ${keymap} | egrep -e "[0-9]+" >/dev/null 2>&1
580 # xkeymap=`tail -n 8 /lib/keymaps/keymapList | grep ${keymap} | sed -r "s/.*\s+${keymap}\s+([a-z-]+).*/\1/g" | egrep -v 1`
582 mkdir -p /etc/sysconfig
583 # echo "XKEYBOARD=${xkeymap}" > /etc/sysconfig/keyboard
584 echo "XKEYBOARD=${keymap}" > /etc/sysconfig/keyboard
585 splash set_msg "Set keymap to ${keymap}"
586 elif [ -z "${keymap}" ]
589 good_msg "Keeping default keymap"
590 splash set_msg "Keeping default keymap"
592 bad_msg "Sorry, but keymap ''${keymap}'' is invalid!"
599 #good_msg 'Checking if volumes need to be started...'
601 # Here, we check for /dev/device-mapper, and if it exists, we setup a
602 # a symlink, which should hopefully fix bug #142775 and bug #147015
603 if [ -e /dev/device-mapper ] && [ ! -e /dev/mapper/control ]
606 ln -sf /dev/device-mapper /dev/mapper/control
609 if [ "${USE_MDADM}" = '1' ]
611 if [ -e '/sbin/mdadm' ]
613 /sbin/mdadm --assemble --scan
615 bad_msg "mdadm not found: skipping mdadm raid assembly!"
619 if [ "${USE_DMRAID_NORMAL}" = '1' ]
621 if [ -e '/sbin/dmraid' ]
623 good_msg "Activating Device-Mapper RAID(s)"
624 if [ '${DMRAID_OPTS}' = '' ]
628 /sbin/dmraid -ay ${DMRAID_OPTS}
633 if [ "${USE_LVM_NORMAL}" = '1' ]
637 for dev in ${RAID_DEVICES}
639 setup_md_device "${dev}"
642 # This is needed for /bin/lvm to accept the following logic
643 lvm_commands="#! /bin/lvm"
645 # If there is a cahe, update it. Unbreak at least dmcrypt
646 [ -d /etc/lvm/cache ] && lvm_commands="${lvm_commands} \nvgscan"
648 # To activate volumegroups on all devices in the cache
649 lvm_commands="${lvm_commands} \nvgchange -ay --sysinit"
651 # To create symlinks so users can use real_root=/dev/vg/root
652 # This needs to run after vgchange, using vgchange --mknodes is too
654 lvm_commands="${lvm_commands} \nvgmknodes --ignorelockingfailure"
656 # And finally execute it all (/proc/... needed if lvm is compiled without readline)
657 good_msg "Scanning for and activating Volume Groups"
658 printf "%b\n" "${lvm_commands}" | /bin/lvm /proc/self/fd/0
660 bad_msg "vgscan or vgchange not found: skipping LVM volume group activation!"
664 if [ "${USE_ZFS}" = '1' ]
666 if [ -z "${ZFS_POOL}" ]
668 good_msg "Importing ZFS pools"
670 /sbin/zpool import -N -a "${ZPOOL_FORCE}"
674 good_msg "Importing ZFS pools succeeded"
676 bad_msg "Imported ZFS pools failed"
680 if [ "$(zpool list -H -o name ${ZFS_POOL} 2>&1)" = "$ZFS_POOL" ]
682 good_msg "ZFS pool ${ZFS_POOL} already imported."
684 if [ -n "${CRYPT_ROOT}" -o -n "${CRYPT_SWAP}" ]
686 good_msg "LUKS detected. Reimporting ${ZFS_POOL}"
687 /sbin/zpool export -f "${ZFS_POOL}"
688 /sbin/zpool import -N "${ZPOOL_FORCE}" "${ZFS_POOL}"
691 good_msg "Importing ZFS pool ${ZFS_POOL}"
693 /sbin/zpool import -N "${ZPOOL_FORCE}" "${ZFS_POOL}"
697 good_msg "Importing ${ZFS_POOL} succeeded"
699 bad_msg "Importing ${ZFS_POOL} failed"
708 if [ ! -n "${ISCSI_NOIBFT}" ]
710 good_msg "Activating iSCSI via iBFT"
714 if [ -n "${ISCSI_INITIATORNAME}" ] && [ -n "${ISCSI_TARGET}" ] && [ -n "${ISCSI_ADDRESS}" ]
716 good_msg "Activating iSCSI via cmdline"
718 if [ "${ISCSI_TGPT}" ]
720 ADDITIONAL="${ADDITIONAL} -g ${ISCSI_TGPT}"
722 ADDITIONAL="${ADDITIONAL} -g 1"
725 if [ "${ISCSI_PORT}" ]
727 ADDITIONAL="${ADDITIONAL} -p ${ISCSI_PORT}"
730 if [ "${ISCSI_USERNAME}" ]
732 ADDITIONAL="${ADDITIONAL} -u ${ISCSI_USERNAME}"
735 if [ "${ISCSI_PASSWORD}" ]
737 ADDITIONAL="${ADDITIONAL} -w ${ISCSI_PASSWORD}"
740 if [ "${ISCSI_USERNAME_IN}" ]
742 ADDITIONAL="${ADDITIONAL} -U ${ISCSI_USERNAME_IN}"
745 if [ "${ISCSI_PASSWORD_IN}" ]
747 ADDITIONAL="${ADDITIONAL} -W ${ISCSI_PASSWORD_IN}"
750 if [ "${ISCSI_DEBUG}" ]
752 ADDITIONAL="${ADDITIONAL} -d ${ISCSI_DEBUG}"
755 iscsistart -i "${ISCSI_INITIATORNAME}" -t "${ISCSI_TARGET}" -a "${ISCSI_ADDRESS}" ${ADDITIONAL}
757 # let iscsid settle - otherwise mounting the iSCSI-disk will fail (very rarely, though)
764 # It is either the root or a swap, other devices are supported in the scripts provided with sys-fs/cryptsetup-luks
767 # please use 'tr' and this line, or remove it
768 # eval local TYPE=`uppercase $1`
779 eval local LUKS_DEVICE='"${CRYPT_'${TYPE}'}"' LUKS_NAME="$1" LUKS_KEY='"${CRYPT_'${TYPE}'_KEY}"' LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"' LUKS_TRIM='"${CRYPT_'${TYPE}'_TRIM}"'
780 local DEV_ERROR=0 KEY_ERROR=0 KEYDEV_ERROR=0
781 local mntkey="/mnt/key/" cryptsetup_options=''
783 [ ! -e /sbin/cryptsetup ] && bad_msg "The ramdisk does not support LUKS" && exit 1
787 # if crypt_silent=1 and some error occurs, enter shell quietly
788 if [ \( ${CRYPT_SILENT} -eq 1 \) -a \( \( \( ${DEV_ERROR} -eq 1 \) -o \( ${KEY_ERROR} -eq 1 \) \) -o \( ${KEYDEV_ERROR} -eq 1 \) \) ]
791 elif [ ${DEV_ERROR} -eq 1 ]
793 prompt_user "LUKS_DEVICE" "${LUKS_NAME}"
795 elif [ ${KEY_ERROR} -eq 1 ]
797 prompt_user "LUKS_KEY" "${LUKS_NAME} key"
799 elif [ ${KEYDEV_ERROR} -eq 1 ]
801 prompt_user "LUKS_KEYDEV" "${LUKS_NAME} key device"
804 case "${LUKS_DEVICE}" in
809 if [ "${retval}" -ne 0 ]; then
810 REAL_LUKS=`findfs "${LUKS_DEVICE}" 2>/dev/null`
814 if [ "$retval" -ne 0 ]; then
815 REAL_LUKS=`busybox findfs "${LUKS_DEVICE}" 2>/dev/null`
819 if [ "${retval}" -ne 0 ]; then
820 REAL_LUKS=`blkid -o device -l -t "${LUKS_DEVICE}"`
824 if [ "${retval}" -eq 0 ] && [ -n "${REAL_LUKS}" ]; then
825 good_msg "Detected device ${REAL_LUKS}"
826 LUKS_DEVICE="${REAL_LUKS}"
831 setup_md_device ${LUKS_DEVICE}
832 cryptsetup isLuks ${LUKS_DEVICE}
835 bad_msg "The LUKS device ${LUKS_DEVICE} does not contain a LUKS header" ${CRYPT_SILENT}
840 if [ "x${LUKS_TRIM}" = "xyes" ]
842 good_msg "Enabling TRIM support for ${LUKS_NAME}." ${CRYPT_SILENT}
843 cryptsetup_options="${cryptsetup_options} --allow-discards"
846 if [ -n "${LUKS_KEY}" ]
848 if [ ! -e "${mntkey}${LUKS_KEY}" ]
850 if [ -b "${LUKS_KEYDEV}" ]
851 then good_msg "Using key device ${LUKS_KEYDEV}." ${CRYPT_SILENT}
853 good_msg "Please insert removable device ${LUKS_KEYDEV} for ${LUKS_NAME}" ${CRYPT_SILENT}
854 # abort after 10 secs
856 while [ ${count} -gt 0 ]
860 if [ -b "${LUKS_KEYDEV}" ]
862 good_msg "Removable device ${LUKS_KEYDEV} detected." ${CRYPT_SILENT}
866 if [ ! -b "${LUKS_KEYDEV}" ]
868 eval CRYPT_${TYPE}_KEY=${LUKS_KEY}
870 eval LUKS_KEYDEV='"${CRYPT_'${TYPE}'_KEYDEV}"'
871 if [ ! -b "${LUKS_KEYDEV}" ]; then
873 bad_msg "Removable device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
876 # continue otherwise will mount keydev which is mounted by bootstrap
880 # At this point a device was recognized, now let's see if the key is there
881 [ ! -d "$mntkey" ] && mkdir -p ${mntkey} 2>/dev/null >/dev/null
883 mount -n -o ro ${LUKS_KEYDEV} ${mntkey} >/dev/null 2>/dev/null
887 bad_msg "Mounting of device ${LUKS_KEYDEV} failed." ${CRYPT_SILENT}
890 good_msg "Removable device ${LUKS_KEYDEV} mounted." ${CRYPT_SILENT}
893 if [ ! -e "${mntkey}${LUKS_KEY}" ]; then
894 umount -n ${mntkey} 2>/dev/null >/dev/null
897 bad_msg "Key {LUKS_KEY} on device ${LUKS_KEYDEV} not found." ${CRYPT_SILENT}
902 # At this point a candidate key exists (either mounted before or not)
903 good_msg "${LUKS_KEY} on device ${LUKS_KEYDEV} found" ${CRYPT_SILENT}
904 if [ "$(echo ${LUKS_KEY} | grep -o '.gpg$')" = ".gpg" ] && [ -e /sbin/gpg ] ; then
905 [ -e /dev/tty ] && mv /dev/tty /dev/tty.org
907 cryptsetup_options="${cryptsetup_options} -d -"
908 gpg_cmd="/sbin/gpg --logger-file /dev/null --quiet --decrypt ${mntkey}${LUKS_KEY} |"
910 cryptsetup_options="${cryptsetup_options} -d ${mntkey}${LUKS_KEY}"
913 # At this point, keyfile or not, we're ready!
914 crypt_filter "${gpg_cmd}cryptsetup ${cryptsetup_options} luksOpen ${LUKS_DEVICE} ${LUKS_NAME}"
917 [ -e /dev/tty.org ] \
919 && mv /dev/tty.org /dev/tty
921 if [ ${crypt_filter_ret} -eq 0 ]
923 good_msg "LUKS device ${LUKS_DEVICE} opened" ${CRYPT_SILENT}
926 bad_msg "Failed to open LUKS device ${LUKS_DEVICE}" ${CRYPT_SILENT}
934 umount ${mntkey} 2>/dev/null >/dev/null
935 rmdir -p ${mntkey} 2>/dev/null >/dev/null
940 # if key is set but key device isn't, find it
942 [ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \
943 && sleep 6 && bootstrapKey "ROOT"
945 if [ -n "${CRYPT_ROOT}" ]; then
947 if [ -n "${REAL_ROOT}" ]
952 REAL_ROOT="/dev/mapper/root"
956 # same for swap, but no need to sleep if root was unencrypted
957 [ -n "${CRYPT_SWAP_KEY}" ] && [ -z "${CRYPT_SWAP_KEYDEV}" ] \
958 && { [ -z "${CRYPT_ROOT}" ] && sleep 6; bootstrapKey "SWAP"; }
960 if [ -n "${CRYPT_SWAP}" ]; then
962 if [ -z "${REAL_RESUME}" ]
964 # Resume from swap as default
965 REAL_RESUME="/dev/mapper/swap"
971 # Sleep a specific number of seconds if SDELAY is set
974 good_msg "Waiting ${SDELAY} seconds..."
976 elif [ "${CDROOT}" = '1' ]
978 # many CD/DVD drives require extra sleep, especially when
979 # connected via USB. Many people reported that 1 second sleep
980 # is not enough on their notebooks, that's why sleep 3, when booting
981 # off a livecd is a better default.
984 good_msg 'Hint: Use parameter scandelay[=seconds] if you need waiting here'
989 # if QUIET is set make the kernel less chatty
990 [ -n "$QUIET" ] && echo '0' > /proc/sys/kernel/printk
994 # if QUIET is set make the kernel less chatty
995 [ -n "$QUIET" ] && echo '6' > /proc/sys/kernel/printk
1000 if [ "${CDROOT}" = '1' ]
1002 if [ -x /${CDROOT_PATH}/cdupdate.sh ]
1004 good_msg "Running cdupdate.sh"
1005 ${CDROOT_PATH}/cdupdate.sh
1008 bad_msg "Executing cdupdate.sh failed!"
1012 good_msg 'No cdupdate.sh script found, skipping...'
1018 # start BTRFS volume detection, if available
1019 [ -x /sbin/btrfsctl ] && /sbin/btrfsctl -a
1025 [ -z "$1" ] && device="${REAL_ROOT}" || device="$1"
1026 [ -z "${device}" ] && return # LiveCD
1028 if [ `echo ${device}|sed -e 's#\(luks:\)\?\(/dev/md\)[[:digit:]]\+#\2#'` = "/dev/md" ]
1030 good_msg 'Detected real_root as a md device. Setting up the device node...'
1031 MD_NUMBER=`echo ${device}|sed -e 's#\(luks:\)\?/dev/md\([[:digit:]]\+\)#\2#'`
1032 if [ ! -e /dev/md${MD_NUMBER} ]
1034 mknod /dev/md${MD_NUMBER} b 9 ${MD_NUMBER} >/dev/null 2>&1
1035 [ $? -ne 0 ] && bad_msg "Creation of /dev/md${MD_NUMBER} failed..."
1037 mdstart ${MDPART} /dev/md${MD_NUMBER}
1041 do_rundebugshell() {
1042 good_msg 'Type "exit" to continue with normal bootup.'
1043 [ -x /bin/sh ] && /bin/sh || /bin/ash
1049 good_msg 'Starting debug shell as requested by "debug" option.'
1055 if [ -d /proc/suspend2 -o -d /sys/power/suspend2 -o -d /sys/power/tuxonice ]; then
1063 # determine swap resume partition
1064 local device=$(ls -lL "${REAL_RESUME}" | sed 's/\ */ /g' | cut -d \ -f 5-6 | sed 's/,\ */:/')
1065 [ -f /sys/power/resume ] && echo "${device}" > /sys/power/resume
1070 if grep "splash=" /proc/cmdline > /dev/null 2>&1; then
1071 splash_theme=$(cat /proc/cmdline | sed 's/.*splash=/splash=/' | sed 's/ .*//' | sed 's/.*theme://' | sed 's/,.*//')
1074 local tuxonice_userui_program="/sys/power/tuxonice/user_interface/program"
1075 local tuxonice_do_resume="/sys/power/tuxonice/do_resume"
1076 local tuxonice_resumedev="/sys/power/tuxonice/resume"
1077 local tuxonice_replace_swsusp="/sys/power/tuxonice/replace_swsusp"
1080 # Backward compatibility
1082 if [ -e /sys/power/suspend2 ]; then
1083 tuxonice_userui_program="/sys/power/suspend2/user_interface/program"
1084 tuxonice_do_resume="/sys/power/suspend2/do_resume"
1085 tuxonice_resumedev="/sys/power/suspend2/resume"
1086 tuxonice_replace_swsusp="/sys/power/suspend2/replace_swsusp"
1087 elif [ -e /proc/suspend2 ]; then
1088 tuxonice_userui_program="/proc/suspend2/userui_program"
1089 tuxonice_do_resume="/proc/suspend2/do_resume"
1090 tuxonice_resumedev="/proc/suspend2/resume"
1091 tuxonice_replace_swsusp="/proc/suspend2/replace_swsusp"
1094 # if 'use_swsusp' is given, use swsusp instead
1095 if grep "use_swsusp" /proc/cmdline > /dev/null 2>&1; then
1096 echo 0 > ${tuxonice_replace_swsusp}
1101 modules_scan tuxonice
1103 # we both configure tuxonice and activate resuming,
1104 # however the kernel will resume only if an image is found
1106 if ! grep suspend_noui /proc/cmdline > /dev/null 2>&1; then
1107 which suspend2ui_text > /dev/null 2>&1 && which suspend2ui_text > "${tuxonice_userui_program}"
1108 which tuxoniceui_text > /dev/null 2>&1 && which tuxoniceui_text > "${tuxonice_userui_program}"
1110 if [ -n "${splash_theme}" ]; then
1111 ln -s /etc/splash/${splash_theme} /etc/splash/suspend2
1112 ln -s /etc/splash/${splash_theme} /etc/splash/tuxonice
1114 which suspend2ui_fbsplash > /dev/null 2>&1 && which suspend2ui_fbsplash > "${tuxonice_userui_program}"
1115 which tuxoniceui_fbsplash > /dev/null 2>&1 && which tuxoniceui_fbsplash > "${tuxonice_userui_program}"
1119 echo "${REAL_RESUME}" > "${tuxonice_resumedev}"
1120 echo > "${tuxonice_do_resume}"
1124 for loop in ${LOOPS}
1126 if [ -e "${CDROOT_PATH}""${loop}" ]
1134 LOOPTYPE="${LOOP##*.}"
1135 [ "${LOOPTYPE}" == "loop" ] && LOOPTYPE="normal"
1136 [ "${LOOP}" == "/zisofs" ] && LOOPTYPE="${LOOP#/}"
1137 [ -z "${LOOPTYPE}" ] && LOOPTYPE="noloop"
1141 echo $(( $(hexdump -n 4 -s $((316 + 12 * $2)) -e '"%i"' $1) * 512))
1144 setup_squashfs_aufs() {
1146 # Setup aufs directories and vars
1147 local overlay=/mnt/overlay
1148 local static=/mnt/livecd
1150 for i in "${overlay}" "${static}"; do
1151 [ ! -d "${i}" ] && mkdir -p "${i}"
1153 good_msg "Loading aufs"
1154 modprobe aufs > /dev/null 2>&1
1156 mount -t squashfs -o loop,ro "${CDROOT_PATH}/${LOOPEXT}${LOOP}" "${static}"
1157 mount -t tmpfs none "${overlay}"
1158 mount -t aufs -o br:${overlay}:${static} aufs "${NEW_ROOT}"
1160 [ ! -d "${NEW_ROOT}${overlay}" ] && mkdir -p "${NEW_ROOT}${overlay}"
1161 [ ! -d "${NEW_ROOT}${static}" ] && mkdir -p "${NEW_ROOT}${static}"
1162 echo "aufs / aufs defaults 0 0" > "${NEW_ROOT}"/etc/fstab
1163 for i in "${overlay}" "${static}"; do mount --move "${i}" "${NEW_ROOT}${i}"; done
1165 # have handy /mnt/cdrom (CDROOT_PATH) as well
1166 local new_cdroot="${NEW_ROOT}${CDROOT_PATH}"
1167 [ ! -d "${new_cdroot}" ] && mkdir -p "${new_cdroot}"
1168 mount --bind "${CDROOT_PATH}" "${new_cdroot}"
1175 if [ "${USE_UNIONFS_NORMAL}" = '1' ]
1177 # Directory used for rw changes in union mount filesystem
1182 # CHANGES=$MEMORY/unionfs_changes/default
1184 # CHANGES=$MEMORY/unionfs_changes/$UID
1187 # mkdir -p ${MEMORY}
1189 good_msg "Loading fuse module"
1190 modprobe fuse > /dev/null 2>&1
1191 # if [ -n "${UNIONFS}" ]
1193 # CHANGESDEV=${UNIONFS}
1194 # good_msg "mounting $CHANGESDEV to $MEMORY for unionfs support"
1195 # mount -t auto $CHANGESDEV $MEMORY
1196 # # mount tmpfs only in the case when changes= boot parameter was
1197 # # empty or we were not able to mount the storage device
1199 # if [ ${ret} -ne 0 ]
1201 # bad_msg "mount of $CHANGESDEV failed falling back to ramdisk based unionfs"
1202 # mount -t tmpfs tmpfs $MEMORY
1204 # if [ "${CDROOT}" -eq '1' -a ! -f ${MEMORY}/livecd.unionfs ]
1207 # bad_msg "failed to find livecd.unionfs file on $CHANGESDEV"
1208 # bad_msg "create a livecd.unionfs file on this device if you wish to use it for unionfs"
1209 # bad_msg "falling back to ramdisk based unionfs for safety"
1210 # mount -t tmpfs tmpfs $MEMORY
1213 # good_msg "Mounting ramdisk to $MEMORY for unionfs support..."
1214 # mount -t tmpfs tmpfs $MEMORY
1220 # mount -t unionfs -o dirs=$CHANGES=rw unionfs ${UNION}
1221 good_msg "Creating union mount"
1222 unionfs -o allow_other,cow,noinitgroups,suid,dev,default_permissions,use_ino ${rw_dir}=RW:${ro_dir}=RO ${UNION} 2>/dev/null
1226 bad_msg "Can't setup union mount!"
1227 USE_UNIONFS_NORMAL=0
1229 [ ! -d "${NEW_ROOT}${CDROOT_PATH}" ] && mkdir -p "${NEW_ROOT}${CDROOT_PATH}"
1230 mount --bind "${CDROOT_PATH}" "${NEW_ROOT}${CDROOT_PATH}"
1232 USE_UNIONFS_NORMAL=0
1239 /^[[:blank:]]*#/ { next }
1241 ' ${NEW_ROOT}/etc/initramfs.mounts
1246 [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
1248 /^[[:blank:]]*#/ { next }
1249 $2 == fs { print $3 }
1250 ' ${NEW_ROOT}/etc/fstab
1255 [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
1257 /^[[:blank:]]*#/ { next }
1258 $2 == fs { print $4 }
1259 ' ${NEW_ROOT}/etc/fstab
1264 [ -e "${NEW_ROOT}"/etc/fstab ] || return 1
1266 /^[[:blank:]]*#/ { next }
1267 $2 == fs { print $1 }
1268 ' ${NEW_ROOT}/etc/fstab
1271 # If the kernel is handed a mount option is does not recognize, it WILL fail to
1272 # mount. util-linux handles auto/noauto, but busybox passes it straight to the kernel
1273 # which then rejects the mount.
1274 # To make like a little easier, busybox mount does not care about leading,
1275 # trailing or duplicate commas.
1276 strip_mount_options()
1278 sed -r 's/(,|^)(no)?auto(,|$)/,/g'