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 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, however having both in the kernel configuration file is harmless. Do not forget to compile and install the new kernel if you added any lines.
Notatka: 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 cd
Since the burner is seen as a SCSI drive, the driver atapicam(4) should not be used in the kernel configuration.
Support for USB 2.0 controllers is provided on FreeBSD; however, you must add:
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 Sekcja 18.3 will help you to format and create partitions on the USB drive if needed.
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=1] add path 'da*' mode 0660 group operator
Notatka: 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 operator
This 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:
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:
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/$USER (replace $USER by the login name of the actual user):
# mkdir /mnt/$USER # chown $USER:$USER /mnt/$USER
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_msdosfs -m 644 -M 755 /dev/da0s1 /mnt/$USER
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
Ten i inne dokumenty można pobrać z ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/.
W przypadku pytań o FreeBSD prosimy przeczytać dostępną dokumentację przed kontaktem z <questions@FreeBSD.org>.
W sprawie zapytań o tę dokumentację prosimy o kontakt z <doc@FreeBSD.org>.