# How to create a zpool.cache from livefs?



## exscape (May 22, 2009)

I'm a bit stuck here. I'm trying to clone a computer to a VM. So, I booted from a LiveFS CD, partitioned/sliced the disk, copied the files using zfs send/recv and scp (for the UFS /boot). The kernel boots just fine, but it won't mount my ZFS root.
I get:


```
Trying to mount root from zfs:tank/root
Manual root filesystem specification:
<fstype>:<device> blah blah...
```

So, I tried 
	
	



```
vfs.zfs.debug=1
```
 and it turns out it's looking for the guid 203643... and/or ad0s1e (which is the case on the "real", cloned computer, I guess (and know for the slice)!), but finds da0s1d and 522839... which is the case on THIS one.
I then noticed/realized that I need to update /boot/zfs/zpool.cache. So I booted up the livefs, imported the pool (*zpool import -R /alt tank*) and exported it. No zpool.cache anywhere.
It seems that you MUST import it WITHOUT altroot (-R), but if I do that, the entire environment goes FUBAR when the CD / is shadowed by my ZFS root, and nothing works!

So, my question is: how am I supposed to create the file if I can't import the pool, and importing the pool is the only way?


----------



## exscape (May 22, 2009)

I finally fixed this. Finally as in I've been at it constantly for like 2.5 hours. Ugh.
Anyway, this post led me on the right path. What I did was, something like:

Boot LiveFS, choose fixit mode

```
cd /mnt2/boot/kernel
kldload ./opensolaris.ko ; kldload ./zfs.ko
```
(I knew this far already, but then I did: )

```
zpool import -f -R /alt tank
zfs set mountpoint=none tank/root
mkdir /boot/zfs
zpool export tank; zpool import tank
export LD_LIBRARY_PATH=/mnt2/lib (I think?)
mkdir /myboot; mount /dev/da0s1a /myboot
cp /boot/zfs/zpool.cache /myboot/boot/zfs/
zfs unmount -a
zfs set mountpoint=/ tank/root
reboot
```

It took me a fair amount of tries until I managed to find that damn zpool.cache. I *think* it was being removed when I exported the pool, but I'm not sure.


----------



## Ximalas (Oct 17, 2011)

*Configuring and installing ZFS from 9.x?*

How would you accomplish this using the 9.0 CDs and DVDs? Gone are the MFS previously used by the CDs and DVDs, thus no place to temporary save the /boot/zfs/zpool.cache file prior to transferring it to your boot data set.

Until this minor setback is resolved, I guess you either need an existing system or you need to install from 8.2-RELEASE, prior to configuring your new zroot data pool and its associated file systems.


----------



## gkontos (Oct 17, 2011)

Ximalas said:
			
		

> How would you accomplish this using the 9.0 CDs and DVDs? Gone are the MFS previously used by the CDs and DVDs, thus no place to temporary save the /boot/zfs/zpool.cache file prior to transferring it to your boot data set.
> 
> Until this minor setback is resolved, I guess you either need an existing system or you need to install from 8.2-RELEASE, prior to configuring your new zroot data pool and its associated file systems.


You can do it using in a different method.


----------



## Ximalas (Oct 18, 2011)

gkontos said:
			
		

> You can do it using in a different method.



Thank you, I did another Google search and the link you posted came up.
Here's my write up from yesterday.


----------



## jarosm (May 31, 2013)

Hi,

I was having similar problem. I have got own distro with read only root fs. So I needed mount little partition to /boot/zfs. It was simply, but this mountpoint has mounted after the zpool tried import pool via, still non exist, /boot/zfs/zpool.cache.

There is my solution:

/etc/rc.d/bootzpool

```
#!/bin/sh
#

# PROVIDE: bootzpool
# BEFORE: zvol zfs
# KEYWORD: nojail

. /etc/rc.subr

name="bootzpool"
start_cmd="bootzpool_start"
stop_cmd="bootzpool_stop"
load_rc_config $name
: ${bootzpool_dev:=/dev/da0s1d}

rcvar="zfs_enable"

bootzpool_start()
{
        echo "mounting /boot/zfs..."
        /sbin/fsck -t ufs $bootzpool_dev >/dev/null 2>&1 && \
                /sbin/mount -o noatime $bootzpool_dev /boot/zfs >/dev/null 2>&1
}

bootzpool_stop()
{
        /sbin/umount /boot/zfs
}

load_rc_config $name
run_rc_command "$1"
```


----------



## jarosm (May 31, 2013)

Last two lines in the scripts are needless. I forgot them from old tested version.

And one important note: the zfs has to be loaded like as a module. If the zfs is included in kernel, this hack won't work.


----------

