Grub 0.97-29ubuntu62 gives error "Error 6: Mismatched or corrupt version of stage1/stage2"

Bug #837815 reported by Steven Shiau
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
grub (Ubuntu)
Fix Released
Critical
Colin Watson
Oneiric
Fix Released
Critical
Colin Watson

Bug Description

On the Oneiric testing system, I ran grub-install to reinstall grub for Debian Lenny.

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=11.10
DISTRIB_CODENAME=oneiric
DISTRIB_DESCRIPTION="Ubuntu oneiric (development branch)"

The version of grub:
$ dpkg -l |grep grub
ii grub 0.97-29ubuntu62 GRand Unified Bootloader (Legacy version)
ii grub-common 1.99-11ubuntu1 GRand Unified Bootloader (common files)

Debian Lenny is on /dev/sda:
$ parted -s /dev/sda print
Model: ATA VMware Virtual I (scsi)
Disk /dev/sda: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number Start End Size Type File system Flags
 1 32.3kB 354MB 354MB primary ext3 boot
 2 354MB 8587MB 8234MB extended
 5 354MB 3381MB 3027MB logical ext3
 6 3381MB 4836MB 1456MB logical ext3
 7 4836MB 5338MB 502MB logical linux-swap(v1)
 8 5338MB 5601MB 263MB logical ext3
 9 5601MB 8587MB 2986MB logical ext3

The root partition of Debian Lenny is /dev/sda1, therefore:
1. mount /dev/sda1 /mnt/
2. ls -alFd /mnt/boot/grub/
drwxr-xr-x 2 root root 1024 2011-08-31 03:12 /mnt/boot/grub/

3. grub-install --no-floppy --root-directory=/mnt/ /dev/sda
Installing GRUB to /dev/sda as (hd0)...

       [ Minimal BASH-like line editing is supported. For
         the first word, TAB lists possible command
         completions. Anywhere else TAB lists the possible
         completions of a device/filename. ]
grub> root (hd0,0)
grub> setup --stage2=/mnt//boot/grub/stage2 --prefix=/boot/grub (hd0)
 Checking if "/boot/grub/stage1" exists... yes
 Checking if "/boot/grub/stage2" exists... yes
 Checking if "/boot/grub/e2fs_stage1_5" exists... yes
 Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 21 sectors are embedded.
succeeded
 Running "install --stage2=/mnt//boot/grub/stage2 /boot/grub/stage1 (hd0) (hd0)1+21 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... failed

Error 6: Mismatched or corrupt version of stage1/stage2
grub> quit

After downgrading to the grub version on Natty, i.e. grub_0.97-29ubuntu61, it works:
$ dpkg -i grub_0.97-29ubuntu61_i386.deb
dpkg: warning: downgrading grub from 0.97-29ubuntu62 to 0.97-29ubuntu61.
(Reading database ... 21423 files and directories currently installed.)
Preparing to replace grub 0.97-29ubuntu62 (using grub_0.97-29ubuntu61_i386.deb) ...
Unpacking replacement grub ...
Setting up grub (0.97-29ubuntu61) ...

root@oneiric:~# grub-install --no-floppy --root-directory=/mnt/ /dev/sda
Installing GRUB to /dev/sda as (hd0)...
Installation finished. No error reported.
This is the contents of the device map /mnt//boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(hd0) /dev/sda
(hd1) /dev/sdb

Revision history for this message
Jarl Nicolson (jnicolson) wrote :

I also experienced this bug when trying to use vmbuilder to create an oneiric VM. During the bootloader step (grub 0.97-29ubuntu62) I get the following:

2011-09-09 16:38:03,944 DEBUG : ['chroot', '/tmp/tmphxwuJ8', 'grub', '--device-map=/tmp/vmbuilder-grub/device.map', '--batch']
2011-09-09 16:38:03,945 DEBUG : stdin was set and it was a string: root (hd0,0)
setup (hd0)
EOT
2011-09-09 16:38:07,981 DEBUG :
2011-09-09 16:38:07,981 DEBUG : [ Minimal BASH-like line editing is supported. For
2011-09-09 16:38:07,982 DEBUG : the first word, TAB lists possible command
2011-09-09 16:38:07,982 DEBUG : completions. Anywhere else TAB lists the possible
2011-09-09 16:38:07,982 DEBUG : completions of a device/filename. ]
2011-09-09 16:38:07,982 DEBUG : grub> root (hd0,0)
2011-09-09 16:38:07,983 DEBUG : grub> setup (hd0)
2011-09-09 16:38:07,983 DEBUG : Checking if "/boot/grub/stage1" exists... yes
2011-09-09 16:38:07,983 DEBUG : Checking if "/boot/grub/stage2" exists... yes
2011-09-09 16:38:07,984 DEBUG : Checking if "/boot/grub/e2fs_stage1_5" exists... yes
2011-09-09 16:38:07,984 DEBUG : Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 21 sectors are embedded.
2011-09-09 16:38:07,984 DEBUG : succeeded
2011-09-09 16:38:07,984 DEBUG : Running "install /boot/grub/stage1 (hd0) (hd0)1+21 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... failed
2011-09-09 16:38:07,985 DEBUG :
2011-09-09 16:38:07,985 DEBUG : Error 6: Mismatched or corrupt version of stage1/stage2
2011-09-09 16:38:07,985 DEBUG : grub> EOT

When using the same vmbuilder config but natty (grub 0.97-29ubuntu61) it works correctly:

2011-09-09 17:23:27,158 DEBUG : ['chroot', '/tmp/tmpqBagP3', 'grub', '--device-map=/tmp/vmbuilder-grub/device.map', '--batch']
2011-09-09 17:23:27,158 DEBUG : stdin was set and it was a string: root (hd0,0)
setup (hd0)
EOT
2011-09-09 17:23:29,191 DEBUG :
2011-09-09 17:23:29,192 DEBUG : [ Minimal BASH-like line editing is supported. For
2011-09-09 17:23:29,192 DEBUG : the first word, TAB lists possible command
2011-09-09 17:23:29,193 DEBUG : completions. Anywhere else TAB lists the possible
2011-09-09 17:23:29,193 DEBUG : completions of a device/filename. ]
2011-09-09 17:23:29,193 DEBUG : grub> root (hd0,0)
2011-09-09 17:23:29,194 DEBUG : grub> setup (hd0)
2011-09-09 17:23:29,194 DEBUG : Checking if "/boot/grub/stage1" exists... yes
2011-09-09 17:23:29,194 DEBUG : Checking if "/boot/grub/stage2" exists... yes
2011-09-09 17:23:29,194 DEBUG : Checking if "/boot/grub/e2fs_stage1_5" exists... yes
2011-09-09 17:23:29,195 DEBUG : Running "embed /boot/grub/e2fs_stage1_5 (hd0)"... 17 sectors are embedded.
2011-09-09 17:23:29,195 DEBUG : succeeded
2011-09-09 17:23:29,196 DEBUG : Running "install /boot/grub/stage1 (hd0) (hd0)1+17 p (hd0,0)/boot/grub/stage2 /boot/grub/menu.lst"... succeeded
2011-09-09 17:23:29,196 DEBUG : Done.
2011-09-09 17:23:29,196 DEBUG : grub> EOT

Revision history for this message
Colin Watson (cjwatson) wrote :

This seems to be due to a toolchain change; two functions in .text.unlikely have been incorrectly reordered before _start. I'm trying to track down exactly what caused this, and whether grub needs to be adjusted or whether it counts as a toolchain regression.

(grub2 does not seem to be affected; no functions in the kernel are in the .text.unlikely section.)

Changed in grub (Ubuntu Oneiric):
status: New → Triaged
importance: Undecided → Critical
assignee: nobody → Colin Watson (cjwatson)
milestone: none → ubuntu-11.10
Revision history for this message
Colin Watson (cjwatson) wrote :

I think this is down to GCC 4.5 vs. 4.6; compiling with gcc-4.5 seems to avoid this. From the GCC 4.6 release notes:

  * A new inter-procedural static profile estimation pass detects functions that are executed once or unlikely to be executed. Unlikely executed functions are optimized for size. Functions executed once are optimized for size except for the inner loops.

  * On most targets with named section support, functions used only at startup (static constructors and main), functions used only at exit and functions detected to be cold are placed into separate text segment subsections. This extends the -freorder-functions feature and is controlled by the same switch. The goal is to improve the startup time of large C++ programs.

    Proper function placement requires linker support. GNU ld 2.21.51 on ELF targets was updated to place those functions together within the text section leading to better code locality and faster startup times of large C++ programs. The feature is also supported in the Apple linker. Support in the gold linker is planned.

Using -fno-reorder-functions also appears to avoid the problem, so I suspect that will be the answer.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package grub - 0.97-29ubuntu64

---------------
grub (0.97-29ubuntu64) oneiric; urgency=low

  * Build stage2 with -fno-reorder-functions to prevent
    unlikely-to-be-executed functions being reordered before _start with GCC
    4.6 (LP: #837815).
 -- Colin Watson <email address hidden> Mon, 26 Sep 2011 10:14:28 +0100

Changed in grub (Ubuntu Oneiric):
status: Triaged → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.