Enabling dtrace on Freebsd

My freshly installed FreeBSD9 does not have dtrace? While using it I got this error:

dtrace: failed to initialize dtrace: DTrace device not available on system 

Doing a “kldstat” command query, dtrace kernel module was not listed.

And reading further:

http://forums.freebsd.org/showthread.php?t=19385

The answer given was to read:

http://wiki.freebsd.org/DTrace

But that seemed to take too much time, so I start investigating the kernel module – first “cd /boot/kernel” to go to the kernel modules directory:

kldload if_ath

kldload: can't load if_ath: File exists

Oops, this kernel modules is already loaded – as verified via “kldstat”. And just trying another file:

kldload dtrace
kldload dtraceall

No error message, so it seemed by default dtrace-related kernel module are not loaded? Not always, sometimes mismatched errors occurred (eg, after another FreeBSD 8.1 installation), and so rebulding the kernel modules are needed.

Steps are as followed:

cd /usr/src/sys/amd64/conf
cp GENERIC MYDTKERNEL

And inside MYDTKERNEL file:

options KDTRACE_FRAME # Ensure frames are compiled in
options KDTRACE_HOOKS # Kernel DTrace hooks

Other options are instruction to backup the current kernel to /boot/kernel.old and this is not enabled by default – my advice is to enable it.

config MYDTKERNEL

And you will see that ../compile/MYDTKERNEL returned, now cd to this directory and continue the compilation:

make depend
make
make install

Hopefully the above will all work without producing an error. If you get an error, like me, getting and “No space left on device” error, what I do is to move the /boot/kernel.old directory to the /usr directory which still have lots of space left. Next reboot the machine, and do a “kldstat” to check that dtrace is loaded or not, which is not.


cd /boot/kernel
kldload dtrace
kldload dtraceall

References:

http://www.freebsd.org/doc/handbook/kernelconfig-building.html

http://silverwraith.com/papers/freebsd-kernel.php

Advertisements

One response to this post.

  1. I downloaded and installed the FreeBSD9.1 32-bit, and later found dtrace not available error. So first download the source code:

    ftp://ftp.freebsd.org/pub/FreeBSD/releases/i386/9.1-RELEASE/src.txz

    Untar the txz into the /usr/src directory.

    cd /usr/src/sys/i386/conf/

    Copy and create the “MYKERNEL” file:

    cp GENERIC MYKERNEL

    Now modify the file “MYKERNEL” to add the following three lines:

    makeoptions WITH_CTF=1
    options KDTRACE_HOOKS # Kernel DTrace hooks
    options DDB_CTF

    Next cd to this directory:

    cd to /usr/src:

    Compile the new kernel by specifying the name of the custom kernel configuration file:

    make buildkernel KERNCONF=MYKERNEL

    Install the new kernel:

    make installkernel KERNCONF=MYKERNEL

    Now reboot into the newly compiled kernel, and then load the dtrace kernel modules via kldload, and now dtrace work.

    References:

    http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-building.html

    http://forums.freebsd.org/showthread.php?t=29172

    Reply

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: