Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 220687 - sys-boot/grub-0.97-r5 floating point exception when re-installing stage1
Summary: sys-boot/grub-0.97-r5 floating point exception when re-installing stage1
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: x86 Linux
: High normal with 1 vote (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-05-06 22:10 UTC by Alexandru Toma
Modified: 2008-11-06 16:45 UTC (History)
4 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
patch 810 w/proper revision checking (810_all_grub-0.97-ext3_256byte_inode.patch,4.70 KB, patch)
2008-07-21 07:15 UTC, RB
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alexandru Toma 2008-05-06 22:10:19 UTC
After upgrading to version 0.97-r5 I got the "IMPORTANT NOTE" about updating the satge1, but when I try to do that I get the following error:

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ 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)
 Filesystem type is ext2fs, partition type 0x83

grub> setup (hd0)Floating point exception


I first got this error while trying the following:

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ 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> find /boot/grub/stage1Floating point exception


After searching a bit on the net I found the following post: http://www.linuxquestions.org/questions/debian-26/grub-setup-problem-bootgrubstage1-not-found-175689/
I also tried the command suggested in that post:

cloud ~ # grub-install --root-directory=/boot /dev/hda
/sbin/grub-install: line 432: 18287 Floating point exception$grub_shell --batch $no_floppy --device-map=$device_map  > $log_file <<EOF
dump ${root_drive}${tmp} ${img_file}
quit
EOF

/sbin/grub-install: line 432: 18292 Floating point exception$grub_shell --batch $no_floppy --device-map=$device_map  > $log_file <<EOF
dump ${root_drive}${tmp} ${img_file}
quit
EOF

/sbin/grub-install: line 432: 18297 Floating point exception$grub_shell --batch $no_floppy --device-map=$device_map  > $log_file <<EOF
dump ${root_drive}${tmp} ${img_file}
quit
EOF

/sbin/grub-install: line 432: 18302 Floating point exception$grub_shell --batch $no_floppy --device-map=$device_map  > $log_file <<EOF
dump ${root_drive}${tmp} ${img_file}
quit
EOF

/sbin/grub-install: line 432: 18307 Floating point exception$grub_shell --batch $no_floppy --device-map=$device_map  > $log_file <<EOF
dump ${root_drive}${tmp} ${img_file}
quit
EOF

The file /boot/boot/grub/stage1 not read correctly.


Also, if I just skip the root (hd0,0) part I get the following:

    GNU GRUB  version 0.97  (640K lower / 3072K upper memory)

 [ 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> setup (hd0)

Error 12: Invalid device requested

Reproducible: Always

Steps to Reproduce:




Portage 2.1.4.4 (default-linux/x86/2007.0/desktop, gcc-4.1.2, glibc-2.6.1-r0, 2.6.23-gentoo-r3 i686)
=================================================================
System uname: 2.6.23-gentoo-r3 i686 AMD Athlon(tm) 64 X2 Dual Core Processor 3800+
Timestamp of tree: Tue, 06 May 2008 19:30:01 +0000
app-shells/bash:     3.2_p17-r1
dev-java/java-config: 1.3.7, 2.1.4
dev-lang/python:     2.4.4-r9
dev-python/pycrypto: 2.0.1-r6
sys-apps/baselayout: 1.12.11.1
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.3.16
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-march=athlon64 -msse3 -O2 -pipe -fomit-frame-pointer"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo /etc/udev/rules.d"
CXXFLAGS="-march=athlon64 -msse3 -O2 -pipe -fomit-frame-pointer"
DISTDIR="/usr/portage/distfiles"
FEATURES="collision-protect distlocks metadata-transfer parallel-fetch sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://ftp.roedu.net/pub/mirrors/gentoo.org ftp://ftp.romnet.org/gentoo http://gentoo.osuosl.org"
LANG="en_US.UTF-8"
LC_ALL="POSIX"
MAKEOPTS="-j3"
PKGDIR="/usr/portage/packages"
PORTAGE_COMPRESS="bzip2"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/portage/local/layman/sunrise /usr/portage/local/layman/xeffects /usr/portage/local/layman/berkano /usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="3dnow 3dnowext X aalib acl acpi alsa cairo cdr cli cracklib crypt cups curl
 dbus dri dvd dvdr dvdread eds emboss encode evo fam firefox flac fortran gd geo
ip gif gpm gstreamer gtk gtk2 hal iconv isdnlog jikes jpeg lcms libcaca mad matr
oska midi mikmod mmx mmxext modplug mp3 mpeg mudflap ncurses network nls nptl np
tlonly ogg opengl openmp pam pcre pdf png pppd python qt3 qt3support qt4 quickti
me readline reflection rtc sdl session spell spl sse sse2 ssl svg tcpd tga theor
a tiff truetype unicode vorbis win32codecs x86 xml xorg xprint xv xvid zlib" ALS
A_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1
x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trid
ent usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym co
py dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linea
r meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="act
ions alias auth_basic authn_alias authn_anon authn_dbm authn_default authn_file 
authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoin
dex cache dav dav_fs dav_lock deflate dir disk_cache env expires ext_filter file
_cache filter headers include info log_config logio mem_cache mime mime_magic ne
gotiation rewrite setenvif speling status unique_id userdir usertrack vhost_alia
s" ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayr
ad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" USERLAND="GNU
" VIDEO_CARDS="nv nvidia vga vesa none"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LDFLAGS, LINGUAS, 
PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Alexandru Toma 2008-05-07 09:36:35 UTC
Right now I can't enter my Gentoo installation anymore. This morning when I started the computer it booted and when it got to loading grub it restarted. If I don't turn the computer off it keeps restarting, booting until it starts to load grub and then restarting again in a loop.

I don't know what happened. I didn't do anything out of the ordinary, apart from the commands I mentioned in the previous post.
Comment 2 Sergey Zhelnin 2008-05-07 21:25:25 UTC
(In reply to comment #0)

Exactly the same error after upgrading grub to sys-boot/grub-0.97-r5.
Add also this information:
cat /etc/mtab:
/dev/hda8 / reiserfs rw,noatime 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw,nosuid,nodev,noexec 0 0
udev /dev tmpfs rw,nosuid 0 0
devpts /dev/pts devpts rw,nosuid,noexec 0 0
/dev/hda2 /mnt/disk_c vfat rw,noatime,iocharset=utf8,codepage=866 0 0
/dev/hda5 /mnt/disk_d vfat rw,noatime,iocharset=utf8,codepage=866 0 0
none /dev/shm tmpfs rw 0 0
usbfs /proc/bus/usb usbfs rw,noexec,nosuid,devmode=0664,devgid=85 0 0
securityfs /sys/kernel/security securityfs rw,noexec,nosuid,nodev 0 0
/dev/hda6 /boot ext2 rw,noatime 0 0

cat /etc/fstab:
/dev/hda6               /boot           ext2            noauto,noatime          1 1
/dev/hda8               /               reiserfs        noatime                 0 0
/dev/hda7               none            swap            sw                      0 0
/dev/cdroms/cdrom0      /mnt/cdrom      iso9660         user,noauto,ro          0 0
#/dev/fd0               /mnt/floppy     auto            noauto                  0 0
/dev/hda2               /mnt/disk_c     vfat            noatime,iocharset=utf8,codepage=866     0 0
/dev/hda5               /mnt/disk_d     vfat            noatime,iocharset=utf8,codepage=866     0 0
/dev/sda1               /mnt/usb        auto            rw,user                 0 0

# NOTE: The next line is critical for boot!
none                    /proc           proc            defaults                0 0
none                    /dev/shm        tmpfs           defaults                0 0
Comment 3 Nick Simonov 2008-05-08 17:35:23 UTC
(In reply to comment #0)

> 
> grub> setup (hd0)Floating point exception
> 

I have exactly the same problem. Tried to delete the boot partition and create it again - didn't help. In the grub shell it can execute 'cat' for any other partition, but fails at 'boot'.

I fixed the problem by downloading and installing the original grub 0.97 from ftp://alpha.gnu.org/gnu/grub/
Comment 4 Bill Binder 2008-05-09 20:28:43 UTC
(In reply to comment #3)
...
> I fixed the problem by downloading and installing the original grub 0.97 from
> ftp://alpha.gnu.org/gnu/grub/
> 

You can use (almost) any live cd - the update should've saved your old boot stuff so all you need to do is copy /boot/grub/stage2.old to /boot/grub/stage2
Comment 5 Alexandru Toma 2008-05-10 15:49:26 UTC
(In reply to comment #4)
> (In reply to comment #3)
> You can use (almost) any live cd - the update should've saved your old boot
> stuff so all you need to do is copy /boot/grub/stage2.old to /boot/grub/stage2
> 

Thank you! That worked. Still, I wonder why this happened in the first place.
Comment 6 Chris Williams 2008-05-13 08:32:14 UTC
I have a "me too" on this setup:

newton ~ # emerge --info
Portage 2.1.4.4 (default-linux/x86/2007.0, gcc-4.1.2, glibc-2.6.1-r0, 2.6.24-gentoo-r7 i686)
=================================================================
System uname: 2.6.24-gentoo-r7 i686 Intel(R) Core(TM)2 CPU 6400 @ 2.13GHz
Timestamp of tree: Sun, 11 May 2008 16:45:01 +0000
distcc 2.18.3 i686-pc-linux-gnu (protocols 1 and 2) (default port 3632) [enabled]
ccache version 2.4 [enabled]
app-shells/bash:     3.2_p33
dev-java/java-config: 1.3.7, 2.1.6
dev-lang/python:     2.4.4-r9
dev-python/pycrypto: 2.0.1-r6
dev-util/ccache:     2.4-r7
sys-apps/baselayout: 2.0.0
sys-apps/openrc:     0.2.3
sys-apps/sandbox:    1.2.18.1-r2
sys-devel/autoconf:  2.13, 2.61-r1
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10.1
sys-devel/binutils:  2.18-r1
sys-devel/gcc-config: 1.4.0-r4
sys-devel/libtool:   1.5.26
virtual/os-headers:  2.6.23-r3
ACCEPT_KEYWORDS="x86"
CBUILD="i686-pc-linux-gnu"
CFLAGS="-mtune=prescott -O2 -pipe -fomit-frame-pointer"
CHOST="i686-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/fonts/fonts.conf /etc/gconf /etc/gentoo-release /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo /etc/texmf/web2c /etc/udev/rules.d"
CXXFLAGS="-mtune=prescott -O2 -pipe -fomit-frame-pointer"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distcc distlocks metadata-transfer sandbox sfperms strict unmerge-orphans userfetch"
GENTOO_MIRRORS="ftp://mirror.internode.on.net/pub/gentoo  http://mirror.pacific.net.au/linux/Gentoo"
LANG="en_US.UTF-8"
MAKEOPTS="-j5"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages"
PORTAGE_TMPDIR="/mnt/data/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://ptolemy/gentoo-portage"
USE="3dnow 3dnowext X a52 acl alsa amr apache2 arts audiofile berkdb bzip2 cdr cli cracklib crypt css cups curl dri dts dvb dvd dvdr encode ethereal exif expat fam ffmpeg flac fortran gd gdbm gif glut gmp gphoto2 gpm gtk guile hal iconv idn imagemagick imap isdnlog java jpeg kde lcms lirc mhash midi mmx mmxext mng moznocompose moznoirc moznomail mp3 mpeg mplayer mudflap mysql ncurses networking nls nptl nptlonly nsplugin nvidia ogg opengl openmp pam pcre perl php png ppds pppd python qt3 quicktime readline reflection regex samba session slang speex spl sse sse2 ssl svg tcltk tcpd tetex theora tiff transcode truetype unicode usb v4l v4l2 vorbis win32codecs x264 x86 xine xml2 xorg xv xvid xvmc zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1 emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" APACHE2_MODULES="actions alias auth_basic auth_digest authn_anon authn_dbd authn_dbm authn_default authn_file authz_dbm authz_default authz_groupfile authz_host authz_owner authz_user autoindex cache dav dav_fs dav_lock dbd deflate dir disk_cache env expires ext_filter file_cache filter headers ident imagemap include info log_config logio mem_cache mime mime_magic negotiation proxy proxy_ajp proxy_balancer proxy_connect proxy_http rewrite setenvif so speling status unique_id userdir usertrack vhost_alias" ELIBC="glibc" INPUT_DEVICES="keyboard mouse" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LIRC_DEVICES="devinput" USERLAND="GNU" VIDEO_CARDS="vesa nv nvidia v4l"
Unset:  CPPFLAGS, CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LDFLAGS, LINGUAS, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS


In case it is pertinent my /boot partition is EXT2 at (hd0,1).
Comment 7 Rene Mueller 2008-07-07 06:14:46 UTC
Same probleme here with grub-0.97-r6.
In my case /boot is an ext2 file system on /dev/sda3. I had
a closer look by recompiling with -g and plugging it in gdb.

# gdb grub
gdb> run
...
grub> root (hd0,2)
 Filesystem type is ext2fs, partition type 0x83
grub> setup (hd0)

Program received signal SIGFPE, Arithmetic exception.
0x0804ee44 in ext2fs_dir (dirname=0xf75ceebc "/boot/grub/stage1") at
fsys_ext2fs.c:293
293       __asm__ ("bsfl %1,%0"
(gdb) bt
#0  0x0804ee44 in ext2fs_dir (dirname=0xf75ceebc "/boot/grub/stage1") at fsys_ext2fs.c:293
#1  0x0804e313 in grub_open (filename=0xf75ceebc "/boot/grub/stage1") at disk_io.c:1728
#2  0x08059b2c in check_file (file=0xf75ceebc "/boot/grub/stage1") at builtins.c:4008
#3  0x0805ccda in setup_func (arg=0xf757dc5a "(hd0)", flags=1) at builtins.c:4155
#4  0x0805ddf8 in enter_cmdline (heap=0xf757dc54 "setup (hd0)", forever=1) at cmdline.c:172
#5  0x08057a7e in cmain () at stage2.c:1079
#6  0x0804c389 in init_bios_info () at common.c:337
#7  0x0804a7e9 in doit () at asmstub.c:180
#8  0x0804a96b in grub_stage2 () at asmstub.c:263
#9  0x08049700 in main (argc=1, argv=0xffaf2d14) at main.c:264
(gdb)

The line numbers seem to be misleading due to inlined and macroed coded.
The offending instruction is 'idiv %ecx' with %ecx == 0. When stepping
through ext2fs_dir (fsys_ext2fs.c) the trap occurs at line 616.
  raw_inode = (struct ext2_inode *)((char *)INODE +
    ((current_ino - 1) & (EXT2_INODES_PER_BLOCK (SUPERBLOCK) - 1)) *
    EXT2_INODE_SIZE (SUPERBLOCK));

The folded macro EXT2_INODES_PER_BLOCK has a division.
#define EXT2_INODE_SIZE(s)       (SUPERBLOCK->s_inode_size)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))

I do not know how an ext2 superblock has to look like. However, patch
810_all_grub-0.97-ext3_256byte_inode.patch affects this line.
I remember it used to work before, i.e., r5 broke it and r5
came with that patch.

Workaround: convert ext2 into ext3 using "tune2fs -j".
Comment 8 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-07-07 06:29:23 UTC
Can you please try r6 with 810_all_grub-0.97-ext3_256byte_inode.patch reverted?
Comment 9 Rene Mueller 2008-07-07 16:47:07 UTC
Unfortunately, it seems that I am unable to reproduce the bug after migrating to ext3. I rebuilt the ext2 file system from scratch (mke2fs), but without success. The bug no longer occurs. 

Surprisingly, "fsck.ext2 -vfc" did not report any error earlier while the bug occurred. The file systems must have been corrupted such that it could not be detected by fsck. 

I have no other explanation available. 
Comment 10 James Jones 2008-07-10 22:07:33 UTC
I did a little further debugging and found the problem:

#define EXT2_INODE_SIZE(s)       (SUPERBLOCK->s_inode_size)
#define EXT2_INODES_PER_BLOCK(s) (EXT2_BLOCK_SIZE(s)/EXT2_INODE_SIZE(s))

s_inode_size == 0, so we get a divide by 0.

It looks like s_inode_size isn't always present, so I made this change to the EXT2_INODE_SIZE() macro:

#define EXT2_INODE_SIZE(s)       ((SUPERBLOCK->s_inode_size) ? \
                                     SUPERBLOCK->s_inode_size : \
                                     sizeof(struct ext2_inode))

Rebuilt, installed, ran grub setup (hd0), no problems :-)

In general, I think there's a better way to check whether the new fields added by 810_all_grub-0.97-ext3_256byte_inode.patch are valid than to check if they're 0, but I didn't dig any deeper.  The kernel source would be a good reference I assume.
Comment 11 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-07-10 22:23:17 UTC
James Jones: thanks, why didn't you read the comment 7, three spots above yours, where it was traced to that exact code already. Then in comment 8 I asked somebody to test with the 810 patch dropped, and rene couldn't because he did a workaround in the meantime.
Comment 12 James Jones 2008-07-10 23:20:10 UTC
I did read that comment, that's why I knew to look at that particular patch specifically...  I tested with r6 with the patch applied.  Dropping the patch would obviously fix the problem, but don't you want the functionality of that patch?
Comment 13 RB 2008-07-21 07:15:08 UTC
Dropping the 810 patch works for r6, but I'd think doing so would do more harm than good, given what it does.

This is just a bad upstream/borrowed patch - the first Fedora patch (http://cvs.fedora.redhat.com/viewcvs/devel/grub/grub-fedora-9.patch) assumes the filesystem is of type EXT2_DYNAMIC_REV instead of checking s_rev_level at run-time to confirm that.  Of course, the old revision just padded the remainder of the block w/zeroes, so we get where we are today.

Whether or not it was made in a vacuum, James' patch above pretty closely matches what linux/ext2_fs.h does.  Attached is patch 810 re-done with code lifted straight from linux/ext2_fs.h - it properly checks the filesystem's revision before blindly grabbing a presumed inode_size.  I've tested it against an ext2 image build of OpenWRT, where this bug has been ghosting me ever since -r5 made it into the tree.
Comment 14 RB 2008-07-21 07:15:56 UTC
Created attachment 160981 [details, diff]
patch 810 w/proper revision checking
Comment 15 Robin Johnson archtester Gentoo Infrastructure gentoo-dev Security 2008-11-05 22:33:49 UTC
Please test 0.97-r8 that is in package.mask very carefully (aka have a livecd handy), but this should now be fixed.
Comment 16 RB 2008-11-06 16:45:54 UTC
50% tested (against workstation w/dynamic inodes).  Will be a few days before I can test on an embedded system (static inodes), but since 810 is the same patch I submitted, it should be okay.