00-crypt.sh: delay the initialization of md devices until the end of start_luks

This will make possible to avoid to create degraded md devices
master v38
Fabio Erculiani 11 years ago
parent 451fac91b4
commit a2f34d906b

@ -62,7 +62,7 @@ _open_luks() {
real_dev="${REAL_RESUME}" real_dev="${REAL_RESUME}"
fi fi
local exit_st= luks_device= local exit_st=0 luks_device=
for luks_device in ${luks_devices}; do for luks_device in ${luks_devices}; do
good_msg "Working on device ${luks_device}..." good_msg "Working on device ${luks_device}..."
@ -70,7 +70,6 @@ _open_luks() {
while true; do while true; do
local gpg_cmd="" local gpg_cmd=""
exit_st=1
# do not force the link to /dev/mapper/root # do not force the link to /dev/mapper/root
# but rather use the value from root=, which is # but rather use the value from root=, which is
@ -223,13 +222,19 @@ _open_luks() {
&& mv /dev/tty.org /dev/tty && mv /dev/tty.org /dev/tty
if [ "${ret}" = "0" ]; then if [ "${ret}" = "0" ]; then
exit_st=0
good_msg "LUKS device ${luks_device} opened" good_msg "LUKS device ${luks_device} opened"
# This is fine if the crypt device is a physical device # Note 1: This is fine if the crypt device is a physical device
# like /dev/sdaX, however, if we have cryptsetup inside # like /dev/sdaX, however, if we have cryptsetup inside
# LVM, we must tweak REAL_ROOT if there is no device node. # LVM, we must tweak REAL_ROOT if there is no device node.
start_volumes # this should create /dev/mapper links # Note 2: we should not activate md arrays yet, because
# they could be started in degraded mode and mdadm is so stupid
# that it may end up creating multiple md devices with the
# same UUID... Let's postpone this for the end
( USE_MDADM=0
USE_DMRAID_NORMAL=0
start_volumes # this creates /dev/mapper links
)
if echo "${real_dev}" | grep -q "^/dev/mapper/"; then if echo "${real_dev}" | grep -q "^/dev/mapper/"; then
if [ ! -e "${real_dev}" ]; then if [ ! -e "${real_dev}" ]; then
# WARN: while for ltype=SWAP this may not be a problem, # WARN: while for ltype=SWAP this may not be a problem,
@ -267,11 +272,14 @@ start_luks() {
return 1 return 1
fi fi
local root_or_swap=
# if key is set but key device isn't, find it # if key is set but key device isn't, find it
[ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \ [ -n "${CRYPT_ROOT_KEY}" ] && [ -z "${CRYPT_ROOT_KEYDEV}" ] \
&& _bootstrap_key "ROOT" && _bootstrap_key "ROOT"
if [ -n "${CRYPT_ROOTS}" ]; then if [ -n "${CRYPT_ROOTS}" ]; then
root_or_swap=1
if _open_luks "root"; then if _open_luks "root"; then
# force REAL_ROOT= to some value if not set # force REAL_ROOT= to some value if not set
# this is mainly for backward compatibility, # this is mainly for backward compatibility,
@ -285,9 +293,17 @@ start_luks() {
&& _bootstrap_key "SWAP" && _bootstrap_key "SWAP"
if [ -n "${CRYPT_SWAPS}" ]; then if [ -n "${CRYPT_SWAPS}" ]; then
root_or_swap=1
if _open_luks "swap"; then if _open_luks "swap"; then
# force REAL_RESUME= to some value if not set # force REAL_RESUME= to some value if not set
[ -z "${REAL_RESUME}" ] && REAL_RESUME="/dev/mapper/swap" [ -z "${REAL_RESUME}" ] && REAL_RESUME="/dev/mapper/swap"
fi fi
fi fi
if [ -n "${root_or_swap}" ]; then
# We postponed the initialization of raid devices
# in order to avoid to assemble possibly degraded
# arrays.
start_md_volumes
fi
} }

Loading…
Cancel
Save