# GRUB Error 13 on a new kernel

## tkzv

1. I compiled a new kernel 4.9.16, with mostly the same config. I copied it to /boot and added it to /boot/grub/menu.lst. After the reboot I got a GRUB error:

Error 13: Invalid or unsupported executable format

Old kernel 4.4.6 boots fine.

file recognizes kernels as:

```

/boot/kernel-4.4.6:                               Linux kernel x86 boot executable bzImage, version 4.4.6-gentoo (root@jet) #1 SMP PREEMPT Mon Jul 4 22:52:11 MSK 2016, RO-rootFS, swap_dev 0x4, Normal VGA

/boot/kernel-4.9.16:                              Linux kernel x86 boot executable bzImage, version 4.9.16-gentoo (root@jet) #2 SMP PREEMPT Tue Jun 6 23:40:29 MSK 2017, RO-rootFS, swap_dev 0x5, Normal VGA

```

This was sys-boot/grub-static-0.97-r12

Just in case: I'm not using the swap partition.

Update: GRUB2 (sys-boot/grub-2.02_beta3-r1) managed to boot with the new kernel properly, once I figured which motherboard I had. The only question now is: Why did not GRUB-legacy boot kernel 4.9.16?

2. (SOLVED: motherboard doesn't support EFI, but BIOS boot partition worked fine.) 

I assumed some new kernel features cause problems and tired installing new GRUB: sys-boot/grub-2.02_beta3-r1. /boot/grub/grub.cfg was generated by grub2-mkconfig from default /etc/default/grub. I created a FAT partition, added it to /etc/fstab, mounted it as /boot/efi, ran grub2-install:

```

# grub2-install --target=x86_64-efi /dev/sda

Installing for x86_64-efi platform.

EFI variables are not supported on this system.

EFI variables are not supported on this system.

Installation finished. No error reported.

```

After the reboot I got the old GRUB menu, which worked fine (but did not boot new kernel).

Disk partitions are:

```

# parted /dev/sda print

Model: ATA WDC WD40EFRX-68W (scsi)

Disk /dev/sda: 4001GB

Sector size (logical/physical): 512B/4096B

Partition Table: gpt

Disk Flags: 

Number  Start   End     Size    File system     Name  Flags

 1      1049kB  3947GB  3947GB  ext4            root  boot, esp

 2      3947GB  4001GB  53.7GB  linux-swap(v1)  swap

 3      4001GB  4001GB  2956kB                        boot, esp

```

The only question now is: Why did not GRUB-legacy boot kernel 4.9.16? Here's the diff between configs: https://pastebin.com/Rg8RixTnLast edited by tkzv on Thu Jun 08, 2017 7:29 pm; edited 4 times in total

----------

## DONAHUE

 *Quote:*   

> # grub2-install --target=x86_64-efi /dev/sda
> 
> Installing for x86_64-efi platform.
> 
> EFI variables are not supported on this system.
> ...

  The kernel needs to support efi/efi variables: 

```
grep -i efi /usr/src/linux/.config
```

 *Quote:*   

> CONFIG_EFI_PARTITION=y
> 
> CONFIG_EFI=y
> 
> CONFIG_EFI_STUB=y
> ...

  The system needs to support efi/efivars: *Quote:*   

> emerge -av efivar efibootmgr

  With kernel and system ready and the EFI partition mounted, run 

```
grub-install --target=x86_64-efi --efi-directory=<path to EFI directory> /dev/sda
```

 (should succeed without error)and finally run 

```
grub-mkconfig -o /boot/grub/grub.cfg
```

 *Quote:*   

> After the reboot I got the old GRUB menu, which worked fine.

  If legacy grub is booting the new kernel, life should be good.

----------

## tkzv

 *DONAHUE wrote:*   

>  The kernel needs to support efi/efi variables: 

 

It does: 

```
# zgrep -i efi /proc/config.gz 

CONFIG_EFI_PARTITION=y

CONFIG_EFI=y

# CONFIG_EFI_STUB is not set

CONFIG_FB_EFI=y

CONFIG_DMI_SCAN_MACHINE_NON_EFI_FALLBACK=y

# EFI (Extensible Firmware Interface) Support

CONFIG_EFI_VARS=y

CONFIG_EFI_ESRT=y

CONFIG_EFI_RUNTIME_MAP=y

# CONFIG_EFI_FAKE_MEMMAP is not set

CONFIG_EFI_RUNTIME_WRAPPERS=y

CONFIG_EFIVAR_FS=m

# CONFIG_EARLY_PRINTK_EFI is not set

# CONFIG_EFI_PGT_DUMP is not set
```

[/quote]

 *DONAHUE wrote:*   

>  The system needs to support efi/efivars:

 

In does. Both efivar and efibootmgr were present.

As I just found, I mistook my motherboard for a slightly different model, ASUS M5A78L/USB3. My motherboard ASUS M5A78L LE turned out to have no EFI support. I'll try BIOS recipe instead.

 *Quote:*   

>  *Quote:*   After the reboot I got the old GRUB menu, which worked fine.  If legacy grub is booting the new kernel, life should be good.

  It doesn't. (I've corrected the first post to make it clearer.) That mystery is still unsolved. Any ideas?

----------

## tkzv

Creating a BIOS boot partition for GRUB2 worked. I still would like to know what was the problem with GRUB1.

----------

## DONAHUE

The manual for legacy grub says  *Quote:*   

> 13. Invalid or unsupported executable format
> 
>     This error is returned if the kernel image being loaded is not recognized as Multiboot or one of the supported native formats (Linux zImage or bzImage, FreeBSD, or NetBSD). 

  Suggesting there is some subtle difference in the compiled form of new and old kernel or how each was copied to /boot.

----------

## tkzv

 *DONAHUE wrote:*   

> The manual for legacy grub says  *Quote:*   13. Invalid or unsupported executable format
> 
>     This error is returned if the kernel image being loaded is not recognized as Multiboot or one of the supported native formats (Linux zImage or bzImage, FreeBSD, or NetBSD).   Suggesting there is some subtle difference in the compiled form of new and old kernel or how each was copied to /boot.

  Both were bzImages, both used XZ compression, though I tried gzip too. 

Here is the diff between old and new configs: https://pastebin.com/Rg8RixTn It's long, but most changes were done automatically.

----------

