# Config for make buildworld on Raspi



## photor-freebsd (Dec 8, 2016)

Hello Forum,

FreeBSD training - next step: I try to update the system the old way using `make buildworld`, `make buildkernel`, `make installkernel` and `make installworld` on my Raspi. The first step (`make buildworld` is running for 20 h now - and seems to do so for some more time. 
So, this seems to be  major task and I want to know,

if and where I can optimize the config to shorten this procedure?
how to avoid building things, that I do (probably) not need? (e.g. remove certain parts of the source tree, specify certain targets)
how can I optimize the kernel config? does anybody have an example config (original one is found at `/usr/src/sys/arm/conf/RPI2`, right)?  
Raspi comes with 4 kernels; at the moment only 1 is utilized; I remember that I can set an option (e.g. "-j3"); where to put this, that it is always used for world and kernel compilation
The above was triggered by the _FreeBSD-SA-16:37.libc_. I guess, in principle the binary-way (`freebsd-update fetch`, `freebsd-update install`) should also work. And maybe it will be the choice in future 

Ciao,

Photor


----------



## SirDice (Dec 8, 2016)

photor-freebsd said:


> how to avoid building things, that I do (probably) not need? (e.g. remove certain parts of the source tree, specify certain targets)


Have a look at src.conf(5).



photor-freebsd said:


> how can I optimize the kernel config? does anybody have an example config (original one is found at  /usr/src/sys/arm/conf/RPI2, right)?


There isn't much to optimize, but even if you do it'll only shave off a couple of minutes from the entire build. The buildworld step is the most time consuming.



photor-freebsd said:


> Raspi comes with 4 kernels; at the moment only 1 is utilized; I remember that I can set an option (e.g. "-j3"); where to put this, that it is always used for world and kernel compilation


I'm sure you meant 4 _cores_, not 4 _kernels_. You can add it to the buildworld step, for buildkernel it's not recommended, for the install* bits it's useless (they need to be executed in order at all times).


----------



## photor-freebsd (Dec 8, 2016)

SirDice said:


> Have a look at src.conf(5).
> 
> 
> There isn't much to optimize, but even if you do it'll only shave off a couple of minutes from the entire build. The buildworld step is the most time consuming.
> ...


Of course, you are right. 4 cores.

As the buildworld is the most time consuming it may make sense to try with "j 3" - I will test this. I will also check for the /etc/src.conf.

Thank you,

Photor

For the record: I tried `make buildworld -j5` which ended with error. Restart without `-j`-option (cleaned the source tree, of course) went through without error. So, better don't use on RasPi. (aded on 2017-01-23)


----------



## photor-freebsd (Dec 9, 2016)

Hello,

as told in the first post here I did the above because of the FreeBSD-SA-16:37.libc. In the accompanying mail a procedure is decribed downloading a patch and applying that using `patch`-comand.

Is it also possible to use `svn update /usr/src` and the start the buildworld-procedure (binary update does not seem to work with Raspi)? From my understanding this should be equivalent.

Ciao,

Photor


----------



## SirDice (Dec 10, 2016)

photor-freebsd said:


> Is it also possible to use  svn update /usr/src and the start the buildworld-procedure (binary update does not seem to work with Raspi)? From my understanding this should be equivalent.


Yes, both the /stable/ and /releng/ branches get the security patches too. So if you update the source the patch will be included.


----------



## abishai (Dec 11, 2016)

SirDice said:


> for buildkernel it's not recommended


Wow, I know nothing about this, I always compiled with -j option. Can you point me where to read about this?


----------



## photor-freebsd (Dec 13, 2016)

Hello Forum,

questions for the next step: I have done the `make buildworld`-step. Now - if I remember correct - I have to do the kernel compilation:

```
root@riker:/usr/src # make buildkernel
make[1]: "/usr/src/Makefile.inc1" line 144: SYSTEM_COMPILER: Determined that CC=cc matches the source tree.  Not bootstrapping a cross-compiler.
ERROR: Missing kernel configuration file(s) (GENERIC).
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src
root@riker:/usr/src #
```
I guess, this is because I have not configured any kernel; I wanted to create the GENERIC kernel without any changes (test run). REMARK: this is running on an Raspberry Pi 2

```
root@riker:/usr/src # uname -a
FreeBSD riker.mydomain.home 11.0-STABLE FreeBSD 11.0-STABLE #0 r309280: Wed Nov 30 08:11:18 UTC 2016     root@releng2.nyi.freebsd.org:/usr/obj/arm.armv6/usr/src/sys/RPI2  arm
```
So, I think I have to put a kernel config somewhere. This config used for the installed kernel is found in /usr/src/sys/arm/conf/RPI2, right? (no GENERIC config found).

Ciao,

Photor


PS: my knowledge is based on earlier uses of FreeBSD 7


----------



## SirDice (Dec 13, 2016)

Use `make buildkernel KERNCONF=RPI2` or add to /etc/make.conf:

```
KERNCONF=RPI2
```


----------



## kpa (Dec 13, 2016)

abishai said:


> Wow, I know nothing about this, I always compiled with -j option. Can you point me where to read about this?



Actually you can use -j N for buildkernel, the bugs that were once causing problems have been solved long ago. It's only the install* targets that should be run without parallel jobs.


----------



## photor-freebsd (Dec 13, 2016)

Thank you. The `make buildkernel` is started 

Ciao,

Photor


----------



## photor-freebsd (Dec 13, 2016)

... and `make installkernel` stopped with:

```
===> zlib (install)
install: zlib.ko: No such file or directory
*** Error code 71

Stop.
make[4]: stopped in /usr/src/sys/modules/zlib
*** Error code 1

Stop.
make[3]: stopped in /usr/src/sys/modules
*** Error code 1

Stop.
make[2]: stopped in /usr/obj/usr/src/sys/RPI2
*** Error code 1

Stop.
make[1]: stopped in /usr/src
*** Error code 1

Stop.
make: stopped in /usr/src
root@riker: /usr/src
```
1st question: is the system still in acondition to reboot safely?
2nd question: what to do to come over this `zlib`-error?

Ciao,

Photor

PS: output copied by hand


----------



## SirDice (Dec 13, 2016)

You need to tell it which kernel to install or else it'll try to install GENERIC, `make installkernel KERNCONF=RPI2`.

It's best to add this to /etc/make.conf so it's always applied.


----------



## photor-freebsd (Dec 13, 2016)

SirDice said:


> You need to tell it which kernel to install or else it'll try to install GENERIC, `make installkernel KERNCONF=RPI2`.
> 
> It's best to add this to /etc/make.conf so it's always applied.



Thank you SirDice, but that's what I did. /etc/make.conf now contains

```
KERNCONF=RPI2
```
Anything else is left commented. And from `make buildkernel`-step it looked like, as if this config was taken. Even the `make installkernel` procedure installed everything up to the lines quoted by me above. Problem seems to be zlib.

Ciao,

Photor


----------



## photor-freebsd (Dec 16, 2016)

Just for completeness: I updated /usr/src and started `make buildworld`-process again. And now it worked (except for the fact that /tmp - a tmpfs - was not big enough; I set /var/tmp as TMP for a while). It was a two-days-journey.

```
$ uname -a
FreeBSD riker.mydomain.home 11.0-STABLE FreeBSD 11.0-STABLE #1 r310064: Thu Dec 15 20:56:34 CET 2016     root@riker.mydomain.home:/usr/obj/usr/src/sys/RPI2  arm
```

Ciao,
Photor


----------



## ekingston (Dec 16, 2016)

Wow, looks like you did it. I would have cross-compiled.

Pi3?
Have you tried all the hardware? 
Wifi? 
bluetooth? 
HDMI? 
HDMI with sound?
The Pi Camera?
The Pi touchscreen thing?


----------



## Phishfry (Dec 16, 2016)

Pi touchscreen and camera are accessories and would need to added to your DTB to work. There is no Plug and Play on Arm.

https://www.raspberrypi.org/documentation/configuration/device-tree.md


----------



## Phishfry (Dec 16, 2016)

There is a new mechanism on ARM64-RPI3 as well called Device Tree Overlay for adding devices..


----------



## photor-freebsd (Dec 19, 2016)

ekingston said:


> Wow, looks like you did it. I would have cross-compiled.
> 
> Pi3?
> Have you tried all the hardware?
> ...


No, it is a Raspi 2 Model B. That's why I thought it would all that without any trouble. 

At the moment I have none of these extra hardware: Monitor is connected using HDMI, no sound; . It was planned to be a training tool for my rusty FreeBSD skills. Next Steps would be installing some packages (web server, maybe X or all headless) or it will migrate to a NAS  and home server(connected over net and with USB-console cable). Learning target: the (for me) "new" package system.  

Ciao,

Photor


----------



## photor-freebsd (Dec 30, 2016)

Hello Forum,

additional questions: during `make installworld` I run into trouble because of too small size of /tmp. At the moment /tmp it is set to 50 MB in /etc/fstab

```
tmpfs /tmp tmpfs rw,mode=1777,size=50m 0 0
```
What is a sensible size for `installworld`? I can just enlarge in /etc/fstab and it will be used after next reboot, right? /tmp is a filesystem just memory and grows as it is needed (up to max value specified), right?

Ciao,

Photor


PS: this is running on a Raspi Model B (1 GB RAM)


----------



## SirDice (Dec 30, 2016)

I haven't built it often on the Pi because it takes forever. But try removing it altogether and put /tmp on disk. Make sure the directory has 1777 permissions.


----------



## photor-freebsd (Dec 30, 2016)

SirDice said:


> I haven't built it often on the Pi because it takes forever.


 OK. Roughly 1.5 days. That's not "forever" 




SirDice said:


> But try removing it altogether and put /tmp on disk. Make sure the directory has 1777 permissions.


 Disk means SDCard. That is similar to `set TMPDIR /var/tmp` for some time, right? But I will try.

Thank you,

Photor


----------

