Skip to content

Commit

Permalink
src/woeusb: workaround_win7_uefi: Properly detect existing EFI direct…
Browse files Browse the repository at this point in the history
…ory, fixes #91

This fixes the case where the source image already have EFI directory.
The primary issue is that according to UEFI spec the efi directory path isn't case-sensitive, we have to detect them regardless of the case and use it as the bootmgfw.efi extract destination.
Also this implements check to skip workaround if any existing efi bootloader is found.

Related-GitHub-Issue: windows 7 iso failed · Issue #91 · slacka/WoeUSB <https://github.com/slacka/WoeUSB/issues/91>
Reported-by: kabnaj <https://github.com/kabnaj>
Original-patch-by: kabnaj <https://github.com/kabnaj>
Signed-off-by: 林博仁 <[email protected]>
  • Loading branch information
brlin-tw committed Jun 13, 2017
1 parent 9cae433 commit f1bed07
Showing 1 changed file with 75 additions and 2 deletions.
77 changes: 75 additions & 2 deletions src/woeusb
Original file line number Diff line number Diff line change
Expand Up @@ -890,15 +890,88 @@ workaround_support_windows_7_uefi_boot(){
echo_with_color yellow "Warning: '7z' utility not found, workaround is not applied." >&2
return 0
fi

# Detect **case-insensitive** existing efi directories according to UEFI spec
local\
test_efi_directory\
efi_directory
test_efi_directory="$(
find\
"${target_fs_mountpoint}"\
-ipath "${target_fs_mountpoint}/efi"
)"
if [ -z "${test_efi_directory}" ]; then
efi_directory="${target_fs_mountpoint}/efi"
if [ "${verbose}" = "1" ]; then
printf\
"%s: DEBUG: Can't find efi directory, use %s.\n"\
"${FUNCNAME[0]}"\
"${efi_directory}"
fi
else # efi directory(case don't care) exists
efi_directory="${test_efi_directory}"
if [ "${verbose}" = "1" ]; then
printf\
"%s: DEBUG: %s detected.\n"\
"${FUNCNAME[0]}"\
"${efi_directory}"
fi
fi
unset test_efi_directory

local\
test_efi_boot_directory\
efi_boot_directory
test_efi_boot_directory="$(
find\
"${target_fs_mountpoint}"\
-ipath "${efi_directory}/boot"
)"
if [ -z "${test_efi_boot_directory}" ]; then
efi_boot_directory="${efi_directory}/boot"
if [ "${verbose}" = "1" ]; then
printf\
"%s: DEBUG: Can't find efi/boot directory, use %s.\n"\
"${FUNCNAME[0]}"\
"${efi_boot_directory}"
fi
else # boot directory(case don't care) exists
efi_boot_directory="${test_efi_boot_directory}"
if [ "${verbose}" = "1" ]; then
printf\
"%s: DEBUG: %s detected.\n"\
"${FUNCNAME[0]}"\
"${efi_boot_directory}"
fi
fi
unset\
efi_directory\
test_efi_boot_directory

# If there's already an EFI bootloader existed, skip the workaround
local test_efi_bootloader
test_efi_bootloader="$(
find\
"${target_fs_mountpoint}"\
-ipath "${target_fs_mountpoint}/efi/boot/boot*.efi"
)"
if [ -n "${test_efi_bootloader}" ]; then
printf\
"INFO: Detected existing EFI bootloader, workaround skipped.\n"
return 0
fi

mkdir\
--parents\
"${target_fs_mountpoint}/EFI/Boot"
"${efi_boot_directory}"

# Skip workaround if EFI bootloader already exist in efi_boot_directory
7z\
e\
-so\
"${source_fs_mountpoint}/sources/install.wim"\
"Windows/Boot/EFI/bootmgfw.efi"\
> "${target_fs_mountpoint}/EFI/Boot/bootx64.efi"
> "${efi_boot_directory}/bootx64.efi"
}; declare -fr workaround_support_windows_7_uefi_boot

install_bootloader_grub(){
Expand Down

0 comments on commit f1bed07

Please sign in to comment.