]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/update-bootloader
b011b72ed1f0085bdcd707e9846fbbf2a51a0bf3
2 ############################################################################
4 # This file is part of the IPFire Firewall. #
6 # IPFire is free software; you can redistribute it and/or modify #
7 # it under the terms of the GNU General Public License as published by #
8 # the Free Software Foundation; either version 2 of the License, or #
9 # (at your option) any later version. #
11 # IPFire is distributed in the hope that it will be useful, #
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14 # GNU General Public License for more details. #
16 # You should have received a copy of the GNU General Public License #
17 # along with IPFire; if not, write to the Free Software #
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
20 # Copyright (C) 2014 IPFire Team <info@ipfire.org>. #
22 ############################################################################
24 GRUB_INSTALL_ARGS
="--no-floppy --recheck"
26 function find_root_device
() {
27 # rootfs / rootfs rw 0 0
30 local dev mp fs flags rest
31 while read -r dev mp fs flags rest
; do
32 # Skip unwanted entries
33 [ "${dev}" = "rootfs" ] && continue
35 if [ "${mp}" = "/" ] && [ -b "${dev}" ]; then
36 root
="$(basename "${dev}")"
41 # Get the actual device from the partition that holds /
42 if [ -n "${root}" ]; then
43 while [ -n "${root}" ]; do
44 if [ -e "/sys/block/${root}" ]; then
49 # Remove last character
57 function root_device_is_mdraid
() {
60 [ -d "/sys/block/${device}/md" ]
63 function mdraid_get_slaves
() {
67 for slave
in /sys
/block
/${device}/slaves
/*; do
72 function grub_update_config
() {
73 echo "Updating configuration..."
75 if ! grub-mkconfig
-o /boot
/grub
/grub.cfg
&>/dev
/null
; then
76 echo "Could not update configuration. Aborting." >&2
83 function grub_install
() {
86 echo "Installing GRUB on ${device}..."
88 if [ ! -b "${device}" ]; then
89 echo "${device} does not exist or is not a block device" >&2
94 for args
in "" "--force"; do
95 if grub-install
${GRUB_INSTALL_ARGS} ${args} "${device}" &>/dev/null; then
100 echo "Could not
install GRUB on
${device}" >&2
105 # Find the root device
106 local device="$
(find_root_device
)"
107 if [ -z "${device}" ]; then
108 echo "Could not
find root device. Aborting.
" >&2
112 echo "Found root device
: /dev
/${device}"
114 # Update configuration files
115 grub_update_config || exit $?
117 # Handle mdraid devices
118 if root_device_is_mdraid "${device}"; then
120 for slave in $(mdraid_get_slaves "${device}"); do
121 grub_install "/dev
/${slave}"
124 # Handle normal block devices
126 grub_install "/dev
/${device}"