Skip to content

Commit

Permalink
Added degraded-raid-fix recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhartsock committed Jan 20, 2014
1 parent 8f4e9c8 commit f8076a1
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -18,6 +18,7 @@ The following platforms are supported by this cookbook, meaning that the recipes
## Recipes

* `mdadm` - The default recipe.
* `mdadm::degraded-raid-fix` - Recipe for fixing a boot race condition where Ubuntu thinks the RAID is degraded.

# Usage

Expand Down
122 changes: 122 additions & 0 deletions files/default/mdadm-functions
@@ -0,0 +1,122 @@
#!/bin/sh

txt_message ()
{
if [ -x /bin/plymouth ] && plymouth --ping; then
return 0
else
echo "$@" >&2
fi
return 0
}

message()
{
if [ -x /bin/plymouth ] && plymouth --ping; then
plymouth message --text="$@"
else
echo "$@" >&2
fi
return 0
}


degraded_arrays()
{
udevadm settle
mdadm --misc --scan --detail --test >/dev/null 2>&1
return $((! $?))
}

mountroot_fail()
{
if degraded_arrays; then
txt_message "
** WARNING: There appears to be one or more degraded RAID devices **
The system may have suffered a hardware fault, such as a disk drive
failure. The root device may depend on the RAID devices being online. One
or more of the following RAID devices are degraded:
"
txt_message "`cat /proc/mdstat`"

BOOT_DEGRADED="false"
# Read BOOT_DEGRADED from file
if [ -r "/conf/conf.d/mdadm" ]; then
. /conf/conf.d/mdadm
fi
# But allow for overides on the kernel command line
for x in $(cat /proc/cmdline); do
case $x in
bootdegraded)
BOOT_DEGRADED="true"
;;
bootdegraded=*)
BOOT_DEGRADED=${x#bootdegraded=}
;;
esac
done
# Allow for a couple of permutations, {true|1|yes|on}
case "$BOOT_DEGRADED" in
1) BOOT_DEGRADED="true";;
yes) BOOT_DEGRADED="true";;
on) BOOT_DEGRADED="true";;
esac
# Check to see if user has already answered interactive question
# If they say anything other than "yes", the boot halts, so we
# can just set it to true to skip asking again.
if [ -f /run/.boot-degraded-asked ] ; then
BOOT_DEGRADED="true"
fi
# Finally, prompt interactively if the user has not specified
# to boot degraded either in a configuration file or as a
# kernel boot parameter
if [ "$BOOT_DEGRADED" != "true" ]; then
txt_message '
You may attempt to start the system anyway, or stop now and attempt
manual recovery operations. To do this automatically in the future,
add "bootdegraded=true" to the kernel boot options.
If you choose to start the degraded RAID, the system may boot normally,
but performance may be degraded, and a further hardware fault could
result in permanent data loss.
If you abort now, you will be provided with a recovery shell.
'
# Set a 15-second timeout for this question
ANSWER="unanswered"
if [ -x /bin/plymouth ] && plymouth --ping; then
plymouth display-message --text="
*** WARNING: Degraded RAID devices detected. ***
Press Y to start the degraded RAID or N to launch recovery shell
"
ANSWER=`plymouth watch-keystroke --keys='yYnN'`
else
read -t 15 -p "Do you wish to start the degraded RAID? [y/N]: " -r ANSWER
fi
echo "" > /run/.boot-degraded-asked
case "$ANSWER" in
unanswered) echo "Timed out" ;;
y*|Y*) BOOT_DEGRADED="true" ;;
*) BOOT_DEGRADED="false";;
esac
fi
if [ "$BOOT_DEGRADED" = "true" ]; then
message "Attempting to start the RAID in degraded mode..."
if mdadm --incremental --run --scan; then
message "Started the RAID in degraded mode."
return 0
else
if mdadm --assemble --scan --run; then
message "Started the RAID in degraded mode."
return 0
else
message "Could not start the RAID in degraded mode."
fi
fi
fi
fi
return 1
}
30 changes: 30 additions & 0 deletions recipes/degraded-raid-fix.rb
@@ -0,0 +1,30 @@
#
# Cookbook Name:: mdadm
# Recipe:: degraded-raid-fix
#
# This cookbook fixes problems on Ubuntu where the OS always
# thinks the RAID is degraded at boot. See below references
# for more information.
#
# References:
# http://ubuntuforums.org/showthread.php?t=1861516&page=2&p=11388915#post11388915
# https://bugs.launchpad.net/ubuntu/+source/mdadm/+bug/872220
# https://bugs.launchpad.net/ubuntu/+source/mdadm/+bug/990913
# https://bugs.launchpad.net/ubuntu/+source/mdadm/+bug/917520
#
#

cookbook_file 'mdadm-functions' do
path '/usr/share/initramfs-tools/scripts/mdadm-functions'
owner 'root'
group 'root'
mode '0755'
notifies :run, 'execute[update_initramfs]'
action :create
end

execute 'update_initramfs' do
command 'update-initramfs -u'
action :nothing
end

0 comments on commit f8076a1

Please sign in to comment.