# Small and lean boot-environments



## Alain De Vos (Mar 16, 2022)

Using "bectl" I create boot-environments.
Now i want these boot-environments to be as "small/little" as possible.
I can do this by moving directories in separate datasets.
A few directories which come to my mind to remove them from the boot-environment are:

```
/usr/local/www
/usr/src
/var/backups
/var/cache
/var/crash
/var/db/pkg
/var/db/portsnap
/var/log
/var/tmp
```

Which of these directories do you think i can safely remove from the boot environment , and which of these directories should i by preference keep in the boot environment , i.e. are a bad idea to move them out?

Note 1 : Creating a separate dataset for /usr/src did not exclude this directory from the boot environment.
Note 2 : Creating a separate dataset for /usr/local/www did exclude this directory from the boot environment.

Weird behavior of bectl or to be expected ?


----------



## SirDice (Mar 16, 2022)

/var/log, /var/tmp, /var/crash and /usr/src aren't part of a boot environment. Not by default anyway.


```
dice@maelcum:~ % zfs list
NAME                 USED  AVAIL     REFER  MOUNTPOINT
zroot               13.9G  36.0G       88K  /zroot
zroot/ROOT          11.2G  36.0G       88K  none
zroot/ROOT/default  11.2G  36.0G     11.2G  /
zroot/tmp            113M  36.0G      113M  /tmp
zroot/usr           2.21G  36.0G       88K  /usr
zroot/usr/home       612K  36.0G      612K  /usr/home
zroot/usr/ports       88K  36.0G       88K  /usr/ports
zroot/usr/src       2.21G  36.0G     2.21G  /usr/src
zroot/var            357M  36.0G       88K  /var
zroot/var/audit       88K  36.0G       88K  /var/audit
zroot/var/crash       88K  36.0G       88K  /var/crash
zroot/var/log        355M  36.0G      355M  /var/log
zroot/var/mail      1.19M  36.0G     1.19M  /var/mail
zroot/var/tmp        112K  36.0G      112K  /var/tmp
```

You do want to keep /var/db/pkg part of the boot environment, it contains the database of installed packages.


----------



## Alain De Vos (Mar 16, 2022)

I might be "overmounting". I'll reboot in single user mode without zfs-mounts.
Indeed, it seemed i was zfs overmounting an already populated /usr/src


----------



## _martin (Mar 16, 2022)

This is interesting topic in a way. Not because of its size but by the approach. One thing I really don't like about the zfs output (underlining the word output, not zfs) is that you can't see the _canmount_ property of a fileset in a `zfs list`.
I very well might be stuck in oldschool view of things and I'm not necessarily doing it the best way but when it comes to the zfs layout I use these:
	
	



```
$ zfs list -r rpool
NAME                         USED  AVAIL  REFER  MOUNTPOINT
rpool                        113G  64.7G    31K  none
rpool/ROOT                  29.2G  64.7G    31K  none
rpool/ROOT/12.2git           362K  64.7G   765M  /
rpool/ROOT/12.2git/usr      81.5K  64.7G  12.4G  /usr
rpool/ROOT/12.2git/usr/src     1K  64.7G   798M  /usr/src
rpool/ROOT/12.2git/var       205K  64.7G  6.89G  /var
rpool/ROOT/12.3             29.2G  64.7G   769M  /
rpool/ROOT/12.3/usr         21.2G  64.7G  12.4G  /usr
rpool/ROOT/12.3/usr/src     2.60G  64.7G   804M  /usr/src
rpool/ROOT/12.3/var         7.14G  64.7G  6.37G  /var
rpool/empty                   31K  64.7G    31K  /var/empty
rpool/home                  28.7G  64.7G  25.8G  /home
rpool/local                 5.43M  64.7G  5.43M  /local
rpool/ports                  755M  64.7G   755M  /usr/ports
rpool/swap                  49.5G  92.4G  21.8G  -
rpool/tmp                   4.36G  64.7G  4.36G  /tmp
$
```
And I like the idea that I know that /, /usr and /usr/src are different filesets.

I don't care about BE size too much. I do need to switch from one to the other without user impact. Having /, /usr, /usr/src and /var part of the environment paid off many times before.


----------



## jbo (Mar 16, 2022)

_martin said:


> I do need to switch from one to the other without user impact. Having /, /usr, /usr/src and /var part of the environment paid off many times before.


I'd like to learn more about the situation(s) where having /usr/src being part of the BE helped. Can you elaborate?

Furthermore, just to make sure that I don't misunderstand anything: when you refer to "fileset" - are we talking "dataset" (ZFS terminology question)?


----------



## SirDice (Mar 16, 2022)

_martin said:


> One thing I really don't like about the zfs output (underlining the word output, not zfs) is that you can't see the _canmount_ property of a fileset in a `zfs list`.


This better?

```
dice@maelcum:~ % zfs list -o name,canmount,mountpoint
NAME                CANMOUNT  MOUNTPOINT
zroot               on        /zroot
zroot/ROOT          on        none
zroot/ROOT/default  noauto    /
zroot/tmp           on        /tmp
zroot/usr           off       /usr
zroot/usr/home      on        /usr/home
zroot/usr/ports     on        /usr/ports
zroot/usr/src       on        /usr/src
zroot/var           off       /var
zroot/var/audit     on        /var/audit
zroot/var/crash     on        /var/crash
zroot/var/log       on        /var/log
zroot/var/mail      on        /var/mail
zroot/var/tmp       on        /var/tmp
```


----------



## _martin (Mar 16, 2022)

You are correct, dataset, not fileset. That's a mistake on my side. Won't edit my response for clarity.

I'm using src to build new environment. For that it helps me greatly if I can "jump" from one env to the other without worrying if src was modified. I may discover that new upgrade is not ok (e.g. virtualbox is having issues, os bug triggers after a heavy load..) and I want clean jump back. I can mount my new BE to alt location and have a look what was wrong in logs, etc. without additional downtime and/or pressure to solve this. I treat it as a whole snapshot.


----------



## Alain De Vos (Mar 16, 2022)

For the record this is my current zfs list
I mount with fstab
/tmp & /var/tmp are tmpfs

zfs list -o name,canmount,mountpoint | egrep "var|usr" | grep ZT |sort | grep -v @ | grep -v jail

```
ZT/nosnapshot/xcache                          on        /usr/home/x/.cache
ZT/usr                                        off       none
ZT/usr/home                                   noauto    /usr/home
ZT/usr/local                                  off       none
ZT/usr/local/www                              noauto    /usr/local/www
ZT/usr/obj                                    noauto    /usr/obj
ZT/usr/ports                                  noauto    /usr/ports
ZT/usr/ports/distfiles                        noauto    /usr/ports/distfiles
ZT/usr/ports/packages                         noauto    /usr/ports/packages
ZT/usr/src                                    noauto    /usr/src
ZT/var                                        off       none
ZT/var/audit                                  noauto    /var/audit
ZT/var/cache                                  noauto    /var/cache
ZT/var/cache/netdata                          noauto    /var/cache/netdata
ZT/var/coredumps                              noauto    /var/coredumps
ZT/var/crash                                  noauto    /var/crash
ZT/var/db                                     off       none
ZT/var/db/influxdb                            noauto    /var/db/influxdb
ZT/var/db/mongodb                             noauto    /var/db/mongodb
ZT/var/db/mysql                               noauto    /var/db/mysql
ZT/var/db/mysql/dbx1                          noauto    /var/db/mysql/dbx1
ZT/var/db/netdata                             noauto    /var/db/netdata
ZT/var/db/postgres                            noauto    /var/db/postgres
ZT/var/db/redis                               noauto    /var/db/redis
ZT/var/db/sqlite                              noauto    /var/db/sqlite
ZT/var/games                                  noauto    /var/games
ZT/var/log                                    noauto    /var/log
ZT/var/mail                                   noauto    /var/mail
ZT/var/spool                                  noauto    /var/spool
ZT/var/www                                    noauto    /var/www
```


----------



## SirDice (Mar 16, 2022)

Alain De Vos said:


> I mount with fstab


Why?


----------



## Alain De Vos (Mar 16, 2022)

I once installed alpine linux on zfs and the freebsd zfs datasets became automaticly mounted creating lots of problems.
So i tried to avoid the situation of automouting when using different zfs O.S. installs.


----------



## grahamperrin@ (Mar 16, 2022)

Alain, this might be of interest:



grahamperrin said:


> … ⚙ D34538 bectl: add some discussion about boot environment layouts
> 
> Summary:



As things currently look (with the markup language it's a bit weird, but hopefully enough for you to get the gist):


----------

