diff --git a/modules/grub.sh b/modules/grub.sh index 985fd25..f6c8f71 100644 --- a/modules/grub.sh +++ b/modules/grub.sh @@ -111,9 +111,10 @@ function grub_install_grub_d_config() { # build. Instead, use `--removable`, which creates entries that automate # booting if you put the image into a new device, which you almost certainly # will after using mender-convert. - run_and_log_cmd_noexit "sudo chroot work/rootfs grub-install --removable --no-nvram" || ret=$? + local -r target_name=$(probe_grub_install_target) + run_and_log_cmd_noexit "sudo chroot work/rootfs grub-install --target=${target_name} --removable --no-nvram" || ret=$? if [ $ret -eq 0 ]; then - run_and_log_cmd_noexit "sudo chroot work/rootfs grub-install --no-nvram" || ret=$? + run_and_log_cmd_noexit "sudo chroot work/rootfs grub-install --target=${target_name} --no-nvram" || ret=$? fi if [ $ret -eq 0 ]; then diff --git a/modules/probe.sh b/modules/probe.sh index 6a00687..2773995 100644 --- a/modules/probe.sh +++ b/modules/probe.sh @@ -36,8 +36,10 @@ probe_arch() { fi target_arch="unknown" - if grep -q x86-64 <<< "${file_info}"; then + if grep -Eq "ELF 64-bit.*x86-64" <<< "${file_info}"; then target_arch="x86_64" + elif grep -Eq "ELF 32-bit.*386" <<< "${file_info}"; then + target_arch="i386" elif grep -Eq "ELF 32-bit.*ARM" <<< "${file_info}"; then target_arch="arm" elif grep -Eq "ELF 64-bit.*aarch64" <<< "${file_info}"; then @@ -72,6 +74,27 @@ probe_grub_efi_name() { echo "$efi_name" } +# Prints GRUB grub-install target name depending on target architecture +# +# No input parameters and these work on the assumption that boot and root parts +# are mounted at work/boot and work/rootfs +probe_grub_install_target() { + local target_name="" + local -r arch=$(probe_arch) + case "${arch}" in + "x86_64") + target_name="x86_64-efi" + ;; + "i386") + target_name="i386-efi" + ;; + *) + log_fatal "Unsupported arch: ${arch}" + ;; + esac + echo "$target_name" +} + # Prints Debian arch name depending on target architecture # # No input parameters and these work on the assumption that boot and root parts