Subject: Re: grub "Error 2"?
To: Johan Ihren <johani@johani.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: port-xen
Date: 04/11/2007 20:00:33
On Wed, Apr 11, 2007 at 03:10:02PM +0200, Johan Ihren wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> I'm trying to clone a box that's running NetBSD/Xen just fine and I'm  
> running headlong into grub frustration.
> 
> Attempt #1:
> 
> copy the disklabel (two identical disks), newfs the new disk and then  
> dump + restore + grub-install /dev/rwd1d.
> 
> This results in a new disk that boots NetBSD just fine with the  
> NetBSD bootloader but fails to install grub:
> 
> box:/root#grub-install /dev/rwd0d
> The file /grub/stage1 not read correctly.
> 
> This also fails:
> 
> box:/root#grub
> grub> root (hd0,a)
> 
> Error 5: Partition table invalid or corrupt
> 
> I can not find any problems with either disk, partition table or  
> anything else...
> 
> Attempt #2:
> 
> No dick copying, instead fresh install of NetBSD 3.1 followed by  
> pkg_add the xenkernel20, xentools20 and grub packages. Then a new  
> "grub-install /dev/rwd0d" (which seems to work out just fine, no  
> errors). We get a nice looking /grub/devices.map file and everything  
> looks fine. So we reboot:
> 
> "GRUB loading stage 1.5"
> 
> followed by:
> 
> "GRUB loading, please wait"
> 
> followed by:
> 
> "Error 2"
> 
> and no further action. This last message looks suspiciously like an  
> error message from the NetBSD bootloader, but I have no idea why that  
> would be.
> 
> Note that (a) this is with a single large (80GB) root partition  
> (which works just fine for me on at least four other systems)

Yes, it can work. It depends on where the kernels (and I guess grub
files ) are located on disk. Do a fresh install and immediatly install
xen kernels and grub, it may work because FFS will allocate blocks near
the beggining of the disk: ffs tries to allocates inodes near the
parent's inode, and blocks near the inode. / has inode 2, so everything in
/ or /grub will not be far away at this stage.
start working, install packages, etc ... the first cylinder groups will
fill up. intall a new kernel in / (either a new inode, or overwriting an
existing inode with a larger file), there's no free blocks in the first
cylinder groups and your file ends up with blocks away from the beggining
of disk. And grub can't load it.

Now if you do some filesystem activity before setting up grub, it's possible
that /grub itself is too far from the start of disk and can't be loaded
by the first stage grub.

So: never make a FFS larger than 512Mo if you want it to play well with
grub.

> and (b)  
> I wonder a bit what the "e" in "grub> root (hd0,e)" in the Xen guide  
> refers to?

partition e in NetBSD disklabel of disk hd0. That's because on this system
I had several NetBSD installations, and the Xen one used partition e.

-- 
Manuel Bouyer <bouyer@antioche.eu.org>
     NetBSD: 26 ans d'experience feront toujours la difference
--