public inbox for ipfire-scm@lists.ipfire.org
 help / color / mirror / Atom feed
From: git@ipfire.org
To: ipfire-scm@lists.ipfire.org
Subject: [git.ipfire.org] IPFire 2.x development tree branch, efi, updated. 12034118dd0cf631efef85edc5d0944055a7ef5f
Date: Fri, 20 Jul 2018 13:03:44 +0100	[thread overview]
Message-ID: <20180720120345.9E5521081BD5@git01.ipfire.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 12762 bytes --]

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "IPFire 2.x development tree".

The branch, efi has been updated
       via  12034118dd0cf631efef85edc5d0944055a7ef5f (commit)
       via  6cf5a533f50256e961023bed8300eef178ac398f (commit)
       via  43829df3bbc85e0bbdddbafeb91fd2fe6bccb6de (commit)
       via  befc0404976287adfd52f76dd9c3a4ab6afe2ab9 (commit)
       via  eadde44b05294152f88eeeb2401622dac6fd0f00 (commit)
       via  c1397b7ab39e6ddeed64e3c63ff7012f5659df84 (commit)
      from  46a4581db662d70e781d59782d2e24a4c2968968 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 12034118dd0cf631efef85edc5d0944055a7ef5f
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:59:00 2018 +0000

    installer: Run install-bootloader script instead of own code
    
    This allows us to keep the GRUB installation routine in one
    place only.
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

commit 6cf5a533f50256e961023bed8300eef178ac398f
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:53:55 2018 +0000

    partresize: Remove debugging line
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

commit 43829df3bbc85e0bbdddbafeb91fd2fe6bccb6de
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:53:24 2018 +0000

    partresize: Only regenerate configuration instead of re-installing GRUB
    
    This should not be necessary
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

commit befc0404976287adfd52f76dd9c3a4ab6afe2ab9
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:51:50 2018 +0000

    Move update-bootloader script into installer
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

commit eadde44b05294152f88eeeb2401622dac6fd0f00
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:47:35 2018 +0000

    update-bootloader: Allow passing device to install GRUB on
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

commit c1397b7ab39e6ddeed64e3c63ff7012f5659df84
Author: Michael Tremer <michael.tremer(a)ipfire.org>
Date:   Fri Jul 20 11:34:55 2018 +0000

    update-bootloader: Extend script to support EFI
    
    Signed-off-by: Michael Tremer <michael.tremer(a)ipfire.org>

-----------------------------------------------------------------------

Summary of changes:
 config/rootfiles/common/aarch64/stage2             |  1 -
 config/rootfiles/common/installer                  |  1 +
 config/rootfiles/common/stage2                     |  1 -
 config/rootfiles/common/x86_64/stage2              |  1 -
 src/initscripts/system/partresize                  |  6 +-
 src/installer/Makefile.am                          |  1 +
 src/installer/hw.c                                 | 47 +-----------
 src/installer/hw.h                                 |  3 -
 .../install-bootloader}                            | 88 +++++++++++++++++-----
 9 files changed, 75 insertions(+), 74 deletions(-)
 rename src/{scripts/update-bootloader => installer/install-bootloader} (67%)

Difference in files:
diff --git a/config/rootfiles/common/aarch64/stage2 b/config/rootfiles/common/aarch64/stage2
index 70a33d659..110114c47 100644
--- a/config/rootfiles/common/aarch64/stage2
+++ b/config/rootfiles/common/aarch64/stage2
@@ -103,7 +103,6 @@ usr/local/bin/scanhd
 usr/local/bin/settime
 usr/local/bin/timecheck
 usr/local/bin/timezone-transition
-usr/local/bin/update-bootloader
 usr/local/bin/update-lang-cache
 usr/local/bin/xt_geoip_build
 usr/local/bin/xt_geoip_update
diff --git a/config/rootfiles/common/installer b/config/rootfiles/common/installer
index ff8cda598..d4abb97aa 100644
--- a/config/rootfiles/common/installer
+++ b/config/rootfiles/common/installer
@@ -1,5 +1,6 @@
 #usr/bin/downloadsource.sh
 #usr/bin/execute-postinstall.sh
+usr/bin/install-bootloader
 #usr/bin/installer
 #usr/bin/start-networking.sh
 #usr/lib/dracut/modules.d/99installer
diff --git a/config/rootfiles/common/stage2 b/config/rootfiles/common/stage2
index a5ba6ae26..5665f2301 100644
--- a/config/rootfiles/common/stage2
+++ b/config/rootfiles/common/stage2
@@ -101,7 +101,6 @@ usr/local/bin/scanhd
 usr/local/bin/settime
 usr/local/bin/timecheck
 usr/local/bin/timezone-transition
-usr/local/bin/update-bootloader
 usr/local/bin/update-lang-cache
 usr/local/bin/xt_geoip_build
 usr/local/bin/xt_geoip_update
diff --git a/config/rootfiles/common/x86_64/stage2 b/config/rootfiles/common/x86_64/stage2
index 70a33d659..110114c47 100644
--- a/config/rootfiles/common/x86_64/stage2
+++ b/config/rootfiles/common/x86_64/stage2
@@ -103,7 +103,6 @@ usr/local/bin/scanhd
 usr/local/bin/settime
 usr/local/bin/timecheck
 usr/local/bin/timezone-transition
-usr/local/bin/update-bootloader
 usr/local/bin/update-lang-cache
 usr/local/bin/xt_geoip_build
 usr/local/bin/xt_geoip_update
diff --git a/src/initscripts/system/partresize b/src/initscripts/system/partresize
index 819d12885..2fad11251 100644
--- a/src/initscripts/system/partresize
+++ b/src/initscripts/system/partresize
@@ -38,12 +38,12 @@ case "${1}" in
 					echo "GRUB_SERIAL_COMMAND=\"serial --unit=0 --speed=115200\"" >> /etc/default/grub
 					sed -i -e "s|panic=10|& console=ttyS0,115200n8|g" /etc/default/grub
 				fi
-				/usr/local/bin/update-bootloader
+
+				# Re-generate GRUB configuration
+				/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg
 			fi
 			umount /boot > /dev/null
 
-			sleep 30
-
 			# Detect device
 			mount | while read -r dev tmp1 mountpoint tmp2; do
 				[ "${dev}" = "rootfs" ] && continue
diff --git a/src/installer/Makefile.am b/src/installer/Makefile.am
index d0e52dc18..32f01bfa6 100644
--- a/src/installer/Makefile.am
+++ b/src/installer/Makefile.am
@@ -35,6 +35,7 @@ bin_PROGRAMS = \
 bin_SCRIPTS = \
 	downloadsource.sh \
 	execute-postinstall.sh \
+	install-bootloader \
 	start-networking.sh
 
 #- installer -------------------------------------------------------------------
diff --git a/src/installer/hw.c b/src/installer/hw.c
index 3bd748036..c9b95017d 100644
--- a/src/installer/hw.c
+++ b/src/installer/hw.c
@@ -78,11 +78,6 @@ struct hw* hw_init() {
 	if (ret == 0)
 		snprintf(hw->arch, sizeof(hw->arch), "%s", uname_data.machine);
 
-	// Detect if we are running in EFI mode
-	ret = access("/sys/firmware/efi", R_OK);
-	if (ret == 0)
-		hw->efi_supported = 1;
-
 	// Should we install in EFI mode?
 	if ((strcmp(hw->arch, "x86_64") == 0) || (strcmp(hw->arch, "aarch64") == 0))
 		hw->efi = 1;
@@ -1041,47 +1036,9 @@ int hw_stop_all_raid_arrays(const char* output) {
 
 int hw_install_bootloader(struct hw* hw, struct hw_destination* dest, const char* output) {
 	char cmd[STRING_SIZE];
-	int r;
-
-	char cmd_grub[STRING_SIZE];
-	snprintf(cmd_grub, sizeof(cmd_grub), "/usr/sbin/grub-install --target=i386-pc"
-			" --no-floppy --recheck");
-
-	if (dest->is_raid) {
-		snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk1->path);
-		r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
-		if (r)
-			return r;
-
-		snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->disk2->path);
-		r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
-		if (r)
-			return r;
-	} else {
-		snprintf(cmd, sizeof(cmd), "%s %s", cmd_grub, dest->path);
-		r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
-		if (r)
-			return r;
-	}
-
-	// Install GRUB in EFI mode
-	if (hw->efi) {
-		for (int removable = 0; removable < 1; removable++) {
-			snprintf(cmd, sizeof(cmd), "/usr/sbin/grub-install"
-				" --target=%s-efi --efi-directory=%s %s %s",
-				hw->arch, HW_PATH_BOOT_EFI,
-				(hw->efi_supported) ? "" : "--no-nvram",
-				(removable) ? "--removable" : "");
-
-			r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
-			if (r)
-				return r;
-		}
-	}
 
-	// Generate configuration file
-	snprintf(cmd, sizeof(cmd), "/usr/sbin/grub-mkconfig -o /boot/grub/grub.cfg");
-	r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
+	snprintf(cmd, sizeof(cmd), "/usr/bin/install-bootloader %s", dest->path);
+	int r = system_chroot(output, DESTINATION_MOUNT_PATH, cmd);
 	if (r)
 		return r;
 
diff --git a/src/installer/hw.h b/src/installer/hw.h
index 4e0afc431..9fe69271e 100644
--- a/src/installer/hw.h
+++ b/src/installer/hw.h
@@ -63,9 +63,6 @@ struct hw {
 
 	// Enabled if we should install in EFI mode
 	int efi;
-
-	// Enabled if this system supports EFI
-	int efi_supported;
 };
 
 struct hw_disk {
diff --git a/src/scripts/update-bootloader b/src/installer/install-bootloader
similarity index 67%
rename from src/scripts/update-bootloader
rename to src/installer/install-bootloader
index ad6fdb642..9c7869613 100644
--- a/src/scripts/update-bootloader
+++ b/src/installer/install-bootloader
@@ -21,7 +21,7 @@
 #                                                                          #
 ############################################################################
 
-GRUB_INSTALL_ARGS="--no-floppy --recheck"
+GRUB_INSTALL_ARGS="--no-floppy --recheck --force"
 
 function find_bootloader_device() {
 	local mp
@@ -52,7 +52,7 @@ function find_device() {
 	# Get the actual device from the partition that holds /
 	while [ -n "${root}" ]; do
 		if [ -e "/sys/block/${root}" ]; then
-			echo "${root}"
+			echo "/dev/${root}"
 			return 0
 		fi
 
@@ -66,15 +66,15 @@ function find_device() {
 function device_is_mdraid() {
 	local device="${1}"
 
-	[ -d "/sys/block/${device}/md" ]
+	[ -d "/sys/block/${device/\/dev/}/md" ]
 }
 
 function mdraid_get_slaves() {
 	local device="${1}"
 
 	local slave
-	for slave in /sys/block/${device}/slaves/*; do
-		basename "${slave}"
+	for slave in /sys/block/${device/\/dev/}/slaves/*; do
+		echo "/dev/$(basename "${slave}")"
 	done 2>/dev/null
 }
 
@@ -99,44 +99,92 @@ function grub_install() {
 		return 1
 	fi
 
-	local args
-	for args in "" "--force"; do
-		if grub-install ${GRUB_INSTALL_ARGS} ${args} "${device}" &>/dev/null; then
-			return 0
-		fi
+	local arches
+	case "$(uname -m)" in
+		aarch64)
+			arches="arm64-efi"
+			;;
+		i?86)
+			arches="i386-pc"
+			;;
+		x86_64)
+			arches="i386-pc x86_64-efi"
+			;;
+	esac
+
+	local arch
+	for arch in ${arches}; do
+		local args="--target=${arch}"
+
+		case "${arch}" in
+			*-efi)
+				# Skip all EFI architectures if no EFI partition exists
+				if [ ! -d "/boot/efi" ]; then
+					continue
+				fi
+
+				args="${args} --efi-directory=/boot/efi"
+
+				# Don't try to modify the BIOS when we are
+				# not running on EFI right now
+				if [ ! -d "/sys/firmware/efi" ]; then
+					args="${args} --no-nvram"
+				fi
+				;;
+		esac
+
+		local removable
+		for removable in "" "--removable"; do
+			if ! grub-install ${GRUB_INSTALL_ARGS} ${args} \
+					${removable} "${device}" &>/dev/null; then
+				echo "Could not install GRUB on ${device}" >&2
+				return 1
+			fi
+
+			# Do not try to install with --removable for non-efi architectures
+			[[ "${arch}" =~ \-efi$ ]] || break
+		done
 	done
 
-	echo "Could not install GRUB on ${device}" >&2
-	return 1
+	return 0
 }
 
 function main() {
+	local device="${1}"
+
 	# Find the root device
-	local device="$(find_bootloader_device)"
 	if [ -z "${device}" ]; then
-		echo "Could not find root device. Aborting." >&2
-		exit 1
+		device="$(find_bootloader_device)"
+		if [ -z "${device}" ]; then
+			echo "Could not find root device. Aborting." >&2
+			return 1
+		fi
+
+		echo "Found bootloader device: ${device}"
 	fi
 
-	echo "Found bootloader device: /dev/${device}"
+	if [ ! -b "${device}" ]; then
+		echo "${device} does not exist" >&2
+		return 2
+	fi
 
 	# Update configuration files
-	grub_update_config || exit $?
+	grub_update_config || return $?
 
 	# Handle mdraid devices
 	if device_is_mdraid "${device}"; then
 		local slave
 		for slave in $(mdraid_get_slaves "${device}"); do
-			grub_install "/dev/${slave}"
+			grub_install "${slave}"
 		done
 
 	# Handle normal block devices
 	else
-		grub_install "/dev/${device}"
+		grub_install "${device}"
 	fi
 
 	return 0
 }
 
 # Run main function
-main
+main "$@" || exit $?


hooks/post-receive
--
IPFire 2.x development tree

                 reply	other threads:[~2018-07-20 12:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180720120345.9E5521081BD5@git01.ipfire.org \
    --to=git@ipfire.org \
    --cc=ipfire-scm@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox