OSEC

Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com
 
[SOLVED] Re: Grub 0.94

From: Darren Tucker (dtuckerzip.com.au)
Date: Sun Apr 18 2004 - 21:01:09 CDT


uc.sheda wrote:

> I think this will works if you're using bash-2.05b
> # export CFLAGS=-fno-stack-protector ; ./configure && gmake

It doesn't for me, it will build but segfaults at run time. I spent
some time fiddling with it, here's how I got grub 0.94 running on (and
booting) OpenBSD 3.5.

# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-unknown-openbsd3.5/2.95.3/specs
gcc version 2.95.3 20010125 (prerelease, propolice)
# cd grub-0.94
# ./configure && make
[...]
make all-recursive
Making all in netboot
Making all in stage2

Problem 1:
make: don't know how to make pre_stage2. Stop in
/home/dtucker/grub-0.94/stage2.

Solution 1: use gmake.

# ./configure && gmake
[...]
Problem 2:
pre_stage2_exec-bios.o: In function `get_diskinfo':
stage2/bios.c:126: undefined reference to `__guard'
stage2/bios.c:248: undefined reference to `__guard'
stage2/bios.c:248: undefined reference to `__stack_smash_handler'

Solution 2: Use "CPPFLAGS=-fno-stack-protector"

# CPPFLAGS=-fno-stack-protector ./configure && gmake
[builds OK]

Attempting to make a bootable floppy:
[manually copy stage1 and stage2 onto /mnt/floppy/grub then umount it]
# grub
    GNU GRUB version 0.94 (640K lower / 3072K upper memory)
[...]
grub> root (fd0)
  Filesystem type is fat, using whole disk

grub> setup (fd0)
Segmentation fault (core dumped)

Problem 3: segfault at run time.

Solution 3: Use LDFLAGS=-Z to disable W^X for grub
# CPPFLAGS="-fno-stack-protector" LDFLAGS="-Z" ./configure
# gmake install

Currently, grub won't currently boot OpenBSD directly, so you need to
use the "chainloader" directive in menu.lst (or grub.conf) to load the
OpenBSD boot loader, which can then boot OpenBSD.

So, here's a complete recipe for making a bootable grub floppy (msdos
fs) on an OpenBSD 3.5 host:

CPPFLAGS="-fno-stack-protector" LDFLAGS="-Z" ./configure
gmake install

newfs_msdos /dev/rfd0c
mount -t msdos /dev/fd0c /mnt/floppy
mkdir /mnt/floppy/grub
cp /usr/local/share/grub/i386-unknown/{stage1,stage2} /mnt/floppy/grub
cat > /mnt/floppy/grub/menu.lst <<EOD
default 0
timeout 10

title OpenBSD
rootnoverify (hd0,3)
chainloader +1
boot
EOD
umount /mnt/floppy

grub --batch <<EOD
root (fd0)
setup (fd0)
EOD
echo Done.

--
Darren Tucker (dtucker at zip.com.au)
GPG key 8FF4FA69 / D9A3 86E9 7EEE AF4B B2D4 37C9 C982 80C7 8FF4 FA69
     Good judgement comes with experience. Unfortunately, the experience
usually comes from bad judgement.