mirror of
https://salsa.debian.org/kernel-team/initramfs-tools.git
synced 2026-01-26 15:39:08 +00:00
Since we now invoke blkid to resolve block device IDs rather than relying on symlinks under /dev/disk, resolve_device just doesn't work until the specified device exists. So we need to use it in the multiple existence checks in local_device_setup, and nowhere else. Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
199 lines
4.3 KiB
Bash
199 lines
4.3 KiB
Bash
# Local filesystem mounting -*- shell-script -*-
|
|
|
|
local_top()
|
|
{
|
|
if [ "${local_top_used}" != "yes" ]; then
|
|
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
|
|
run_scripts /scripts/local-top
|
|
[ "$quiet" != "y" ] && log_end_msg
|
|
fi
|
|
local_top_used=yes
|
|
}
|
|
|
|
local_block()
|
|
{
|
|
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-block"
|
|
run_scripts /scripts/local-block "$@"
|
|
[ "$quiet" != "y" ] && log_end_msg
|
|
}
|
|
|
|
local_premount()
|
|
{
|
|
if [ "${local_premount_used}" != "yes" ]; then
|
|
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
|
|
run_scripts /scripts/local-premount
|
|
[ "$quiet" != "y" ] && log_end_msg
|
|
fi
|
|
local_premount_used=yes
|
|
}
|
|
|
|
local_bottom()
|
|
{
|
|
if [ "${local_premount_used}" = "yes" ] || [ "${local_top_used}" = "yes" ]; then
|
|
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
|
|
run_scripts /scripts/local-bottom
|
|
[ "$quiet" != "y" ] && log_end_msg
|
|
fi
|
|
local_premount_used=no
|
|
local_top_used=no
|
|
}
|
|
|
|
# $1=device ID to mount
|
|
# $2=optionname (for root and etc)
|
|
# Sets $DEV to the resolved device node
|
|
local_device_setup()
|
|
{
|
|
local dev_id="$1"
|
|
local name="$2"
|
|
local real_dev
|
|
|
|
wait_for_udev 10
|
|
|
|
# Load ubi with the correct MTD partition and return since fstype
|
|
# doesn't work with a char device like ubi.
|
|
if [ -n "$UBIMTD" ]; then
|
|
modprobe ubi mtd=$UBIMTD
|
|
DEV="${dev_id}"
|
|
return
|
|
fi
|
|
|
|
# Don't wait for a device that doesn't have a corresponding
|
|
# device in /dev and isn't resolvable by blkid (e.g. mtd0)
|
|
if [ "${dev_id#/dev}" = "${dev_id}" ] &&
|
|
[ "${dev_id#*=}" = "${dev_id}" ]; then
|
|
DEV="${dev_id}"
|
|
return
|
|
fi
|
|
|
|
# If the root device hasn't shown up yet, give it a little while
|
|
# to allow for asynchronous device discovery (e.g. USB). We
|
|
# also need to keep invoking the local-block scripts in case
|
|
# there are devices stacked on top of those.
|
|
if ! real_dev=$(resolve_device "${dev_id}") ||
|
|
! get_fstype "${real_dev}" >/dev/null; then
|
|
log_begin_msg "Waiting for ${name} file system"
|
|
|
|
# Timeout is max(30, rootdelay) seconds (approximately)
|
|
slumber=30
|
|
if [ ${ROOTDELAY:-0} -gt $slumber ]; then
|
|
slumber=$ROOTDELAY
|
|
fi
|
|
|
|
while true; do
|
|
sleep 1
|
|
local_block "${dev_id}"
|
|
if real_dev=$(resolve_device "${dev_id}") &&
|
|
get_fstype "${real_dev}" >/dev/null; then
|
|
wait_for_udev 10
|
|
log_end_msg 0
|
|
break
|
|
fi
|
|
slumber=$(( ${slumber} - 1 ))
|
|
if [ ${slumber} -eq 0 ]; then
|
|
log_end_msg 1 || true
|
|
break
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# We've given up, but we'll let the user fix matters if they can
|
|
while ! real_dev=$(resolve_device "${dev_id}") ||
|
|
! get_fstype "${real_dev}" >/dev/null; do
|
|
echo "Gave up waiting for ${name} device. Common problems:"
|
|
echo " - Boot args (cat /proc/cmdline)"
|
|
echo " - Check rootdelay= (did the system wait long enough?)"
|
|
if [ "${name}" = root ]; then
|
|
echo " - Check root= (did the system wait for the right device?)"
|
|
fi
|
|
echo " - Missing modules (cat /proc/modules; ls /dev)"
|
|
panic "ALERT! ${dev_id} does not exist. Dropping to a shell!"
|
|
done
|
|
|
|
DEV="${real_dev}"
|
|
}
|
|
|
|
local_mount_root()
|
|
{
|
|
local_top
|
|
local_device_setup "${ROOT}" root
|
|
ROOT="${DEV}"
|
|
|
|
# Get the root filesystem type if not set
|
|
if [ -z "${ROOTFSTYPE}" ]; then
|
|
FSTYPE=$(get_fstype "${ROOT}")
|
|
else
|
|
FSTYPE=${ROOTFSTYPE}
|
|
fi
|
|
|
|
local_premount
|
|
|
|
if [ "${readonly}" = "y" ]; then
|
|
roflag=-r
|
|
else
|
|
roflag=-w
|
|
fi
|
|
|
|
# FIXME This has no error checking
|
|
modprobe ${FSTYPE}
|
|
|
|
checkfs ${ROOT} root
|
|
|
|
# FIXME This has no error checking
|
|
# Mount root
|
|
if [ "${FSTYPE}" != "unknown" ]; then
|
|
mount ${roflag} -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} ${rootmnt}
|
|
else
|
|
mount ${roflag} ${ROOTFLAGS} ${ROOT} ${rootmnt}
|
|
fi
|
|
}
|
|
|
|
local_mount_fs()
|
|
{
|
|
read_fstab_entry "$1"
|
|
|
|
local_device_setup "$MNT_FSNAME" "$1"
|
|
MNT_FSNAME="${DEV}"
|
|
|
|
local_premount
|
|
|
|
if [ "${readonly}" = "y" ]; then
|
|
roflag=-r
|
|
else
|
|
roflag=-w
|
|
fi
|
|
|
|
# FIXME This has no error checking
|
|
modprobe "${MNT_TYPE}"
|
|
|
|
if [ "$MNT_PASS" != 0 ]; then
|
|
checkfs "$MNT_FSNAME" "$MNT_DIR"
|
|
fi
|
|
|
|
# FIXME This has no error checking
|
|
# Mount filesystem
|
|
mount ${roflag} -t "${MNT_TYPE}" -o "${MNT_OPTS}" "$MNT_FSNAME" "${rootmnt}${MNT_DIR}"
|
|
}
|
|
|
|
mountroot()
|
|
{
|
|
local_mount_root
|
|
}
|
|
|
|
mount_top()
|
|
{
|
|
# Note, also called directly in case it's overridden.
|
|
local_top
|
|
}
|
|
|
|
mount_premount()
|
|
{
|
|
# Note, also called directly in case it's overridden.
|
|
local_premount
|
|
}
|
|
|
|
mount_bottom()
|
|
{
|
|
# Note, also called directly in case it's overridden.
|
|
local_bottom
|
|
}
|