The cfumass(4) driver is a USB device mode driver first available in FreeBSD 12.0.
Mass Storage target is provided by templates 0 and 10. Both usb_template(4) and cfumass(4) kernel modules must be loaded. cfumass(4) interfaces to the CTL subsystem, the same one that is used for iSCSI or Fibre Channel targets. On the host side, USB Mass Storage initiators can only access a single LUN, LUN 0.
The simplest way to set up a read-only USB storage target
	is to use the cfumass rc script.  To
	configure it this way, copy the files to be presented to the
	USB host machine into the /var/cfumass
	directory, and add this line to
	/etc/rc.conf:
cfumass_enable="YES"
To configure the target without restarting, run this command:
#service cfumass start
Differently from serial and network functionality, the
	template should not be set to 0 or 10 in
	/boot/loader.conf.  This is because the
	LUN must be set up before setting the template.  The cfumass
	startup script sets the correct template number automatically
	when started.
The rest of this chapter provides detailed description of setting the target without using the cfumass rc file. This is necessary if eg one wants to provide a writeable LUN.
USB Mass Storage does not require the
	ctld(8) daemon to be running, although it can be used if
	desired.  This is different from iSCSI.
	Thus, there are two ways to configure the target:
	ctladm(8), or ctld(8).  Both require the
	cfumass.ko kernel module to be loaded.
	The module can be loaded manually:
#kldload cfumass
If cfumass.ko has not been built into
	the kernel, /boot/loader.conf can be set
	to load the module at boot:
cfumass_load="YES"
A LUN can be created without the ctld(8) daemon:
#ctladm create -b block -o file=/data/target0
This presents the contents of the image file
	/data/target0 as a LUN
	to the USB host.  The file must exist
	before executing the command.  To configure the
	LUN at system startup, add the command to
	/etc/rc.local.
ctld(8) can also be used to manage
	LUNs.  Create
	/etc/ctl.conf, add a line to
	/etc/rc.conf to make sure ctld(8) is
	automatically started at boot, and then start the
	daemon.
This is an example of a simple
	/etc/ctl.conf configuration file.  Refer
	to ctl.conf(5) for a more complete description of the
	options.
target naa.50015178f369f092 {
	lun 0 {
		path /data/target0
		size 4G
	}
}The example creates a single target with a single
	LUN.  The
	naa.50015178f369f092 is a device identifier
	composed of 32 random hexadecimal digits.  The
	path line defines the full path to a file
	or zvol backing the LUN.  That file must
	exist before starting ctld(8).  The second line is
	optional and specifies the size of the
	LUN.
To make sure the ctld(8) daemon is started at
	boot, add this line to
	/etc/rc.conf:
ctld_enable="YES"
To start ctld(8) now, run this command:
#service ctld start
As the ctld(8) daemon is started, it reads
	/etc/ctl.conf.  If this file is edited
	after the daemon starts, reload the changes so they take
	effect immediately:
#service ctld reload
All FreeBSD documents are available for download at https://download.freebsd.org/ftp/doc/
Questions that are not answered by the
    documentation may be
    sent to <freebsd-questions@FreeBSD.org>.
    Send questions about this document to <freebsd-doc@FreeBSD.org>.