How to Modify the FreeBSD 7 Kernel to Add DTrace Support

Published Date Author: , Posted October 21st, 2009 at 9:48:21am

Here is a quick-start guide: http://wiki.freebsd.org/DTrace

The kernel config files are located in: /usr/src/sys/{ARCH}/conf. Create a new one called DTRACE:
[code]
# cd /usr/src/sys/amd64/conf
# cp GENERIC DTRACE
# vim DTRACE
[/code]

For DTrace support, add the following options:

[code]
options KDTRACE_HOOKS # all architectures – enable general DTrace hooks
options DDB_CTF # all architectures – kernel ELF linker loads CTF data
options KDTRACE_FRAME # amd64 only
[/code]

All sources must be rebuilt and installed with CTF options. The system will need to be restarted.
To accomplish this task, rebuild the FreeBSD sources using:

[code]
# cd /usr/src
# make buildkernel KERNCONF=DTRACE WITH_CTF=1
# make installkernel KERNCONF=DTRACE
# shutdown -r NOW
…reboot…
# kldload dtraceall
# dtrace -l | head
[/code]

After rebooting and allowing the new kernel to be loaded into memory, support for the Korn shell should be added. This is needed as the DTrace toolkit has several utilities written in ksh. Install the /usr/ports/shells/ksh93.

Finally, obtain the current DTrace toolkit. The current version is available at http://sourceforge.net/projects/dtracetoolkit/. There is an install mechanism included; however, installation is not required to make use of the bundled utilities.

If you are running seclevel > -1, add the following to the top of /etc/rc.conf:
[code]kldload_enable="YES"[/code]
Then create a file in /usr/local/etc/rc.d called kldload:
[code]
#!/bin/ksh
#
# PROVIDE: kldload
# REQUIRE: LOGIN

. /etc/rc.subr

name=kldload
rcvar=set_rcvar
start_cmd="kldload dtraceall"

load_rc_config ${name}
run_rc_command "$1"
[/code]

No comments as yet.

Leave Your Comment  Leave a comment

All fields marked with "*" are required.