documentation:technical_docs
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | documentation:technical_docs [2018/08/20 07:46] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Technical documentation for developers ====== | ||
+ | {{description> | ||
+ | |||
+ | |||
+ | ====== NanoBSD ====== | ||
+ | |||
+ | The first step was to understand [[Documentation: | ||
+ | |||
+ | ====== How to build BSDRP images ====== | ||
+ | |||
+ | All theses steps are done from a FreeBSD system. | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | ===== Prerequisite ===== | ||
+ | |||
+ | You need 3G of free space (1G for FreeBSD installation, | ||
+ | |||
+ | |||
+ | ==== Getting BSDRP source code ==== | ||
+ | |||
+ | You can download the source code of BSDRP with svnlite (included in FreeBSD): | ||
+ | |||
+ | < | ||
+ | pkg install ca_root_nss | ||
+ | svnlite co https:// | ||
+ | cd BSDRP | ||
+ | </ | ||
+ | |||
+ | or using git if you had installed it: | ||
+ | < | ||
+ | pkg install ca_root_nss | ||
+ | git clone https:// | ||
+ | </ | ||
+ | |||
+ | Once you download the code, you can kept your BSDRP sources up-to-date with these commands: | ||
+ | < | ||
+ | svnlite update | git pull | ||
+ | ./make -u | ||
+ | </ | ||
+ | |||
+ | ===== make.sh flowshart ===== | ||
+ | |||
+ | Here is the big picture regarding BSDRP image build process: | ||
+ | |||
+ | {{BSDRP.framework.flowshart.png| BSDRP build framework flowshart}} | ||
+ | |||
+ | ===== Running the build script ===== | ||
+ | |||
+ | Display the options proposed by the make.sh script : | ||
+ | |||
+ | < | ||
+ | ./make.sh -h | ||
+ | </ | ||
+ | |||
+ | The FreeBSD code include all architecture and limited cross-compiling tools: You can generate an i386 BSDRP image from a FreeBSD amd64, but you can't generate a sparc64 image from an i386/amd64 host. | ||
+ | ===== Current problems with make ===== | ||
+ | |||
+ | ==== Disk image creation can fail ==== | ||
+ | |||
+ | On FreeBSD dektop, sometimes NanoBSD can't umount the md during image creation. | ||
+ | |||
+ | "fstat | grep BSDRP" display the name of the process locking the temporary mount point. It can be: | ||
+ | * gam_server | ||
+ | * gvfsd-trash | ||
+ | |||
+ | here is the log of a failed build: | ||
+ | |||
+ | < | ||
+ | ### log : / | ||
+ | Error encountered. Check errors in last log file. | ||
+ | Running exit trap code | ||
+ | root@dev # tail -n 4 / | ||
+ | unmount: unmount of / | ||
+ | </ | ||
+ | |||
+ | ==== gam_server ==== | ||
+ | For preventing gamin to lock the working mount point, create this configuration file and force a restart of gamin: | ||
+ | < | ||
+ | mkdir / | ||
+ | echo "fsset ufs poll 10" > / | ||
+ | killall -9 gam_server | ||
+ | </ | ||
+ | |||
+ | ==== gvfsd-trash ==== | ||
+ | |||
+ | I don't know how to fix this gvfs bug. | ||
+ | |||
+ | ====== How to generate customized BSDRP images ====== | ||
+ | |||
+ | If you want to generate your customized BSDRP image, first try to build one generic BSDRP image from source. | ||
+ | |||
+ | You can check the files of the project " | ||
+ | A child project overwrite the MASTER_PROJECT files/ | ||
+ | |||
+ | If this step works for you, then you can begin to customize it. | ||
+ | |||
+ | ===== Customizing BSDRP in few slides ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== main files ===== | ||
+ | |||
+ | ==== make.conf ==== | ||
+ | |||
+ | This file include the main global information for building the image: | ||
+ | * NAME: Name of the Project | ||
+ | * MASTER_PROJECT: | ||
+ | * SVN_SRC_PATH: | ||
+ | * SVN_PORTS_PATH: | ||
+ | * FREEBSD_SRC: | ||
+ | * SRC_PATCH_DIR: | ||
+ | * PORTS_SRC: Directory for locally stored ports source tree | ||
+ | * PORT_PATCH_DIR: | ||
+ | * DISK_SIZE : Size in MB of the destination disk | ||
+ | * NANOBSD_DIR: | ||
+ | * NANO_MODULES_ARCH: | ||
+ | |||
+ | |||
+ | ==== $PROJECT/ | ||
+ | |||
+ | This file include all the customization steps: | ||
+ | |||
+ | You can change the: | ||
+ | * Size of configuration partition (NANO_CONFSIZE) | ||
+ | * Size of data partition (NANO_DATASIZE) | ||
+ | * Size of the /etc RAM disk (NANO_RAM_ETCSIZE) | ||
+ | * Size of the /tmp, /var RAM disk (NANO_RAM_TMPVARSIZE) | ||
+ | * and so one… | ||
+ | * | ||
+ | You can declare new package (and their dependency, but only if they use special option) to be installed: For example, if you want to add vim-lite, you add theses lines: | ||
+ | |||
+ | < | ||
+ | add_port " | ||
+ | add_port " | ||
+ | </ | ||
+ | |||
+ | If you need to set special permission on some file after their installation, | ||
+ | |||
+ | ==== $PROJECT/ | ||
+ | |||
+ | This directory include the kernel configuration files. | ||
+ | You need to edit these files and the NANO_MODULES_$ARCH variable in the make.conf for customizing your own kernel and modules. | ||
+ | ==== $PROJECT/ | ||
+ | |||
+ | All files put in the Files/ directory will be copied to the BSDRP image. | ||
+ | |||
+ | ===== Little child project example ===== | ||
+ | |||
+ | Here is a little example (minimum modification) for building a new project based on BSDRP, but for a web server appliance: | ||
+ | This project will be a child project of BSDRP. | ||
+ | |||
+ | Start by downloading BSDRP source code (refers to getting BSDRP source code chapter) and go in the BSDRP directory. | ||
+ | |||
+ | Then create a new directory using your project name: | ||
+ | < | ||
+ | |||
+ | === make.conf === | ||
+ | |||
+ | Now we need to configure a minimum project configuration file: | ||
+ | |||
+ | < | ||
+ | echo ' | ||
+ | echo ' | ||
+ | </ | ||
+ | |||
+ | === Listing all run-dependency of your ports === | ||
+ | |||
+ | We want to add the port www/mohawk. | ||
+ | |||
+ | The first step is to list all run-deps of this port. | ||
+ | |||
+ | You need to have downloaded the FreeBSD port-tree first (automatically done if you've already generated one BSDRP image). | ||
+ | |||
+ | If you've installed BSDRP on / | ||
+ | < | ||
+ | setenv PORTSDIR / | ||
+ | cd $PORTSDIR/ | ||
+ | make run-depends-list | ||
+ | devel/ | ||
+ | </ | ||
+ | |||
+ | Here we need devel/ | ||
+ | |||
+ | === project.nano === | ||
+ | |||
+ | Now we will copy the nanobsd configuration file from BSDRP: | ||
+ | < | ||
+ | cp BSDRP/ | ||
+ | </ | ||
+ | |||
+ | Edit the file WEBSRV/ | ||
+ | < | ||
+ | add_port " | ||
+ | </ | ||
+ | |||
+ | And add (in the #### Ports list section #####) all the running dependency and your port: | ||
+ | |||
+ | < | ||
+ | add_port " | ||
+ | add_port " | ||
+ | </ | ||
+ | |||
+ | Remove theses lines that compile and install extra small tools too: | ||
+ | < | ||
+ | customize_cmd add_netrate | ||
+ | </ | ||
+ | |||
+ | Then modify the bsdrp_custom () function in this file too for removing the quagga chown hack. | ||
+ | |||
+ | === Files/ | ||
+ | |||
+ | Now set-up the version number: | ||
+ | < | ||
+ | mkdir -p WEBSRV/ | ||
+ | echo ' | ||
+ | </ | ||
+ | |||
+ | === Generating image === | ||
+ | |||
+ | Now you should generate a full new image: | ||
+ | |||
+ | < | ||
+ | root@laptop:/ | ||
+ | BSD Router Project image build script | ||
+ | |||
+ | Will generate an WEBSRV image with theses values: | ||
+ | - Target architecture: | ||
+ | - Console : -vga | ||
+ | - Source Updating/ | ||
+ | - Build the full world (take about 1 hour): YES | ||
+ | - FAST mode (skip compression and checksumming): | ||
+ | - TMPFS: NO | ||
+ | - Debug image type: NO | ||
+ | Copying amd64 Kernel configuration file | ||
+ | Launching NanoBSD build process... | ||
+ | 00:00:00 # NanoBSD image WEBSRV build starting | ||
+ | 00:00:00 ## Clean and create object directory (/ | ||
+ | 00:00:00 ## Construct build make.conf (/ | ||
+ | 00:00:00 ## run buildworld | ||
+ | 00:00:00 ### log: / | ||
+ | 00:15:03 ## build kernel (amd64) | ||
+ | 00:15:03 ### log: / | ||
+ | 00:17:50 ## Clean and create world directory (/ | ||
+ | 00:17:50 ## Construct install make.conf (/ | ||
+ | 00:17:50 ## installworld | ||
+ | 00:17:50 ### log: / | ||
+ | 00:18:29 ## install /etc | ||
+ | 00:18:29 ### log: / | ||
+ | 00:18:30 ## configure nanobsd /etc | ||
+ | 00:18:30 ## install kernel (amd64) | ||
+ | 00:18:30 ### log: / | ||
+ | 00:18:33 ## run customize scripts | ||
+ | 00:18:33 ## customize " | ||
+ | 00:18:33 ### log: / | ||
+ | 00:18:33 ## customize " | ||
+ | 00:18:33 ### log: / | ||
+ | 00:18:34 ## customize " | ||
+ | 00:18:34 ### log: / | ||
+ | 00:18:34 ## customize " | ||
+ | 00:18:34 ### log: / | ||
+ | 00:18:34 ## customize " | ||
+ | 00:18:34 ### log: / | ||
+ | 00:18:34 ## customize " | ||
+ | 00:18:34 ### log: / | ||
+ | 00:18:38 ## customize " | ||
+ | 00:18:38 ### log: / | ||
+ | 00:18:38 ## customize " | ||
+ | 00:18:38 ### log: / | ||
+ | 00:18:38 ## configure nanobsd setup | ||
+ | 00:18:38 ### log: / | ||
+ | 00:18:39 ## run late customize scripts | ||
+ | 00:18:39 ## build diskimage | ||
+ | 00:18:39 ### log: / | ||
+ | 00:19:02 # NanoBSD image WEBSRV completed | ||
+ | unmounting | ||
+ | / | ||
+ | NanoBSD build seems finish successfully. | ||
+ | Compressing WEBSRV upgrade image... | ||
+ | / | ||
+ | 100 % 26.2 MiB / 101.9 MiB = 0.257 3.0 MiB/s | ||
+ | Generating checksum for WEBSRV upgrade image... | ||
+ | WEBSRV upgrade image file here: | ||
+ | / | ||
+ | Compressing WEBSRV full image... | ||
+ | / | ||
+ | 100 % 26.2 MiB / 244.1 MiB = 0.107 5.3 MiB/s | ||
+ | Generating checksum for WEBSRV full image... | ||
+ | Zipped WEBSRV full image file here: | ||
+ | / | ||
+ | Zipping and renaming mtree... | ||
+ | / | ||
+ | 100 % 262.3 KiB / 1753.4 KiB = 0.150 | ||
+ | HIDS reference file here: | ||
+ | / | ||
+ | Done ! | ||
+ | </ | ||
+ | |||
+ | ====== How to modify an existing image ====== | ||
+ | |||
+ | All theses step are done from a FreeBSD system using a unziped BSDRP full-image. | ||
+ | |||
+ | ===== Partition layout of a BSDRP image ===== | ||
+ | |||
+ | Here are all partition found in a BSDRP-full image: | ||
+ | |||
+ | * s1a: first system partition (UFS labeled as BSDRPs1a) | ||
+ | * s2a: Second system partition, didn't exist if the system was never upgraded (UFS labeled as BSDRPs2a) | ||
+ | * s3: cfg partition (UFS labeled as BSDRPs3) | ||
+ | * s4: data partition (UFS labeled as BSDRPs4) | ||
+ | |||
+ | FreeBSD call " | ||
+ | |||
+ | ===== Mounting a BSDRP image as a memory disk ===== | ||
+ | |||
+ | ==== Automated way ==== | ||
+ | |||
+ | Use the script include with BSDRP sources: | ||
+ | ./ | ||
+ | ./ | ||
+ | |||
+ | ==== Manual way ==== | ||
+ | Using the BSDRP image file, create a memory disk (md): | ||
+ | |||
+ | < | ||
+ | mdconfig -a -t vnode -f BSDRP_0.35_full_i386_serial.img -x 63 -y 16 | ||
+ | </ | ||
+ | The system will display the md name created: | ||
+ | |||
+ | < | ||
+ | md0 | ||
+ | </ | ||
+ | |||
+ | Now list all partitions on this md: | ||
+ | |||
+ | < | ||
+ | # ls /dev/md0* | ||
+ | # / | ||
+ | </ | ||
+ | |||
+ | You should found the s1a (system) and s3 (cfg) partition. | ||
+ | Mount the system partition for example: | ||
+ | |||
+ | < | ||
+ | mount /dev/md0s1a /mnt | ||
+ | </ | ||
+ | |||
+ | Now you can do all your changes on the image. | ||
+ | |||
+ | And the end, umount and close the memory disk: | ||
+ | < | ||
+ | umount /mnt | ||
+ | mdconfig -d -u 0 | ||
+ | </ | ||
+ | |||
+ | ==== Increasing /etc and /var RAM disk size ===== | ||
+ | |||
+ | Mount the filesystem in read-write mode: | ||
+ | |||
+ | < | ||
+ | [root@BSDRP]/# | ||
+ | </ | ||
+ | |||
+ | And change the value in these files: | ||
+ | |||
+ | * / | ||
+ | * / | ||
+ | |||
+ | The remount the filesystem in read-only and reboot (answer " | ||
+ | |||
+ | < | ||
+ | [root@BSDRP]/ | ||
+ | [root@BSDRP]/ | ||
+ | </ | ||
+ | |||
+ | ====== How to debug ====== | ||
+ | |||
+ | Here are some advice for debugging. | ||
+ | |||
+ | ===== Performance optimization ===== | ||
+ | |||
+ | You can found more information about FreeBSD on the [[Documentation: | ||
+ | |||
+ | ===== Shell script ===== | ||
+ | |||
+ | Start your script with "sh -x": | ||
+ | |||
+ | < | ||
+ | [root@router]~# | ||
+ | </ | ||
+ | |||
+ | ===== RC script ====== | ||
+ | |||
+ | If you want to create some RC scripts, you need to start by reading [[http:// | ||
+ | |||
documentation/technical_docs.txt · Last modified: 2024/04/04 13:05 by olivier