# Boot environments: child datasets not activating



## cmh (Sep 15, 2020)

I am beginning to use boot environments on a system, and have moved my zfs datasets around within the pool to create child datasets of the boot environment's root dataset with the intention that these datasets be duplicated into the boot environment. However, the child datasets are not being activated when I use bectl. I am wondering what I am doing wrong.

Running `bectl create -r test` does what I expect. New zfs datasets appear associated with the root and the child datasets of the root.


```
root@xyzzy:/home/cmh # zfs list -o name,canmount,mountpoint
NAME                            CANMOUNT  MOUNTPOINT
zroot                                off  /zroot
zroot/ROOT                           off  none
zroot/ROOT/release-11.4               on  /
zroot/ROOT/release-11.4/local         on  /usr/local
zroot/ROOT/release-11.4/usrobj        on  /usr/obj
zroot/ROOT/release-11.4/usrsrc        on  /usr/src
--snip--

root@xyzzy:/home/cmh # bectl create -r test
root@xyzzy:/home/cmh # zfs list -o name,canmount,mountpoint
NAME                            CANMOUNT  MOUNTPOINT
zroot                                off  /zroot
zroot/ROOT                           off  none
zroot/ROOT/release-11.4               on  /
zroot/ROOT/release-11.4/local         on  /usr/local
zroot/ROOT/release-11.4/usrobj        on  /usr/obj
zroot/ROOT/release-11.4/usrsrc        on  /usr/src
zroot/ROOT/test                   noauto  /
zroot/ROOT/test/local             noauto  /usr/local
zroot/ROOT/test/usrobj            noauto  /usr/obj
zroot/ROOT/test/usrsrc            noauto  /usr/src
--snip--
```

However, running `bectl activate` does not set "canmount=on" on the child datasets of the new root. Upon rebooting, I have the new root, but I have the child datasets of the old root. This is counter to what I expect. The bectl documentation does not describe things in much detail. But I am wondering if I am doing something wrong given that some of these zfs filesystems were manually moved into position. Perhaps I am not inheriting some property that I should? 


```
root@xyzzy:/home/cmh # bectl activate test
successfully activated boot environment test
root@xyzzy:/home/cmh # zfs list -o name,canmount,mountpoint
NAME                            CANMOUNT  MOUNTPOINT
zroot                                off  /zroot
zroot/ROOT                           off  none
zroot/ROOT/release-11.4           noauto  /
zroot/ROOT/release-11.4/local         on  /usr/local
zroot/ROOT/release-11.4/usrobj        on  /usr/obj
zroot/ROOT/release-11.4/usrsrc        on  /usr/src
zroot/ROOT/test                   noauto  /
zroot/ROOT/test/local             noauto  /usr/local
zroot/ROOT/test/usrobj            noauto  /usr/obj
zroot/ROOT/test/usrsrc            noauto  /usr/src
--snip--
```

How can I get the child datasets to mount automatically when I change boot environments?

For interest, I am attaching the zfs properties for one of the child datasets in case this is helpful.


```
root@xyzzy:/home/cmh # zfs get  all zroot/ROOT/test/local
NAME                   PROPERTY              VALUE                                                SOURCE
zroot/ROOT/test/local  type                  filesystem                                           -
zroot/ROOT/test/local  creation              Tue Sep 15  9:53 2020                                -
zroot/ROOT/test/local  used                  8K                                                   -
zroot/ROOT/test/local  available             332G                                                 -
zroot/ROOT/test/local  referenced            3.89G                                                -
zroot/ROOT/test/local  compressratio         1.00x                                                -
zroot/ROOT/test/local  mounted               no                                                   -
zroot/ROOT/test/local  origin                zroot/ROOT/release-11.4/local@2020-09-15-09:53:20-0  -
zroot/ROOT/test/local  quota                 none                                                 default
zroot/ROOT/test/local  reservation           none                                                 default
zroot/ROOT/test/local  recordsize            128K                                                 default
zroot/ROOT/test/local  mountpoint            /usr/local                                           local
zroot/ROOT/test/local  sharenfs              off                                                  default
zroot/ROOT/test/local  checksum              on                                                   default
zroot/ROOT/test/local  compression           lz4                                                  inherited from zroot
zroot/ROOT/test/local  atime                 off                                                  inherited from zroot
zroot/ROOT/test/local  devices               on                                                   default
zroot/ROOT/test/local  exec                  on                                                   default
zroot/ROOT/test/local  setuid                on                                                   default
zroot/ROOT/test/local  readonly              off                                                  inherited from zroot/ROOT/test
zroot/ROOT/test/local  jailed                off                                                  default
zroot/ROOT/test/local  snapdir               hidden                                               default
zroot/ROOT/test/local  aclmode               discard                                              default
zroot/ROOT/test/local  aclinherit            restricted                                           default
zroot/ROOT/test/local  createtxg             23449181                                             -
zroot/ROOT/test/local  canmount              noauto                                               local
zroot/ROOT/test/local  xattr                 on                                                   default
zroot/ROOT/test/local  copies                1                                                    default
zroot/ROOT/test/local  version               5                                                    -
zroot/ROOT/test/local  utf8only              off                                                  -
zroot/ROOT/test/local  normalization         none                                                 -
zroot/ROOT/test/local  casesensitivity       sensitive                                            -
zroot/ROOT/test/local  vscan                 off                                                  default
zroot/ROOT/test/local  nbmand                off                                                  default
zroot/ROOT/test/local  sharesmb              off                                                  default
zroot/ROOT/test/local  refquota              none                                                 default
zroot/ROOT/test/local  refreservation        none                                                 default
zroot/ROOT/test/local  guid                  10200537805109230507                                 -
zroot/ROOT/test/local  primarycache          all                                                  default
zroot/ROOT/test/local  secondarycache        all                                                  default
zroot/ROOT/test/local  usedbysnapshots       0                                                    -
zroot/ROOT/test/local  usedbydataset         8K                                                   -
zroot/ROOT/test/local  usedbychildren        0                                                    -
zroot/ROOT/test/local  usedbyrefreservation  0                                                    -
zroot/ROOT/test/local  logbias               latency                                              default
zroot/ROOT/test/local  dedup                 off                                                  default
zroot/ROOT/test/local  mlslabel                                                                   -
zroot/ROOT/test/local  sync                  standard                                             default
zroot/ROOT/test/local  refcompressratio      3.27x                                                -
zroot/ROOT/test/local  written               8K                                                   -
zroot/ROOT/test/local  logicalused           2K                                                   -
zroot/ROOT/test/local  logicalreferenced     11.4G                                                -
zroot/ROOT/test/local  volmode               default                                              default
zroot/ROOT/test/local  filesystem_limit      none                                                 default
zroot/ROOT/test/local  snapshot_limit        none                                                 default
zroot/ROOT/test/local  filesystem_count      none                                                 default
zroot/ROOT/test/local  snapshot_count        none                                                 default
zroot/ROOT/test/local  redundant_metadata    all                                                  default
```


----------



## mickey (Sep 15, 2020)

cmh said:


> I am beginning to use boot environments on a system, and have moved my zfs datasets around within the pool to create child datasets of the boot environment's root dataset with the intention that these datasets be duplicated into the boot environment. However, the child datasets are not being activated when I use bectl. I am wondering what I am doing wrong.
> 
> Running `bectl create -r test` does what I expect. New zfs datasets appear associated with the root and the child datasets of the root.
> 
> ...


I think your problem lies with the canmount property being set to 'on' in the BE you manually put together, when it should be set to 'noauto'.


----------



## cmh (Sep 16, 2020)

mickey said:


> I think your problem lies with the canmount property being set to 'on' in the BE you manually put together, when it should be set to 'noauto'.



Thanks for the reply, but if child datasets are set to 'noauto' then they do not get mounted at boot time, right?


----------



## mickey (Sep 17, 2020)

cmh said:


> Thanks for the reply, but if child datasets are set to 'noauto' then they do not get mounted at boot time, right?


Mounting of a BE's child datasets is handled by /etc/rc.d/zfsbe (during a normal multi user boot at least). When booting single user you have to manually mount any child datasets or call aforementioned script to do it, When a dataset's canmount property is explictly on however, the dataset *will* get mounted at some point, possibly overriding an existing mount. I believe that's where your problem lies.


----------



## cmh (Sep 17, 2020)

Thanks, that is helpful and I was able to validate this, which solved my problem. 

Perhaps I have not thought through all the cases, but it does seem a bit opaque this way. In my view it would be more clear if `bectl activate` were to reset `canmount` to `on` on the new BE child datasets (and to `noauto` on the previous BE child datasets). This would be more transparent with respect to the normal functioning of zfs mounting... the way it is presently set up with /etc/rc.d/zfsbe introduces magic.

It would be helpful to have a note in the bectl manpage referencing the non-intuitive use of canmount and the /etc/rc.d/zfsbe script.


----------



## mickey (Sep 17, 2020)

cmh said:


> It would be helpful to have a note in the bectl manpage referencing the non-intuitive use of canmount and the /etc/rc.d/zfsbe script.


Agreed, to make matters worse, last time I was experimenting with bectl(8) and beadm(8) I noticed that both tools handled things a little differently and overall beadm(8) seemed a bit more mature. Where both failed was if you want/need to have an intentionally empty and not mountable child dataset like /usr or /var in your BE whose sole purpose is to inherit the mountpoint property to it's childs. When activating a BE containing such a child dataset, it's canmount property gets changed from off to either noauto or on and bad things will happen


----------

