# NanoBSD with /cfg on zpool



## Deever (Mar 17, 2016)

Hi folks!

I'm trying to install FreeBSD on an SD card, but with the /cfg stored on a zpool. Here is my approach:


```
FlashDevice generic 2g
NANO_BOOTLOADER="/boot/boot0"
NANO_MODULES="default"
NANO_LABEL="nanobsd"

cust_zfs_load () (
  touch ${NANO_WORLDDIR}/boot/loader.conf
  echo "zfs_load=\"YES\"" >> ${NANO_WORLDDIR}/boot/loader.conf
  rm -r ${NANO_WORLDDIR}/boot/zfs
  ln -s /etc/zfs ${NANO_WORLDDIR}/boot/zfs
  sed -i '' -e ',/cfg,d' ${NANO_WORLDDIR}/etc/fstab
  echo "nanobsd/cfg /cfg zfs rw 0 0" >> ${NANO_WORLDDIR}/etc/fstab
  sed -i '' -e 's,mount -a -t,zpool import nanobsd; cp -R /cfg/* /etc; mount -a -t,' ${NANO_WORLDDIR}/etc/rc.d/mountcritlocal
)

cust_root () (
  echo $PASSWORD | chroot ${NANO_WORLDDIR} pw usermod root -h 0
)

customize_cmd cust_zfs_load
customize_cmd cust_root
customize_cmd cust_allow_ssh_root
```
I know it's very ugly, but simply creating a ZFS automounted under /cfg didn't work because of the zpool.cache file missing. With this /cfg/rc.conf, at least the network is being configured, however the hostname(1) NOT being set:


```
hostname="nanobsd.local"
ifconfig_em0="DHCP"
```

Questions:

Why doesn't setting the hostname work this way while setting up networking works? (The hostname variable is simply ignored)
How can this be done without changing code under /etc/rc.d and so that it works?
I had to set NANO_BOOTLOADER and NANO_MODULES to restore default behavior. Are there other things I need to revert to make NanoBSD behave like plain FreeBSD (besides the read-only stuff, which of course still should be the case)?
Is there a way to make /var persistent? How can I remove the /var md(4) (and use /var from zpool)?
Thanks for answering!

Greetings,
/dev


----------



## Deever (Mar 20, 2016)

Hello? Noone familiar with NanoBSD?


----------



## ondra_knezour (Mar 20, 2016)

Those two documents may contain something which may inspire you
http://2010.eurobsdcon.org/fileadmin/fe_user/pmh/5Ubt34.pdf
https://2010.asiabsdcon.org/papers/abc2010-P4A-paper.pdf


----------



## Deever (Mar 21, 2016)

Thank you! /etc/rc.initdiskless was the right hint! But I've got new problems now:
-Creating/modifying content below /conf in cust_* functions is not possible because the directory /conf doesn't exist anymore when the cust_* functions are run. I had to modify nanobsd.sh and add the line

```
echo "zpool import -f nanobsd" >> conf/default/etc/remount
```
after that one

```
echo "mount -o ro /dev/${NANO_DRIVE}s3" > conf/default/etc/remount
```
Is that possible without patching existing files?
-Booting the image I get the error on the screen shot. Importing the pool works actually, just the system refuses to do it itself.


----------

