From: Andrei Borzenkov Subject: [PATCH] grub-mkrescue: overwrite mtools bootstrap code with one from dosfstools With ESP created by mtools Mac boot manager hangs. Tested on MacBook 3,1 and iMac 9,1. It was determined that using bootstrap code from dosfstools avoids this. This patch explicitly overwrites bootstrap code with dosfstools version. --- util/grub-mkrescue.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c index 4511826..66ae085 100644 --- a/util/grub-mkrescue.c +++ b/util/grub-mkrescue.c @@ -53,6 +53,35 @@ static char **xorriso_argv; static char *iso_uuid; static char *iso9660_dir; +/* The following bootstrap code is from dosfstools distributed under + GPL Version 3 license. + */ +#define BOOTCODE_OFFSET 62 +#define BOOTCODE_SIZE 448 + +static char dummy_boot_code[BOOTCODE_SIZE] = + "\x0e" /* push cs */ + "\x1f" /* pop ds */ + "\xbe\x5b\x7c" /* mov si, offset message_txt */ + /* write_msg: */ + "\xac" /* lodsb */ + "\x22\xc0" /* and al, al */ + "\x74\x0b" /* jz key_press */ + "\x56" /* push si */ + "\xb4\x0e" /* mov ah, 0eh */ + "\xbb\x07\x00" /* mov bx, 0007h */ + "\xcd\x10" /* int 10h */ + "\x5e" /* pop si */ + "\xeb\xf0" /* jmp write_msg */ + /* key_press: */ + "\x32\xe4" /* xor ah, ah */ + "\xcd\x16" /* int 16h */ + "\xcd\x19" /* int 19h */ + "\xeb\xfe" /* foo: jmp foo */ + /* message_txt: */ + "This is not a bootable disk. Please insert a bootable floppy and\r\n" + "press any key to try again ... \r\n"; + static void xorriso_push (const char *val) { @@ -793,6 +822,29 @@ main (int argc, char *argv[]) xorriso_push ("-efi-boot-part"); xorriso_push ("--efi-boot-image"); + /* Mac fails to boot from ESP created by mformat; it was found that using + different bootstrap code in bootblock avoids this problem. + Tested on MacBook 3,1 (late 2007) and iMac 9.1 (2009). + */ + { + int efiimgfatfd; + + efiimgfatfd = grub_util_fd_open (efiimgfat, GRUB_UTIL_FD_O_WRONLY); + if (efiimgfatfd == -1) + grub_util_error (_("cannot open `%s': %s"), efiimgfat, + strerror (errno)); + + if (grub_util_fd_seek (efiimgfatfd, BOOTCODE_OFFSET) == -1) + grub_util_error (_("cannot seek `%s': %s"), efiimgfat, + strerror (errno)); + + if (grub_util_fd_write (efiimgfatfd, dummy_boot_code, BOOTCODE_SIZE) != BOOTCODE_SIZE) + grub_util_error (_("cannot write to `%s': %s"), efiimgfat, + strerror (errno)); + + close (efiimgfatfd); + } + grub_util_unlink_recursive (efidir); free (efiimgfat); free (efidir_efi); -- tg: (a9399f2..) t/mtools-bad-boot-sector (depends on: master)