Skip to content

Commit

Permalink
Added command line option to skip GRUB legacy bootloader (#70)
Browse files Browse the repository at this point in the history
* Added command line option to skip GRUB legacy bootloader

* GUI option: legacy grub bootloader

Co-authored-by: Marc Brakels <marc.brakels@topic.nl>
  • Loading branch information
marc1990 and marctopic committed Feb 27, 2022
1 parent 69a430d commit 4d4910b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
20 changes: 12 additions & 8 deletions WoeUSB/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def init(from_cli=True, install_mode=None, source_media=None, target_media=None,
target_media = args.target

workaround_bios_boot_flag = args.workaround_bios_boot_flag

skip_legacy_bootloader = args.workaround_skip_grub

target_filesystem_type = args.target_filesystem

Expand All @@ -106,13 +108,13 @@ def init(from_cli=True, install_mode=None, source_media=None, target_media=None,

if from_cli:
return [source_fs_mountpoint, target_fs_mountpoint, temp_directory, install_mode, source_media, target_media,
workaround_bios_boot_flag, target_filesystem_type, filesystem_label, verbose, debug, parser]
workaround_bios_boot_flag, skip_legacy_bootloader, target_filesystem_type, filesystem_label, verbose, debug, parser]
else:
return [source_fs_mountpoint, target_fs_mountpoint, temp_directory, target_media]


def main(source_fs_mountpoint, target_fs_mountpoint, source_media, target_media, install_mode, temp_directory,
target_filesystem_type, workaround_bios_boot_flag, parser=None):
target_filesystem_type, workaround_bios_boot_flag, parser=None, skip_legacy_bootloader=False):
"""
:param parser:
:param source_fs_mountpoint:
Expand Down Expand Up @@ -192,10 +194,10 @@ def main(source_fs_mountpoint, target_fs_mountpoint, source_media, target_media,
copy_filesystem_files(source_fs_mountpoint, target_fs_mountpoint)

workaround.support_windows_7_uefi_boot(source_fs_mountpoint, target_fs_mountpoint)
if not skip_legacy_bootloader:
install_legacy_pc_bootloader_grub(target_fs_mountpoint, target_device, command_grubinstall)

install_legacy_pc_bootloader_grub(target_fs_mountpoint, target_device, command_grubinstall)

install_legacy_pc_bootloader_grub_config(target_fs_mountpoint, target_device, command_grubinstall, name_grub_prefix)
install_legacy_pc_bootloader_grub_config(target_fs_mountpoint, target_device, command_grubinstall, name_grub_prefix)

if workaround_bios_boot_flag:
workaround.buggy_motherboards_that_ignore_disks_without_boot_flag_toggled(target_device)
Expand Down Expand Up @@ -642,6 +644,8 @@ def setup_arguments():
help="Specify label for the newly created file system in --device creation method")
parser.add_argument("--workaround-bios-boot-flag", action="store_true",
help="Workaround BIOS bug that won't include the device in boot menu if non of the partition's boot flag is toggled")
parser.add_argument("--workaround-skip-grub", action="store_true",
help="This will skip the legacy grub bootloader creation step.")
parser.add_argument("--target-filesystem", "--tgt-fs", choices=["FAT", "NTFS"], default="FAT", type=str.upper,
help="Specify the filesystem to use as the target partition's filesystem.")
parser.add_argument('--for-gui', action="store_true", help=argparse.SUPPRESS)
Expand Down Expand Up @@ -707,12 +711,12 @@ def run():

source_fs_mountpoint, target_fs_mountpoint, temp_directory, \
install_mode, source_media, target_media, \
workaround_bios_boot_flag, target_filesystem_type, new_file_system_label, \
verbose, debug, parser = result
workaround_bios_boot_flag, skip_legacy_bootloader, target_filesystem_type, \
new_file_system_label, verbose, debug, parser = result

try:
main(source_fs_mountpoint, target_fs_mountpoint, source_media, target_media, install_mode, temp_directory,
target_filesystem_type, workaround_bios_boot_flag, parser)
target_filesystem_type, workaround_bios_boot_flag, parser, skip_legacy_bootloader)
except KeyboardInterrupt:
pass
except Exception as error:
Expand Down
13 changes: 9 additions & 4 deletions WoeUSB/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ def __init__(self, title, pos, size, style=wx.DEFAULT_FRAME_STYLE):
self.options_filesystem = wx.MenuItem(options_menu, wx.ID_ANY, _("Use NTFS"),
_("Use NTFS instead of FAT. NOTE: NTFS seems to be slower than FAT."),
wx.ITEM_CHECK)
self.options_skip_grub = wx.MenuItem(options_menu, wx.ID_ANY, _("Skip legacy grub bootloader"),
_("No legacy grub bootloader will be created. NOTE: It will only boot on system with UEFI support."),
wx.ITEM_CHECK)
options_menu.Append(self.options_boot)
options_menu.Append(self.options_filesystem)
options_menu.Append(self.options_skip_grub)

self.__MenuBar = wx.MenuBar()
self.__MenuBar.Append(file_menu, _("&File"))
Expand Down Expand Up @@ -242,8 +246,8 @@ def on_install(self, __):
filesystem = "NTFS"
else:
filesystem = "FAT"

woe = WoeUSB_handler(iso, device, boot_flag=self.__parent.options_boot.IsChecked(), filesystem=filesystem)
woe = WoeUSB_handler(iso, device, boot_flag=self.__parent.options_boot.IsChecked(), filesystem=filesystem, skip_grub=self.__parent.options_skip_grub.IsChecked())
woe.start()

dialog = wx.ProgressDialog(_("Installing"), _("Please wait..."), 101, self.GetParent(),
Expand Down Expand Up @@ -383,14 +387,15 @@ class WoeUSB_handler(threading.Thread):
error = ""
kill = False

def __init__(self, source, target, boot_flag, filesystem):
def __init__(self, source, target, boot_flag, filesystem, skip_grub=False):
threading.Thread.__init__(self)

core.gui = self
self.source = source
self.target = target
self.boot_flag = boot_flag
self.filesystem = filesystem
self.skip_grub = skip_grub

def run(self):
source_fs_mountpoint, target_fs_mountpoint, temp_directory, target_media = core.init(
Expand All @@ -401,7 +406,7 @@ def run(self):
)
try:
core.main(source_fs_mountpoint, target_fs_mountpoint, self.source, self.target, "device", temp_directory,
self.filesystem, self.boot_flag)
self.filesystem, self.boot_flag , None, self.skip_grub)
except SystemExit:
pass

Expand Down

0 comments on commit 4d4910b

Please sign in to comment.