# Boot on GPT ZFS - What am I doing wrong?



## SocialHaze (Sep 29, 2011)

I'm trying to boot from a ZFS pool on GPT partition.


```
BTX loader 1.00 BTX version is 1.02
BIOS drive C: is disk0

FreeBSD/x86 ZFS enabled bootstrap loader, Revision 1.1

can't load 'kernel'

Type '?' for a list of commands, 'help' for more detailed help.
OK lsdev
disk devices:
disk0 BIOS drive C:
disk0s1: FFS bad disklabel
zfs devices: 
OK lsmod
OK
```


```
FreeBSD-8.2-RELEASE-amd64-livefs.iso
SHA256=f72ff7e9043f200651ca6dff3a4b71ec9447319c6efc419a2f6922a921bdfc68
```


```
Fixit# gpart show -l
=> ad4 GPT
1 /dev/ad4p1 (freebsd-boot)
3 /dev/ad4p3 (freebsd-zfs)

Fixit# gpart bootcode -b /dist/boot/pmbr -p /dist/boot/gptzfsloader -i 1 /dev/ad4p1
```


```
Fixit# zpool status
pool: zpool
state: ONLINE
config:
zpool ONLINE
ad4p3 ONLINE

Fixit# zpool get bootfs zpool
zpool bootfs zpool local

Fixit# zfs get mountpoint zpool
zpool mountpoint legacy local
```


```
Fixit# cd /zpool/boot
Fixit# ls -l
drw------- 2 root 0 2 Feb 17 2011 zfs/

Fixit# cp -f defaults/loader.conf .
Fixit# cat loader.conf
vfs.root.mountfrom="zfs:zpool"
zfs_load="YES"
```

Filesystem was taken from /dist/ on the livefs.  All of it is read-only except /boot/zfs.

Thoughts?


----------



## davidgurvich (Sep 29, 2011)

What were the gpart commands you used to partition the drive?  Also, have you looked at the http://wiki.freebsd.org/ZFSOnRootWithZFSboot page?


----------



## kpa (Sep 29, 2011)

Did you create a /boot/loader.conf with those lines? It looks like you edited /boot/defaults/loader.conf instead which is a no-no.


----------



## SocialHaze (Sep 29, 2011)

davidgurvich said:
			
		

> What were the gpart commands you used to partition the drive?  Also, have you looked at the http://wiki.freebsd.org/ZFSOnRootWithZFSboot page?



I don't think that's relevant, however the commands were:


```
gpart create -s gpt /dev/ad4
gpart add -s size -t type -l label /dev/ad4
```

Where type is one of freebsd-boot or freebsd-zfs.  I also looked at several tutorials, the best one likely being Installing FreeBSD Root on ZFS using GPT.

However at this point I'd really need the input of someone who understands what's happening with the boot loader, that it cannot detect the filesystem.




			
				kpa said:
			
		

> Did you create a /boot/loader.conf with those lines? It looks like you edited /boot/defaults/loader.conf instead which is a no-no.



The /boot/defaults/loader.conf was copied to the /boot directory before being edited.  The only modifications to the default were the two lines mentioned.


----------



## wblock@ (Sep 29, 2011)

Sceak said:
			
		

> The /boot/defaults/loader.conf was copied to the /boot directory before being edited.  The only modifications to the default were the two lines mentioned.



That defeats the purpose of the separate defaults file.  /boot/defaults/loader.conf is read, then any settings in /boot/loader.conf override them.

So just put the changes in /boot/loader.conf and let the defaults come from /boot/defaults/loader.conf automatically.


----------



## usdmatt (Sep 29, 2011)

At first I thought maybe you hadn't installed the kernel to your pool, or you'd forgotten to


```
cp -Rlp /zpool/boot/GENERIC/* /zpool/boot/kernel/
```

as I get the same "can't load kernel" error if I move my /boot/kernel directory. However, I still see the pool listed under the output of lsdev on my test machine and you appear not to. This is what mine looks like (copied by hand)


```
disk devices:
 disk1: BIOS drive C:
  disk1p1: FreeBSD boot
  disk1p2: FreeBSD ZFS
zfs devices
 zfs0: tank
```

If I were you I would do the following:

Reinstall the bootcode. The command you posted is wrong (the last arg should be the device not the partition). Your disk does appear to boot but the loader finds no pool & complains about bad labels so I would try that first. I'm also wondering if the 'gpart bootcode' command you have posted is not actually the exact one you used and you have installed a non-gpt aware loader by mistake?


```
gpart bootcode -b /dist/boot/pmbr -p /dist/boot/gptzfsloader -i 1 /dev/ad4
```

I would then go back into fixit, create a /boot/zfs directory, import the pool and copy the /boot/zfs/zpool.cache onto the pool again. Your /zpool/boot/zfs directory seems to have a 2 next to it which suggests to me that it's empty. I usually replace the zpool.cache file as a matter of course if I import into fixit as I'm never sure if it will 'grab' the pool and stop it importing into the main system I'm trying to install/fix.

Other than that I can't think of many reasons why it shouldn't boot unless it's some hardware fault. The bootfs property/loader/etc all look ok.


----------



## SocialHaze (Sep 30, 2011)

I'm pleased to report that I was able to boot from a ZFS filesystem on a GPT partition.

I restarted from the tutorial and the only thing I think I did differently this time was to set the sector 0 boot loader to the default, non-interactive boot loader using fdisk.

It was quite the introduction to FreeBSD, but so far so good.


Thank you all for your attention and your assistance.


----------



## wblock@ (Sep 30, 2011)

That's... a little weird.  fdisk(8) is for MBR partition schemes, gpart(8) is what should be used now.

Oh, and also, it's

```
gpart bootcode -b /dist/boot/pmbr -p /dist/boot/[color="Red"]gptzfsboot[/color] -i 1 /dev/ad4
```


----------



## kpa (Sep 30, 2011)

It probably works because the standard MBR and the protected MBR /boot/pmbr do roughly the same things but the protected version has a "hands off" flag turned on for the pseudo partition that covers the whole disk. Use of the protected MBR is recommended of course with GPT disks.


----------

