Translations of this page:

Technical documentation for developers

Discovering NanoBSD

The first step was to discover NanoBSD.

All notes are write here: NanoBSD

How to build from sources

All theses steps are done from an FreeBSD system

prerequisite

Getting FreeBSD sources

You need an up-to-date FreeBSD sources.

You can download the FreeBSD-current sources following theses steps:

Copy the standard-supfile to /etc:

cp /usr/share/examples/cvsup/standard-supfile /etc

Then edit /etc/standard-supfile and replace the line:

*default host=CHANGE_THIS.FreeBSD.org

with,for example:

*default host=cvsup2.FreeBSD.org

And check that this line is correct if you want 7.2 sources:

*default release=cvs tag=RELENG_7_2

Or this if you want 8.0 sources:

*default release=cvs tag=RELENG_8_0

You can found other cvsup mirrors here

Then, download the source with this command:

csup /etc/standard-supfile

Getting FreeBSD ports tree

You need an up-to-date FreeBSD ports tree.

Download/extract the ports source tree:

portsnap fetch extract update

Installing Subversion

You need to install subversion:

cd /usr/ports/devel/subversion
make install clean

Getting BSDRP source code

Once subversion installed, you can download the source code of BSDRP with theses commands:

cd /usr/src/tools/tools/nanobsd
svn co https://bsdrp.svn.sourceforge.net/svnroot/bsdrp/trunk BSDRP
cd BSDRP

Once you download the code, you can kept your sources up-to-date with these commands:

cd /usr/src/tools/tools/nanobsd/BSDRP
svn update

Running the build script

Display the options proposed by the make.sh script :

./make.sh -h

The FreeBSD code include all architecture and cross-compiling tools: You can generate an i386 BSDRP image from a FreeBSD amd64.

Current problems with make

Using FreeBSD 8.0 Beta

Using an up-to-date current code can prevent the build process to failed: Sometimes, there are bug in the current that prevent build world or build kernel to finish.

FreeBSD project have a tinderbox server that report all current compilation problem: Check it's log for the "HEAD" branch.

In general, re-sync your code few hours later fix the problem or introduce a new in other part :-)

Disk image creation can fail

If you had installed gamin on your FreeBSD, sometimes NanoBSD can't umount the md during image creation. “fstat /usr/obj/nanobsd.bsdrp/_.mnt” show that the process gam_server (gamin) lock the mount point.

here is the log of a failed build:


Copying worlddir...
307484 blocks
Filesystem  1K-blocks   Used  Avail Capacity iused ifree %iused  Mounted on
/dev/md0s1a    293632 157919 112222    58%    4831 34335   12%   /usr/obj/nanobsd.bsdrp/_.mnt
Generating mtree...
umount: unmount of /usr/obj/nanobsd.bsdrp/_.mnt failed: Device busy
Filesystem  1K-blocks   Used  Avail Capacity iused ifree %iused  Mounted on
/dev/md0s1a    293632 157453 112688    58%    4831 34335   12%   /usr/obj/nanobsd.bsdrp/_.mnt
umount: unmount of /usr/obj/nanobsd.bsdrp/_.mnt failed: Device busy
mdconfig: ioctl(/dev/mdctl): Device busy

For prevent gamin to lock the working mount point, create this configuration file and force a restart of gamin:

mkdir /usr/local/etc/gamin
echo "fsset ufs poll 10" > /usr/local/etc/gamin/gaminrc
killall -9 gam_server

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
  • s2a: Second system partition, didn't exist if the system was never upgraded
  • s3: cfg partition
  • s4: data partition

FreeBSD call “slide” (s) an MBR partition.

Mounting a BSDRP image as a memory disk

Automated way

Use the script include with BSDRP sources: ./image_tool.sh mount <filename> ./image_tool.sh umount

Manual way

Using the BSDRP image file, create a memory disk (md):

mdconfig -a -t vnode -f BSDRP-i386-vga-ad0.img -x 63 -y 16

The system will display the md name created:

md0

Now list all partitions on this md:

# ls /dev/md0*
# /dev/md0    /dev/md0s1  /dev/md0s1a /dev/md0s2  /dev/md0s3

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

How to run

Qemu

Note: I don't know how to boot Qemu from a simulated USB drive (image generated with disk as “da0”).

You can use the qemu script for FreeBSD or follow theses advices:

Convert image to Qemu format

Is not mandatory to convert raw BSDRP image for being use under Qemu, but the qcow2 image is a lot's smaller.

bunzip2 BSDRP_0.3_full_amd64_vga.img.bz2
qemu-img convert -f raw -O qcow2 BSDRP_0.3_full_amd64_vga.img BSDRP_0.3_full_amd64_vga.qcow2

Starting amd64 release

If you generated an amd64 release, with console as “vga” and disk as “ad0”:

qemu-system-x86_64 -hda /usr/obj/nanobsd.bsdrp/BSDRP.img

If you generated an amd64 release, with console as “serial” and disk as “ad0”:

You can tell to qemu option to will disable vga card, and redirect serial to standard output:

qemu-system-x86_64 -nographic -hda /usr/obj/nanobsd.bsdrp/BSDRP.img

Or you can use a vnc as a console:

qemu-system-x86_64 -hda /usr/obj/nanobsd.bsdrp/BSDRP.img -vnc :0
vncviewer localhost

Starting i386 release

For the i386 release, with console as “vga” and disk as “ad0”:

qemu -net nic,model=rtl8139 -hda /usr/obj/nanobsd.bsdrp/BSDRP.img

(You need to change the default emulated NIC on the “Empty base image” because I've forgot to add the corresponding drivers into the kernel).

Create an ethernet link between your host and the virtual machine

As root, creat the virtual TAP interface and assign it an IP address:

ifconfig tap0 create
ifconfig tap0 10.0.0.1/24

Then, start qemu linked to this TAP interface:

qemu -hda BSDRP.img -net nic,model=rtl8139 -net tap,ifname=tap0 -localtime -kernel-kqemu

At the end, you can delete the TAP interface:

ifconfig tap0 destroy

When you shutdown your qemu machine, the tap interface change to state “down”, you need to re-configure it to up before re-use it:

ifconfig tap0 up

Sun xVM Virtual Box

How to use Sun xVM Virtual Box (Ver 3.0.4).

  • Convert Image
  • Creating multi images (setting different UUID)

Convert raw image file to vdi image file

Using the Virtual Box command line tool, convert the raw image file to vdi:

bunzip2 BSDRP_0.3_full_amd64_vga.img.bz2
VBoxManage convertfromraw BSDRP.img bsdrp.vdi --format vdi
VirtualBox Command Line Management Interface Version 3.0.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

Converting from raw image file="BSDRP.img" to file="bsdrp.vdi"...
Creating dynamic image with size 999968256 bytes (954MB)...

Creating multiple images

Create a copy for example R1

VBoxManage clonehd bsdrp.vdi r1.vdi --format VDI
VirtualBox Command Line Management Interface Version 3.0.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'VDI'. UUID: 87002bab-42ec-4656-9658-6ebe27178445

If you copied an image with the file system of the operating system, you need to generate a new UUID for the disk or it will not be accepted in Virtual Box if you are using the original.

Change the UUID of vdi image R2.vdi for example

VBoxManage internalcommands sethduuid r2.vdi
VirtualBox Command Line Management Interface Version 3.0.4
(C) 2005-2009 Sun Microsystems, Inc.
All rights reserved.

UUID changed to: da4de103-c139-436f-a76a-b8f1e743f269

How to debug

Here are some advice for debugging.

Performance optimization

You can found more information about FreeBSD on the Performance page.

Shell script

Start your script with “sh -x”:

 
documentation/technical_docs.txt · Last modified: 2010/01/12 14:53 by olivier
 
Except where otherwise noted, content on this wiki is licensed under the following license:modified BSD license
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki