Prepare Build Environment

This instruction based on page: "How To Build illumos"

To build dilos-illumos on DilOS you should follow the steps below.

NOTE:

You need to upgrade DilOS. This step is required only once and should be made only in the global zone before preparing the build environment. You need to have 'sudo' permissions for your build user for DEB packages generation process. Please update the /etc/sudoers file with the correct info. Instructions are based on updates and sources tree tag with update from 'dilos-unstable'. Add the repository below to the top of the /etc/apt/sources.list file:

deb http://apt.dilos.org/dilos dilos2-unstable main

and issue the following commands:

sudo apt-get update && sudo os-upgrade

You will be upgraded to new BE. Please reboot after successful upgrade.

It is not recommended to build DilOS in the global zone. It is suggested creating new zone for the building process. As an example refer to the following links for more details about zone and network configuration:

Zone creation: How to setup DPKG zone

Network configuration: How to configure NAT

It is recommended to have at least 2G of RAM and 2G of swap. To update swap size, use the steps below in a global zone, don't forget to reboot to enable swap:

Add swap:
$ sudo zfs set volsize=2g rpool/swap
$ sudo reboot

You can change the swap size on the fly. To do it do:

change the swap size on the fly
$ /usr/sbin/swap -lh
swapfile             dev    swaplo   blocks     free
/dev/zvol/dsk/rpool/swap 129,3        4K    2,00G    2,00G
$ sudo swap -d /dev/zvol/dsk/rpool/swap
$ sudo zfs set volsize=4g rpool/swap
$ sudo swap -a /dev/zvol/dsk/rpool/swap
$ /usr/sbin/swap -lh
swapfile             dev    swaplo   blocks     free
/dev/zvol/dsk/rpool/swap 129,3        4K    4,00G    4,00G

The build process should be run in the newly created zone from the user with the sudo permissions (not root). So, now while you are in the global zone check the id of yournonrootuser (like you did it for admin user when creating DPKG zone before).

Obtain non-root user id
$ id yournonrootuser

uid=1000(admin) gid=10(staff) groups=10(staff)

All the commands below should be executed in the newly created zone (not global) - login to the zone with root account.

Note : The NOPASSWD option should be added to your build user in the /etc/sudoers file.

Create a build user:
# useradd -u uidfromglobalzone -g staff -d /export/home/yournonrootuser -s /bin/bash yournonrootuser
# passwd yournonrootuser
# echo "yournonrootuser ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/yournonrootuser
# /system/bin/usermod -P 'Primary Administrator' yournonrootuser

After this you can re-login to the zone under this build user account and continue to do the following steps.

Install packages:
$ sudo apt-get install git ca-certificates
$ sudo update-ca-certificates -d # need it for first time

Prepare dilos-userland-gate clone: 

INFO

For clone dilos-illumos you have to create account on BitBucket and send it by BitBucket mail form to account 'dilos' - I'll add you to repo

$ git clone -b dilos2 https://bitbucket.org/dilos/dilos-illumos.git my-dilos-illumos
Install build dependencies:
$ cd my-dilos-illumos
$ tools/bld_pkgs.sh
Download and unpack closed binaries
$ sudo apt-get install wget
$ wget -c \
  https://download.joyent.com/pub/build/illumos/on-closed-bins.i386.tar.bz2 \
  https://download.joyent.com/pub/build/illumos/on-closed-bins-nd.i386.tar.bz2
$ tar xjvpf on-closed-bins.i386.tar.bz2
$ tar xjvpf on-closed-bins-nd.i386.tar.bz2

Prepare illumos.sh

Copy original illumos.sh:
$ cp usr/src/tools/env/illumos.sh .

The settings we are going to focus on for now are the following:

For GCC build only you have to add to your illumos.sh:

# on Intel and SPARC we use GCC6 that already defined on build system

export GNUC_ROOT="/usr/gcc/6"						# path to GCC binaries installed
export PRIMARY_CC=gcc6,/usr/lib/ccache/gcc-6,gnu
export PRIMARY_CCC=gcc6,/usr/lib/ccache/g++-6,gnu

# disable SMB_PRINTING
export ENABLE_SMB_PRINTING='#'

These variables are needed for the version identification and the DEB packages tools:

export GATE='2.0.2.40-dbg'							# it is variable will be updated on loading kernel screen.
export BLD_REVISION=$(git log -1 --pretty=format:%h)
export DEB_VERSION="2.0.2.40-1"					# DEB packages version, must be incremented for correct upgrade
export DEB_MAINTAINER="Igor Kozhukhov <ikozhukhov@gmail.com>"	# you can use your name here
export DPKG_BUILD_FLAGS="-b -d -uc"				# flags for dpkg-buildpackage. You can provide your flags.

Note:

Version in DEB_VERSION must be higher then current installed version of package 'libc-dev'

Check your version of libc using : dpkg -l | grep libc

Example:

If you have installed libc-2.0.2.7 for your build you can use: 

DEB_VERSION="2.0.2.7-2"

or

DEB_VERSION="2.0.2.8"

or another higher version

Prepare build tools:
$ ln -s usr/src/tools/scripts/bldenv .
$ ksh93 bldenv -d illumos.sh -c "cd usr/src && dmake setup"	# -d - if you use DEBUG build. You have to remove it for non-DEBUG build
# on SPARC:
$ sudo rm -rf /opt/onbld && sudo cp -ax usr/src/tools/proto/root_sparc-nd/opt/onbld /opt/
# Or on Intel:
$ sudo rm -rf /opt/onbld && sudo cp -ax usr/src/tools/proto/root_i386-nd/opt/onbld /opt/

Start Build

INFO

Will be better to start build process on 'screen' terminal. You can install it by command:

$ sudo apt-get install screen

If you modified profile to "Primary administrator" by usermod, you need to re-login to the build zone (or via ssh)

To run the full build procedure, please issue the commands below:

$ cp usr/src/tools/scripts/nightly .
$ time ./nightly illumos.sh

Note that the command does not give any progress output. You can instead follow the log file at log/nightly.log, which is updated (slowly) during the build process. In another terminal, run:

$ tail -f log/nightly.log

For the incremental build, the following command can be used (don't forget to increase the DEB_VERSION number):

$ time ./nightly -i illumos.sh

Update to New Build

Update Using apt-get

New build should be installed from the global zone. Add the build path to the apt repo list, for instance it could be something like:

$ cat /etc/apt/sources.list
# Main repository sources
deb [trusted=yes] file:///export/home/admin/my-dilos-illumos/packages/i386/apt unstable main
deb http://apt.dilos.org/dilos dilos-testing main contrib non-free

Issue an apt-get update command to check get new deb packets information. Check that there are no issues with new repo. Note that it is OK to get the warning message below:

$ sudo apt-get update
...
Reading package lists... Done                                                   
W: The repository 'file:/export/home/dim/my-dilos-illumos/packages/i386/apt unstable Release' is not signed. 
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use. 
N: See apt-secure(8) manpage for repository creation and user configuration details.

Run upgrade procedure:

$ sudo os-upgrade
...
upgrade done

Updating bootarchive ...
Activating 'dilos_<version>' ...

Now you can reboot to new 'dilos_<version>'.