mirror of
https://github.com/pbatard/rufus.git
synced 2024-08-14 23:57:05 +00:00
[grub] switch to the more compatible Grub 2.00-22
* Also enable Old BIOS fixes with Syslinux, Grub installation and fix related UI issues * Also add a check to confirm that Grub SBR will fit
This commit is contained in:
parent
b3947fc026
commit
8b47e95eb5
7 changed files with 96 additions and 60 deletions
|
@ -1,10 +1,12 @@
|
|||
grldr.mbr was compiled on Linux Debian 7.7.0 x64, using gcc-multilib 4.7.2,
|
||||
from https://github.com/chenall/grub4dos/commit/8549aae.
|
||||
This directory contains the Grub4DOS boot records that are used by Rufus
|
||||
|
||||
Note that, for convenience reasons, the first 512 bytes from this grldr.mbr are
|
||||
*not* the ones that Rufus processes when writing the actual MBR (first 512 bytes).
|
||||
Instead, the byte array from src/ms-sys/inc/mbr_grub.h (whose content is identical)
|
||||
is what Rufus uses. If you have modified this file, and the MBR section is
|
||||
altered, be mindful that you also need to update the array in mbr_grub.h.
|
||||
* grldr.mbr was compiled on Linux Debian 7.7.0 x64, using gcc-multilib 4.7.2, from
|
||||
https://github.com/chenall/grub4dos/commit/8549aae.
|
||||
|
||||
For details, see src/format.c.
|
||||
* Note that, for convenience reasons, the first 512 bytes from this grldr.mbr are
|
||||
*not* the ones that Rufus processes when writing the actual MBR (first 512 bytes).
|
||||
Instead, the byte array from src/ms-sys/inc/mbr_grub.h (whose content is identical)
|
||||
is what Rufus uses. If you have modified this file, and the MBR section is altered,
|
||||
be mindful that you also need to update the array in mbr_grub.h.
|
||||
|
||||
* For details, see src/format.c, src/msys/br.c and src/msys/inc/mbr_grub.h.
|
||||
|
|
Binary file not shown.
|
@ -1,16 +1,25 @@
|
|||
boot.img and core.img were compiled from git://git.savannah.gnu.org/grub.git,
|
||||
commit 72ec399ad8d6348b6c74ea63d80c79784c8b84ae, on a Debian 7.7.0 x64 system.
|
||||
This was done following the guide from:
|
||||
http://pete.akeo.ie/2014/05/compiling-and-installing-grub2-for.html.
|
||||
This directory contains the Grub 2.0 boot records that are used by Rufus
|
||||
|
||||
boot.img has been modified to nop the jump @ 0x66 as per grub2's setup.c comments:
|
||||
* boot.img was compiled from git://git.savannah.gnu.org/grub.git at commit:
|
||||
72ec399ad8d6348b6c74ea63d80c79784c8b84ae.
|
||||
|
||||
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
|
||||
for buggy BIOSes which don't pass boot drive correctly. Instead,
|
||||
they pass 0x00 or 0x01 even when booted from 0x80. */
|
||||
|
||||
Note that, for convenience reasons, the content of boot.img is *not* the one that
|
||||
Rufus processes when writing the MBR.
|
||||
Instead, the byte array from src/ms-sys/inc/mbr_grub2.h (whose content is identical)
|
||||
is what Rufus uses. If you modify these files, be mindful that you may also need
|
||||
to update the array in mbr_grub2.h.
|
||||
* core.img was compiled from grub 2.00-22 using the tarballs found at
|
||||
https://launchpad.net/ubuntu/+source/grub2/2.00-22.
|
||||
The use of the 2.00-22 source is done for compatibility reasons.
|
||||
|
||||
* This was done on a Debian 7.7.0 x64 system using gcc-multilib 4.7.2, following
|
||||
the guide from http://pete.akeo.ie/2014/05/compiling-and-installing-grub2-for.html
|
||||
Note that exFAT was not included in core.img in order to keep it under 31.5 KB.
|
||||
|
||||
* boot.img has been modified to nop the jump @ 0x66 as per grub2's setup.c comments:
|
||||
/* If DEST_DRIVE is a hard disk, enable the workaround, which is
|
||||
for buggy BIOSes which don't pass boot drive correctly. Instead,
|
||||
they pass 0x00 or 0x01 even when booted from 0x80. */
|
||||
|
||||
* Note that, for convenience reasons, the content of boot.img is *not* the one that
|
||||
Rufus processes when writing the MBR.
|
||||
Instead, the byte array from src/ms-sys/inc/mbr_grub2.h (whose content is identical)
|
||||
is what Rufus uses. If you modify these files, be mindful that you may also need
|
||||
to update the array in mbr_grub2.h.
|
||||
|
||||
* For details, see src/format.c, src/msys/br.c and src/msys/inc/mbr_grub2.h.
|
54
src/format.c
54
src/format.c
|
@ -890,7 +890,8 @@ static BOOL WriteMBR(HANDLE hPhysicalDrive)
|
|||
}
|
||||
if (IsChecked(IDC_BOOT)) {
|
||||
// Set first partition bootable - masquerade as per the DiskID selected
|
||||
buf[0x1be] = (IsChecked(IDC_RUFUS_MBR))?(BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80;
|
||||
buf[0x1be] = (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && IsChecked(IDC_RUFUS_MBR)) ?
|
||||
(BYTE)ComboBox_GetItemData(hDiskID, ComboBox_GetCurSel(hDiskID)):0x80;
|
||||
uprintf("Set bootable USB partition as 0x%02X\n", buf[0x1be]);
|
||||
}
|
||||
|
||||
|
@ -947,34 +948,51 @@ out:
|
|||
*/
|
||||
static BOOL WriteSBR(HANDLE hPhysicalDrive)
|
||||
{
|
||||
BOOL r = FALSE;
|
||||
DWORD size;
|
||||
// TODO: Do we need anything special for 4K sectors?
|
||||
DWORD size, max_size, mbr_size = 0x200;
|
||||
int dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
|
||||
unsigned char* buf = NULL;
|
||||
FILE fake_fd = { 0 };
|
||||
const char* using_msg = "Using %s SBR\n";
|
||||
|
||||
fake_fd._ptr = (char*)hPhysicalDrive;
|
||||
fake_fd._bufsiz = SelectedDrive.Geometry.BytesPerSector;
|
||||
if ((dt == DT_GRUB4DOS) || ((dt == DT_ISO) && (iso_report.has_grub4dos))) {
|
||||
// Ensure that we have sufficient space for the SBR
|
||||
max_size = IsChecked(IDC_EXTRA_PARTITION) ?
|
||||
(DWORD)(SelectedDrive.Geometry.BytesPerSector * SelectedDrive.Geometry.SectorsPerTrack) : 1024 * 1024;
|
||||
max_size -= mbr_size;
|
||||
if ((dt == DT_ISO) && (iso_report.has_grub4dos))
|
||||
dt = DT_GRUB4DOS;
|
||||
if ((dt == DT_ISO) && (iso_report.has_grub2))
|
||||
dt = DT_GRUB2;
|
||||
|
||||
switch (dt) {
|
||||
case DT_GRUB4DOS:
|
||||
buf = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_GR_GRUB_GRLDR_MBR), _RT_RCDATA, "grldr.mbr", &size, FALSE);
|
||||
if ((buf != NULL) && (size > 0x200)) {
|
||||
uprintf(using_msg, "Grub4DOS");
|
||||
// -0x200 to remove the MBR part
|
||||
r = (write_data(&fake_fd, 512, &buf[0x200], (uint64_t)(size - 0x200)) != 0);
|
||||
if ((buf == NULL) || (size <= mbr_size)) {
|
||||
uprintf("grldr.mbr is either not present or too small");
|
||||
return FALSE;
|
||||
}
|
||||
} else if ((dt == DT_GRUB2) || ((dt == DT_ISO) && (iso_report.has_grub2))) {
|
||||
buf = &buf[mbr_size];
|
||||
size -= mbr_size;
|
||||
break;
|
||||
case DT_GRUB2:
|
||||
buf = GetResource(hMainInstance, MAKEINTRESOURCEA(IDR_GR_GRUB2_CORE_IMG), _RT_RCDATA, "core.img", &size, FALSE);
|
||||
if (buf != NULL) {
|
||||
uprintf(using_msg, "Grub 2.0");
|
||||
// TODO: test what happens for 4096 bytes sectors
|
||||
r = (write_data(&fake_fd, 512, buf, (uint64_t)size) != 0);
|
||||
if (buf == NULL) {
|
||||
uprintf("Could not access core.img");
|
||||
return FALSE;
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
default:
|
||||
// No need to write secondary block
|
||||
r = TRUE;
|
||||
return TRUE;
|
||||
}
|
||||
return r;
|
||||
|
||||
uprintf("Writing SBR (Secondary Boot record)");
|
||||
if (size > max_size) {
|
||||
uprintf(" SBR size is too large - You may need to uncheck 'Add fixes for old BIOSes'.");
|
||||
return FALSE;
|
||||
}
|
||||
return (write_data(&fake_fd, mbr_size, buf, (uint64_t)size) != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -984,7 +1002,7 @@ static __inline const char* dt_to_name(int dt) {
|
|||
switch (dt) {
|
||||
case DT_FREEDOS: return "FreeDOS";
|
||||
case DT_REACTOS: return "ReactOS";
|
||||
default:
|
||||
default:
|
||||
return ((dt==DT_ISO)&&(iso_report.has_kolibrios))?"KolibriOS":"Standard";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,8 +66,8 @@
|
|||
#define IDR_FD_EGA18_CPX 326
|
||||
#define IDR_SL_LDLINUX_V4_BSS 400
|
||||
#define IDR_SL_LDLINUX_V4_SYS 401
|
||||
#define IDR_SL_LDLINUX_V6_BSS 402
|
||||
#define IDR_SL_LDLINUX_V6_SYS 403
|
||||
#define IDR_SL_LDLINUX_V6_BSS 402
|
||||
#define IDR_SL_LDLINUX_V6_SYS 403
|
||||
#define IDR_SL_MBOOT_C32 404
|
||||
#define IDR_GR_GRUB_GRLDR_MBR 450
|
||||
#define IDR_GR_GRUB2_CORE_IMG 451
|
||||
|
|
27
src/rufus.c
27
src/rufus.c
|
@ -43,6 +43,7 @@
|
|||
#include "localization.h"
|
||||
|
||||
/* Redefinitions for WDK and MinGW */
|
||||
// TODO: these would be better in a 'missing.h' file
|
||||
#ifndef PBM_SETSTATE
|
||||
#define PBM_SETSTATE (WM_USER+16)
|
||||
#endif
|
||||
|
@ -487,7 +488,7 @@ static void SetMBRProps(void)
|
|||
int dt = (int)ComboBox_GetItemData(hBootType, ComboBox_GetCurSel(hBootType));
|
||||
BOOL needs_masquerading = (IS_WINPE(iso_report.winpe) && (!iso_report.uses_minint));
|
||||
|
||||
if ((!mbr_selected_by_user) && ((image_path == NULL) || (dt != DT_ISO) || (fs != FS_NTFS))) {
|
||||
if ((!mbr_selected_by_user) && ((image_path == NULL) || (dt != DT_ISO) || (fs != FS_NTFS) || IS_GRUB(iso_report))) {
|
||||
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, BST_UNCHECKED);
|
||||
IGNORE_RETVAL(ComboBox_SetCurSel(hDiskID, 0));
|
||||
return;
|
||||
|
@ -502,25 +503,30 @@ static void SetMBRProps(void)
|
|||
static void EnableAdvancedBootOptions(BOOL enable, BOOL remove_checkboxes)
|
||||
{
|
||||
int bt = GETBIOSTYPE((int)ComboBox_GetItemData(hPartitionScheme, ComboBox_GetCurSel(hPartitionScheme)));
|
||||
BOOL actual_enable = ((bt==BT_UEFI)||(selection_default>=DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
|
||||
BOOL actual_enable_mbr = ((bt==BT_UEFI)||(selection_default>=DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
|
||||
BOOL actual_enable_fix = ((bt==BT_UEFI)||(selection_default==DT_IMG)||!IsChecked(IDC_BOOT))?FALSE:enable;
|
||||
static UINT uXPartChecked = BST_UNCHECKED;
|
||||
|
||||
if ((selection_default == DT_ISO) && (iso_report.has_kolibrios || IS_GRUB(iso_report) || IS_REACTOS(iso_report) || HAS_SYSLINUX(iso_report))) {
|
||||
actual_enable_mbr = FALSE;
|
||||
mbr_selected_by_user = FALSE;
|
||||
}
|
||||
if (remove_checkboxes) {
|
||||
// Store/Restore the checkbox states
|
||||
if (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && !actual_enable) {
|
||||
if (IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && !actual_enable_mbr) {
|
||||
uMBRChecked = IsChecked(IDC_RUFUS_MBR);
|
||||
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, BST_UNCHECKED);
|
||||
uXPartChecked = IsChecked(IDC_EXTRA_PARTITION);
|
||||
CheckDlgButton(hMainDialog, IDC_EXTRA_PARTITION, BST_UNCHECKED);
|
||||
} else if (!IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && actual_enable) {
|
||||
} else if (!IsWindowEnabled(GetDlgItem(hMainDialog, IDC_RUFUS_MBR)) && actual_enable_mbr) {
|
||||
CheckDlgButton(hMainDialog, IDC_RUFUS_MBR, uMBRChecked);
|
||||
CheckDlgButton(hMainDialog, IDC_EXTRA_PARTITION, uXPartChecked);
|
||||
}
|
||||
}
|
||||
|
||||
EnableWindow(GetDlgItem(hMainDialog, IDC_EXTRA_PARTITION), actual_enable);
|
||||
EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), actual_enable);
|
||||
EnableWindow(hDiskID, actual_enable);
|
||||
EnableWindow(GetDlgItem(hMainDialog, IDC_EXTRA_PARTITION), actual_enable_fix);
|
||||
EnableWindow(GetDlgItem(hMainDialog, IDC_RUFUS_MBR), actual_enable_mbr);
|
||||
EnableWindow(hDiskID, actual_enable_mbr);
|
||||
}
|
||||
|
||||
static void EnableBootOptions(BOOL enable, BOOL remove_checkboxes)
|
||||
|
@ -556,7 +562,8 @@ static void SetTargetSystem(void)
|
|||
if (SelectedDrive.PartitionType == PARTITION_STYLE_GPT) {
|
||||
ts = 2; // GPT/UEFI
|
||||
} else if (SelectedDrive.has_protective_mbr || SelectedDrive.has_mbr_uefi_marker || (IS_EFI(iso_report) &&
|
||||
(!HAS_SYSLINUX(iso_report)) && (!iso_report.has_bootmgr) && (!IS_WINPE(iso_report.winpe))) ) {
|
||||
(!HAS_SYSLINUX(iso_report)) && (!iso_report.has_bootmgr) && (!IS_REACTOS(iso_report)) &&
|
||||
(!iso_report.has_kolibrios) && (!IS_GRUB(iso_report)) && (!IS_WINPE(iso_report.winpe))) ) {
|
||||
ts = 1; // MBR/UEFI
|
||||
} else {
|
||||
ts = 0; // MBR/BIOS|UEFI
|
||||
|
@ -714,7 +721,7 @@ void UpdateProgress(int op, float percent)
|
|||
return;
|
||||
}
|
||||
if (percent > 100.1f) {
|
||||
duprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
|
||||
// duprintf("UpdateProgress(%d): invalid percentage %0.2f\n", op, percent);
|
||||
return;
|
||||
}
|
||||
if ((percent < 0.0f) && (nb_slots[op] <= 0)) {
|
||||
|
@ -1556,7 +1563,7 @@ void SetBoot(int fs, int bt)
|
|||
static_sprintf(tmp, "Syslinux %s", embedded_sl_version_str[1]);
|
||||
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, tmp), DT_SYSLINUX_V6));
|
||||
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "ReactOS"), DT_REACTOS));
|
||||
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub 2.0"), DT_GRUB2));
|
||||
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub 2.00-22"), DT_GRUB2));
|
||||
IGNORE_RETVAL(ComboBox_SetItemData(hBootType, ComboBox_AddStringU(hBootType, "Grub4DOS"), DT_GRUB4DOS));
|
||||
}
|
||||
if ((!advanced_mode) && (selection_default >= DT_SYSLINUX_V4)) {
|
||||
|
|
16
src/rufus.rc
16
src/rufus.rc
|
@ -32,7 +32,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
|
|||
|
||||
IDD_DIALOG DIALOGEX 12, 12, 227, 329
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Rufus 1.5.0.543"
|
||||
CAPTION "Rufus 1.5.0.544"
|
||||
FONT 8, "Segoe UI", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
|
||||
|
@ -164,7 +164,7 @@ END
|
|||
|
||||
IDD_DIALOG_XP DIALOGEX 12, 12, 227, 329
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
CAPTION "Rufus 1.5.0.543"
|
||||
CAPTION "Rufus 1.5.0.544"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
|
||||
|
@ -297,7 +297,7 @@ END
|
|||
IDD_DIALOG_RTL DIALOGEX 12, 12, 227, 329
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||
CAPTION "Rufus 1.5.0.543"
|
||||
CAPTION "Rufus 1.5.0.544"
|
||||
FONT 8, "Segoe UI", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
|
||||
|
@ -437,7 +437,7 @@ END
|
|||
IDD_DIALOG_RTL_XP DIALOGEX 12, 12, 227, 329
|
||||
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
|
||||
EXSTYLE WS_EX_RTLREADING | WS_EX_APPWINDOW | WS_EX_LAYOUTRTL
|
||||
CAPTION "Rufus 1.5.0.543"
|
||||
CAPTION "Rufus 1.5.0.544"
|
||||
FONT 8, "MS Shell Dlg", 400, 0, 0x1
|
||||
BEGIN
|
||||
DEFPUSHBUTTON "Start",IDC_START,113,291,50,14
|
||||
|
@ -701,8 +701,8 @@ END
|
|||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,5,0,543
|
||||
PRODUCTVERSION 1,5,0,543
|
||||
FILEVERSION 1,5,0,544
|
||||
PRODUCTVERSION 1,5,0,544
|
||||
FILEFLAGSMASK 0x3fL
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
|
@ -719,13 +719,13 @@ BEGIN
|
|||
BEGIN
|
||||
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)"
|
||||
VALUE "FileDescription", "Rufus"
|
||||
VALUE "FileVersion", "1.5.0.543"
|
||||
VALUE "FileVersion", "1.5.0.544"
|
||||
VALUE "InternalName", "Rufus"
|
||||
VALUE "LegalCopyright", "© 2011-2014 Pete Batard (GPL v3)"
|
||||
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html"
|
||||
VALUE "OriginalFilename", "rufus.exe"
|
||||
VALUE "ProductName", "Rufus"
|
||||
VALUE "ProductVersion", "1.5.0.543"
|
||||
VALUE "ProductVersion", "1.5.0.544"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
|
|
Loading…
Reference in a new issue