]>
git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/scripts/update-bootloader
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_bootloader_device
() {
29 if find_device
"${mp}"; then
37 function find_device
() {
38 local mountpoint
="${1}"
41 local dev mp fs flags rest
42 while read -r dev mp fs flags rest
; do
43 # Skip unwanted entries
44 [ "${dev}" = "rootfs" ] && continue
46 if [ "${mp}" = "${mountpoint}" ] && [ -b "${dev}" ]; then
47 root
="$(basename "${dev}")"
52 # Get the actual device from the partition that holds /
53 while [ -n "${root}" ]; do
54 if [ -e "/sys/block/${root}" ]; then
59 # Remove last character
66 function device_is_mdraid
() {
69 [ -d "/sys/block/${device}/md" ]
72 function mdraid_get_slaves
() {
76 for slave
in /sys
/block
/${device}/slaves
/*; do
81 function grub_update_config
() {
82 echo "Updating configuration..."
84 if ! grub-mkconfig
-o /boot
/grub
/grub.cfg
&>/dev
/null
; then
85 echo "Could not update configuration. Aborting." >&2
92 function grub_install
() {
95 echo "Installing GRUB on ${device}..."
97 if [ ! -b "${device}" ]; then
98 echo "${device} does not exist or is not a block device" >&2
103 for args
in "" "--force"; do
104 if grub-install
${GRUB_INSTALL_ARGS} ${args} "${device}" &>/dev/null; then
109 echo "Could not
install GRUB on
${device}" >&2
114 # Find the root device
115 local device="$
(find_bootloader_device
)"
116 if [ -z "${device}" ]; then
117 echo "Could not
find root device. Aborting.
" >&2
121 echo "Found bootloader device
: /dev
/${device}"
123 # Update configuration files
124 grub_update_config || exit $?
126 # Handle mdraid devices
127 if device_is_mdraid "${device}"; then
129 for slave in $(mdraid_get_slaves "${device}"); do
130 grub_install "/dev
/${slave}"
133 # Handle normal block devices
135 grub_install "/dev
/${device}"