How to auto-detect a USB drive?

Polytropon freebsd at
Wed Mar 11 07:52:55 PDT 2009

On Wed, 11 Mar 2009 07:42:04 -0700 (PDT), Peter Steele <psteele at> wrote:
> I want to have a process running on my FreeBSD box that
> automatically detects when a USB drive is inserted. What's
> the easiest way to accomplish this? I know I could simply
> monitor /var/log/messages and look for the appropriate
> events to appear, but is there a more elegant way? 

The system will monitor it itself. :-)

My question to you would be: What exactly do you mean by
"automatically detect"? The drive *is* automatically detected.
Should it be mounted afterwards?

The creation of the device files (after system startup) is
controlled by the file /etc/devfs.rules.

You can use automounters to automatically mount devices when
they appear. In order how to determine file systems, slices
and partitions on such an USB device, you could, for example,
have a look at how FreeSBIE does it.

Additionally, there are already tools integrated in KDE and
Gnome that automount USB devices.

>From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list