linuxrc: move root device detection/init code to rootdev_init

master
Fabio Erculiani 12 years ago
parent 37121be638
commit faf020424d

@ -1698,3 +1698,188 @@ ensure_initramfs_mounts() {
fi fi
done done
} }
rootdev_init() {
good_msg "Initializing root device..."
while true
do
local got_good_root=
while [ "${got_good_root}" != '1' ]
do
case "${REAL_ROOT}" in
LABEL=*|UUID=*)
ROOT_DEV=""
retval=1
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
retval=$?
fi
if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
good_msg "Detected real_root=${ROOT_DEV}"
REAL_ROOT="${ROOT_DEV}"
else
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
continue
fi
;;
ZFS*)
if [ "${USE_ZFS}" = '0' ]; then
prompt_user "REAL_ROOT" "root block device"
continue
fi
ROOT_DEV="${REAL_ROOT#*=}"
if [ "${ROOT_DEV}" != 'ZFS' ]
then
if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
then
got_good_root=1;
REAL_ROOT=${ROOT_DEV}
ROOTFSTYPE=zfs
else
bad_msg "${ROOT_DEV} is not a filesystem"
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
continue
fi
else
BOOTFS=$(/sbin/zpool list -H -o bootfs)
if [ "${BOOTFS}" != '-' ]
then
for i in ${BOOTFS}
do
zfs get type ${i} > /dev/null
retval=$?
if [ ${retval} -eq 0 ]; then
got_good_root=1
REAL_ROOT=${i}
ROOTFSTYPE=zfs
break
fi
done
else
got_good_root=0
fi
fi
if [ ${got_good_root} -ne 1 ]; then
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
fi
continue
;;
esac
if [ "${REAL_ROOT}" = '' ]
then
# No REAL_ROOT determined/specified. Prompt user for root block device.
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
# Check for a block device or NFS
elif [ -b "${REAL_ROOT}" ] || is_nfs
then
got_good_root=1
else
bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
REAL_ROOT=""
got_good_root=0
fi
done
if [ "${got_good_root}" = "1" ] && is_livecd && ! is_nfs
then
# CD already mounted; no further checks necessary
break
elif [ "${LOOPTYPE}" = "sgimips" ]
then
# sgimips mounts the livecd root partition directly
# there is no isofs filesystem to worry about
break
else
good_msg "Mounting $REAL_ROOT as root..."
if [ "${ROOTFSTYPE}" = 'zfs' ]
then
if [ "$(zfs get -H -o value mountpoint ${REAL_ROOT})" = 'legacy' ]
then
MOUNT_STATE=rw
else
MOUNT_STATE=rw,zfsutil
fi
else
MOUNT_STATE=ro
fi
# Try to mount the device as ${NEW_ROOT}
if is_nfs; then
findnfsmount
else
# mount ro so fsck doesn't barf later
if [ "${REAL_ROOTFLAGS}" = '' ]; then
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
else
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
fi
fi
# If mount is successful break out of the loop
# else not a good root and start over.
if [ "$?" = '0' ]
then
# now that the root filesystem is mounted, before
# checking the validity of ${NEW_ROOT} and ${REAL_INIT},
# ensure that ${NEW_ROOT}/etc/initramfs.mounts entries
# are mounted.
ensure_initramfs_mounts
# NFS does not need further checks here.
if is_nfs; then
break
fi
if [ ! -d "${NEW_ROOT}/dev" ]; then
_msg="The filesystem ${REAL_ROOT},"
_msg="${_msg} mounted at ${NEW_ROOT}"
_msg="${_msg} does not contain /dev"
_msg="${_msg}, init will likely fail..."
bad_msg "${_msg}"
fi
if [ ! -x "${NEW_ROOT}${REAL_INIT:-/sbin/init}" ]; then
_msg="The filesystem ${REAL_ROOT},"
_msg="${_msg} mounted at ${NEW_ROOT}"
_msg="${_msg} does not contain a valid"
_msg="${_msg} init=${REAL_INIT}"
bad_msg "${_msg}"
fi
break
else
bad_msg "Could not mount specified ROOT, try again"
got_good_root=0
REAL_ROOT=''
fi
fi
done
}

@ -296,187 +296,7 @@ rundebugshell "before setting up the root filesystem"
is_livecd && livecd_init is_livecd && livecd_init
# Determine root device # Determine root device
good_msg "Determining root device..." rootdev_init
while true
do
while [ "${got_good_root}" != '1' ]
do
case "${REAL_ROOT}" in
LABEL=*|UUID=*)
ROOT_DEV=""
retval=1
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(findfs "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(busybox findfs "${REAL_ROOT}" 2>/dev/null)
retval=$?
fi
if [ ${retval} -ne 0 ]; then
ROOT_DEV=$(blkid -o device -l -t "${REAL_ROOT}")
retval=$?
fi
if [ ${retval} -eq 0 ] && [ -n "${ROOT_DEV}" ]; then
good_msg "Detected real_root=${ROOT_DEV}"
REAL_ROOT="${ROOT_DEV}"
else
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
continue
fi
;;
ZFS*)
if [ "${USE_ZFS}" = '0' ]; then
prompt_user "REAL_ROOT" "root block device"
continue
fi
ROOT_DEV="${REAL_ROOT#*=}"
if [ "${ROOT_DEV}" != 'ZFS' ]
then
if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
then
got_good_root=1;
REAL_ROOT=${ROOT_DEV}
ROOTFSTYPE=zfs
else
bad_msg "${ROOT_DEV} is not a filesystem"
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
continue
fi
else
BOOTFS=$(/sbin/zpool list -H -o bootfs)
if [ "${BOOTFS}" != '-' ]
then
for i in ${BOOTFS}
do
zfs get type ${i} > /dev/null
retval=$?
if [ ${retval} -eq 0 ]; then
got_good_root=1
REAL_ROOT=${i}
ROOTFSTYPE=zfs
break
fi
done
else
got_good_root=0
fi
fi
if [ ${got_good_root} -ne 1 ]; then
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
fi
continue
;;
esac
if [ "${REAL_ROOT}" = '' ]
then
# No REAL_ROOT determined/specified. Prompt user for root block device.
prompt_user "REAL_ROOT" "root block device"
got_good_root=0
# Check for a block device or NFS
elif [ -b "${REAL_ROOT}" ] || is_nfs
then
got_good_root=1
else
bad_msg "Block device ${REAL_ROOT} is not a valid root device..."
REAL_ROOT=""
got_good_root=0
fi
done
if [ "${got_good_root}" = "1" ] && is_livecd && ! is_nfs
then
# CD already mounted; no further checks necessary
break
elif [ "${LOOPTYPE}" = "sgimips" ]
then
# sgimips mounts the livecd root partition directly
# there is no isofs filesystem to worry about
break
else
good_msg "Mounting $REAL_ROOT as root..."
if [ "${ROOTFSTYPE}" = 'zfs' ]
then
if [ "$(zfs get -H -o value mountpoint ${REAL_ROOT})" = 'legacy' ]
then
MOUNT_STATE=rw
else
MOUNT_STATE=rw,zfsutil
fi
else
MOUNT_STATE=ro
fi
# Try to mount the device as ${NEW_ROOT}
if is_nfs; then
findnfsmount
else
# mount ro so fsck doesn't barf later
if [ "${REAL_ROOTFLAGS}" = '' ]; then
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE} ${REAL_ROOT} ${NEW_ROOT}
else
good_msg "Using mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS}"
mount -t ${ROOTFSTYPE} -o ${MOUNT_STATE},${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
fi
fi
# If mount is successful break out of the loop
# else not a good root and start over.
if [ "$?" = '0' ]
then
# now that the root filesystem is mounted, before
# checking the validity of ${NEW_ROOT} and ${REAL_INIT},
# ensure that ${NEW_ROOT}/etc/initramfs.mounts entries
# are mounted.
ensure_initramfs_mounts
# NFS does not need further checks here.
if is_nfs; then
break
fi
if [ ! -d "${NEW_ROOT}/dev" ]; then
_msg="The filesystem ${REAL_ROOT},"
_msg="${_msg} mounted at ${NEW_ROOT}"
_msg="${_msg} does not contain /dev"
_msg="${_msg}, init will likely fail..."
bad_msg "${_msg}"
fi
if [ ! -x "${NEW_ROOT}${REAL_INIT:-/sbin/init}" ]; then
_msg="The filesystem ${REAL_ROOT},"
_msg="${_msg} mounted at ${NEW_ROOT}"
_msg="${_msg} does not contain a valid"
_msg="${_msg} init=${REAL_INIT}"
bad_msg "${_msg}"
fi
break
else
bad_msg "Could not mount specified ROOT, try again"
got_good_root=0
REAL_ROOT=''
fi
fi
done
# End determine root device
# If CD root is set determine the looptype to boot # If CD root is set determine the looptype to boot
if is_livecd if is_livecd

Loading…
Cancel
Save