update-bootloader: Search for /boot first and then /

The bootloader is usually installed on the /boot partition
if that exists. Some installations may mount / from a different
device, so we make sure to update the bootloader on the
right device.
This commit is contained in:
Michael Tremer
2015-01-01 16:36:51 +01:00
parent 91e56a59a4
commit 5946f1f9d0

View File

@@ -23,8 +23,19 @@
GRUB_INSTALL_ARGS="--no-floppy --recheck" GRUB_INSTALL_ARGS="--no-floppy --recheck"
function find_root_device() { function find_bootloader_device() {
# rootfs / rootfs rw 0 0 local mp
for mp in /boot /; do
if find_device "${mp}"; then
return 0
fi
done
return 1
}
function find_device() {
local mountpoint="${1}"
local root local root
local dev mp fs flags rest local dev mp fs flags rest
@@ -32,29 +43,27 @@ function find_root_device() {
# Skip unwanted entries # Skip unwanted entries
[ "${dev}" = "rootfs" ] && continue [ "${dev}" = "rootfs" ] && continue
if [ "${mp}" = "/" ] && [ -b "${dev}" ]; then if [ "${mp}" = "${mountpoint}" ] && [ -b "${dev}" ]; then
root="$(basename "${dev}")" root="$(basename "${dev}")"
break break
fi fi
done < /proc/mounts done < /proc/mounts
# Get the actual device from the partition that holds / # Get the actual device from the partition that holds /
if [ -n "${root}" ]; then while [ -n "${root}" ]; do
while [ -n "${root}" ]; do if [ -e "/sys/block/${root}" ]; then
if [ -e "/sys/block/${root}" ]; then echo "${root}"
echo "${root}" return 0
return 0 fi
fi
# Remove last character # Remove last character
root="${root::-1}" root="${root::-1}"
done done
fi
return 1 return 1
} }
function root_device_is_mdraid() { function device_is_mdraid() {
local device="${1}" local device="${1}"
[ -d "/sys/block/${device}/md" ] [ -d "/sys/block/${device}/md" ]
@@ -103,19 +112,19 @@ function grub_install() {
function main() { function main() {
# Find the root device # Find the root device
local device="$(find_root_device)" local device="$(find_bootloader_device)"
if [ -z "${device}" ]; then if [ -z "${device}" ]; then
echo "Could not find root device. Aborting." >&2 echo "Could not find root device. Aborting." >&2
exit 1 exit 1
fi fi
echo "Found root device: /dev/${device}" echo "Found bootloader device: /dev/${device}"
# Update configuration files # Update configuration files
grub_update_config || exit $? grub_update_config || exit $?
# Handle mdraid devices # Handle mdraid devices
if root_device_is_mdraid "${device}"; then if device_is_mdraid "${device}"; then
local slave local slave
for slave in $(mdraid_get_slaves "${device}"); do for slave in $(mdraid_get_slaves "${device}"); do
grub_install "/dev/${slave}" grub_install "/dev/${slave}"