# root on zfs hangs with "missing boot loader"



## Beeblebrox (Jun 6, 2011)

*Ooops I did it again...*
The variety and scope of what I manage to break along my learning process with FreeBSD is starting to remind me of this cheesy pop song.  So my thanks once again to all the members of this community with their help.

Over the weekend I installed grub2 as boot loader from linux system on my disk and thought I could later fix the grub menu manually to boot into my zfs pool housing the FreeBSD system.  Silly me - very hard with root on zfs and better to build grub from the FreeBSD port.

Anyhoo, having failed massively at this, I placed the small mfsBSD on a usb stick and booted it, with the aim of restoring the btx loader for FreBSD. I then ran:
`# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ada0`
which should restore the loader. All the loader.conf and other files under /boot in the zpool remain intact and untouched. Unfortunately when I reboot system hangs with message:

```
Missing boot loader
```

Giving the above gpart command inside a chroot after mounting dev
`# mount -t devfs devfs /chroot/dev`

```
gpart: param 'arg0': invalid argument
```


----------



## Beeblebrox (Jun 6, 2011)

*Update*

One of the problems here seems to be that my system is 9-CURRENT, while mfsBSD is running 8.2 kernel and modules.
Therefore I decided something different: I booted from my usb, mounted the usb and created a folder called /boot/k90 (for kernel-9).  I then imported the root zpool on my hdd, mounted the zpool, copied my kernel, zfs and disk related modules, pmbr, gptzfsboot to the k90 folder and copied zpool.cache to boot/zfs on the usb.  I also copied my loader.conf as loader.k90 to /boot on the usb.
I then re-booted and chose "6" on th btx menu which dropped me to the loader command shell.  here I did:


```
# unload kernel
# load boot/k90/kernel
# load boot/k90/opensolaris.ko
# load boot/k90/krpc.ko
# load boot/k90/zfs.ko
# load -t boot/zfs/zpool.cache  boot/zfs/zpool.cache
# read-conf boot/loader.k90
```

At this point everything should be ready to go so that I can boot into my own system and correct the error from there. lsmod  shows kernel and all ko's as loaded, so I tell it to boot.  I can see my own custom kernel loading and nicely scrolling by, but then it stops with 'cannot mount root' message.  When I try to give it the root name:
[CMD=]mountroot> zfs:sysbsd/root[/CMD]
kernel panics and shuts down because it cannot (I assume) find the zpool. Any suggestions from here?  I planned on running the *gpart gptzfsboot* command once inside my native environment and hoped that this would resolve the problem.  However at this point I am wondering if my zpool.cache is somehow messed up - although I do not recall doing anything to the cache?


----------



## gkontos (Jun 6, 2011)

The reason for the panic is that you just loaded a kernel, some modules and that's it. Your system was trying to find /etc and /sbin in the USB stick.

Now, when you installed grub you did it in the mbr while your FreeBSD installation was using a gpt scheme. Boot with mfsBSD ZFSv28, it works fine with 9-Current. Then issue a:

[CMD=""]# gpart show[/CMD]

This should give you an idea of where the problem is. Normally you should see something this:

```
gkontos@hp>gpart show
=>       34  488397101  ada0  GPT  (232G)
         34        128     1  freebsd-boot  (64k)
        162  488396973     2  freebsd-zfs  (232G)
```
But in your case things will be different since grub has messed up your scheme. 
You can use either:

[CMD=""]# gpart recover[/CMD]

or just reinstall the freebsd-boot loader with:

[CMD=""]# gpart delete -i 1 ad0[/CMD]
[CMD=""]# gpart add -b 34 -s 64k -t freebsd-boot ad0[/CMD]
[CMD=""]# gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 ad0[/CMD]

Regards,


----------



## Beeblebrox (Jun 6, 2011)

Thanks gkontos, your analysis was correct.  I forgot that I had changed the flag on that 64k bios partition as bios-grub while trying to install grub.  The btx menu now comes up and system boots - fixed.

A Huge Thanks to you once more.


----------

