# make release in custom directory



## sandm44n (Dec 12, 2018)

Hi all,

I'm trying to build FreeBSD from scratch in a custom directory. In my line of testing, I was able to get to start to finish by using the default directories (/usr/src and /usr/obj). However, I would like to now use a custom directory to specify where the source is and where the object files should be located, so that I can build it under Jenkins. I'm aware of the fact that there's a release.sh script that can do everything - build kernel, world, and installer images - however, I would eventually like to insert some additional steps after buildworld and buildkernel which is why I'm doing it this way.

I was succesful in buildworld and buildkernel by specifying the MAKEOBJDIRPREFIX variable in make - but I can't seem to figure out how to build the release iso.

Here's a rough outline of what I'm doing


```
cd /path/to/source
make buildkernel KERNCONF=CUSTOM MAKEOBJDIRPREFIX="`realpath ./obj`" SRCCONF="`realpath ./src.conf``" __MAKE_CONF="`realpath ./make.conf``"
make buildworld MAKEOBJDIRPREFIX="`realpath ./obj`" SRCCONF="`realpath ./src.conf`" __MAKE_CONF="`realpath ./make.conf`"
cd release
make release KERNCONF=CUSTOM MAKEOBJDIR="`realpath ../obj`" -DNO_ROOT
```

The make release failed, so I tried again but this time specifying CHROOTDIR and CHROOTBUILD_SKIP instead, which also didn't work. Here's the output of the current errors that I'm looking at for make release
https://pastebin.com/5BGCrMry

Please let me know if I'm going in the right direction, or if there's a better way to approach this!

Thanks


----------



## T-Daemon (Dec 12, 2018)

Hi sandm44n,

taking as reference 7. Building FreeBSD Installation Media - 7.1.1. The release.sh Script 
and release(7)


> The optional _release.conf_ configuration file supports the following vari-
> ables:
> 
> _CHROOTDIR_          The directory within which the release will be built.
> ...


the release.conf file is the right place to change all needed variables, not make


----------



## SirDice (Dec 12, 2018)

How I build my releases:

```
cd /usr/src
make buildworld buildkernel
cd /usr/src/release
make -DNOPORTS -DNODOC -DNOPKGS KERNCONF=GENERIC release
make -DNOPORTS -DNODOC -DNOPKGS KERNCONF=GENERIC DESTDIR=/storage/release/12-stable install
```
It doesn't matter where your source lives, it doesn't have to be /usr/src/ and you don't have to set anything if you use a different base directory. As long as the structure of the source tree itself remains the same. You already found WRKDIRPREFIX to change the default /usr/obj. You don't have to set anything else. The install stage will create a FTP directory under DESTDIR and will also store the ISO and memory stick images there.


----------



## sandm44n (Dec 12, 2018)

SirDice said:


> How I build my releases:
> 
> ```
> cd /usr/src
> ...


Is WRKDIRPREFIX separate from MAKEOBJDIRPREFIX?

This is currently what I'm doing to build the world and kernel

```
cd /usr/local/jenkins/workspace/testing
make buildkernel KERNCONF=CUSTOM __MAKE_CONF=`realpath ./make.conf` MAKEOBJDIRPREFIX=`realpath ./obj` -j8
make buildworld SRCCONF=`realpath ./src.conf` __MAKE_CONF=`realpath ./make.conf` MAKEOBJDIRPREFIX=`realpath ./obj` -j8
```
That part completes succesfully, and I see the directory structure inside the ./obj folder. However, when running a make release similar to what you're running

```
make -DNOPORTS -DNODOC -DNOPKGS KERNCONF=CUSTOM release
```
I get all kinds of errors
https://pastebin.com/3PiaGD6L

This same build procedure works fine with the source in /usr/src and the objects going into /usr/obj, as your setup is, but it seems that the moment I try to change these folders release breaks.


----------



## SirDice (Dec 12, 2018)

Oh, oops. Sorry, WRKDIRPREFIX is actually for building ports (it changes the work/ directory, useful if you have a read-only /usr/ports/). It's indeed MAKEOBJDIRPREFIX for building world and all.


----------



## sandm44n (Dec 14, 2018)

I figured out what the issue was - I'm leaving this here for any future readers.

I was specifying a make.conf and src.conf when building the world and kernel, but not when building the release. In those configuration files, I had disabled certain things that make release was trying to include as a dependency. By passing SRCCONF and __MAKE_CONF as environment variables to my make release, I was able to successfully create the ISO.

However, since this is not running as root, it seems like certain binaries and files are not getting their appropriate permissions set as I'm not running as root. For example, bsdinstall rootpass fails because the passwd file doesn't have the correct permissions. As a temporary workaround, I gave my jenkins user access to sudo without a password, but this is obviously not ideal. If anybody else has any experience on building a release dvd iso without root, I would appreciate any pointers.


----------

