A lot of external storage solutions, nowadays, use the Universal Serial Bus (USB): hard drives, USB thumbdrives, CD-R burners, etc. FreeBSD provides support for these devices.
The USB mass storage devices driver, umass(4), provides the support for USB storage devices. If you use the GENERIC kernel, you do not have to change anything in your configuration. If you use a custom kernel, be sure that the following lines are present in your kernel configuration file:
device scbus device da device pass device uhci device ohci device ehci device usb device umass
The umass(4) driver uses the SCSI subsystem to access to the USB storage devices, your USB device will be seen as a SCSI device by the system. Depending on the USB chipset on your motherboard, you only need either device uhci or device ohci for USB 1.X support, however having both in the kernel configuration file is harmless. Support for USB 2.0 controllers is provided by the ehci(4) driver (the device ehci line). Do not forget to compile and install the new kernel if you added any lines.
Note: If your USB device is a CD-R or DVD burner, the SCSI CD-ROM driver, cd(4), must be added to the kernel via the line:
device cdSince the burner is seen as a SCSI drive, the driver atapicam(4) should not be used in the kernel configuration.
The configuration is ready to be tested: plug in your USB device, and in the system message buffer (dmesg(8)), the drive should appear as something like:
umass0: USB Solid state disk, rev 1.10/1.00, addr 2 GEOM: create disk da0 dp=0xc2d74850 da0 at umass-sim0 bus 0 target 0 lun 0 da0: <Generic Traveling Disk 1.11> Removable Direct Access SCSI-2 device da0: 1.000MB/s transfers da0: 126MB (258048 512 byte sectors: 64H 32S/T 126C)
Of course, the brand, the device node (da0) and other details can differ according to your configuration.
Since the USB device is seen as a SCSI one, the camcontrol command can be used to list the USB storage devices attached to the system:
# camcontrol devlist <Generic Traveling Disk 1.11> at scbus0 target 0 lun 0 (da0,pass0)
If the drive comes with a file system, you should be able to mount it. The Section 19.3 will help you to format and create partitions on the USB drive if needed.
Warning: Allowing untrusted users to mount arbitrary media, e.g., by enabling vfs.usermount as described below, should not be considered safe from a security point of view. Most file systems in FreeBSD were not built to safeguard against malicious devices.
To make this device mountable as a normal user, certain steps have to be taken. First, the devices that are created when a USB storage device is connected need to be accessible by the user. A solution is to make all users of these devices a member of the operator group. This is done with pw(8). Second, when the devices are created, the operator group should be able to read and write them. This is accomplished by adding these lines to /etc/devfs.rules:
[localrules=5] add path 'da*' mode 0660 group operator
Note: If there already are SCSI disks in the system, it must be done a bit different. E.g., if the system already contains disks da0 through da2 attached to the system, change the second line as follows:
add path 'da[3-9]*' mode 0660 group operatorThis will exclude the already existing disks from belonging to the operator group.
You also have to enable your devfs.rules(5) ruleset in your /etc/rc.conf file:
devfs_system_ruleset="localrules"
Next, the kernel has to be configured to allow regular users to mount file systems. The easiest way is to add the following line to /etc/sysctl.conf:
vfs.usermount=1
Note that this only takes effect after the next reboot. Alternatively, one can also use sysctl(8) to set this variable.
The final step is to create a directory where the file system is to be mounted. This directory needs to be owned by the user that is to mount the file system. One way to do that is for root to create a subdirectory owned by that user as /mnt/username (replace username by the login name of the actual user and usergroup by the user's primary group):
# mkdir /mnt/username # chown username:usergroup /mnt/username
Suppose a USB thumbdrive is plugged in, and a device /dev/da0s1 appears. Since these devices usually come preformatted with a FAT file system, one can mount them like this:
% mount -t msdosfs -o -m=644,-M=755 /dev/da0s1 /mnt/username
If you unplug the device (the disk must be unmounted before), you should see, in the system message buffer, something like the following:
umass0: at uhub0 port 1 (addr 2) disconnected (da0:umass-sim0:0:0:0): lost device (da0:umass-sim0:0:0:0): removing device entry GEOM: destroy disk da0 dp=0xc2d74850 umass0: detached
Beside the Adding Disks and Mounting and Unmounting File Systems sections, reading various manual pages may be also useful: umass(4), camcontrol(8), and usbconfig(8) under FreeBSD 8.X or usbdevs(8) under earlier versions of FreeBSD.