# How to pass "-o readonly=on" to ZFS root pool at startup?



## jyhpsycho (Mar 4, 2014)

I made a FreeBSD Installation USB memory stick. It uses ZFS as root instead of UFS2. I used `zfs set readonly=on` to the filesystem mounted as root, but I think that isn't sufficient. I want to make sure it does not perform any unnecessary writes to USB, not even ZFS' history logs. How to do this? I can't find the solution anywhere.


----------



## SirDice (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*



			
				jyhpsycho said:
			
		

> I used `zfs set readonly=on` to filesystem mounted as root, but I think that isn't sufficient.


Why do you think it's not sufficient?


----------



## jyhpsycho (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*



			
				SirDice said:
			
		

> jyhpsycho said:
> 
> 
> 
> ...



It prevents writes to individual filesystems, not to the whole pool. It seems that ZFS writes some pool metadata when mounting that to another system, thus zpool says

```
This pool seems to be used on another system
```
 when I import that pool later (for maintenance) on a system which I used to make installation media. It requires the -f option to import.


----------



## SirDice (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*

ZFS wasn't really built for USB sticks that move around. You have to `zpool export` the pool each time before you unplug it. Then you won't get that message.


----------



## jyhpsycho (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*



			
				SirDice said:
			
		

> You have to `zpool export` the pool each time before you unplug it. Then you won't get that message.



Is it really possible to export a zpool that contains a filesystem mounted as /? I used that USB to installation media like CD.

EDITED: And, it still writes some data means "it not cleanly unmounted before". I want to prevent that.


----------



## SirDice (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*

Tricky. It should be possible, the filesystem is mounted read-only. But you would be pulling the rug from under the running system. I don't think it's going to like that. Although ZFS is great it's not built for this.

Maybe you can add a `zpool export` somewhere in the shutdown routines. So when you shutdown, after it did all it's business, the last thing it does is the export. Perhaps that can be made to work.


----------



## jyhpsycho (Mar 4, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*

Thanks for the advice. I'll try it.


----------



## jyhpsycho (Mar 10, 2014)

*Re: How to pass "-o readonly=on" to ZFS root pool at startup*

Hmm, that does not suffice for me, either. ZFS still writes some pool metadata, and the USB stick goes wrong. It's not a good idea to use ZFS on a USB stick unless that supports a device-level read-only switch. Thanks for your attention


----------



## David NewHamlet (Jul 25, 2017)

This is a three years old topic and it match my case now.

In a embedded development task we need to use a zfs pool on compressed md_image (so the compressed image is readonly) as rootfs.
But the kernel always try to mount the zfs in read-write and failed because the underlyer device(md_image) is readonly.

vfs.root.mountfrom.options=ro in loader.conf only change the log text.


----------



## David NewHamlet (Jul 30, 2017)

Thanks for you reply. But in userspace user can import a pool on readonly device with -o readonly=on(zpool import -o readonly=on readonlytank). There is not such MUST be wrote metadata for readonly pool. I has dropped an issue to core term: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=221067


----------



## ShelLuser (Jul 30, 2017)

There's always the readonly property, tried setting that manually?


----------

