For the complete documentation index, see llms.txt. This page is also available as Markdown.

25.3 Automatic File System Mounting

FreeBSD provides multiple methods for automatic mounting.

Automount

Note

automount has limited permission control for regular users and primarily performs mount operations as root; if finer-grained permission control is needed, DSBMD is recommended.

automount is built into the FreeBSD base system and works with devd(8) to monitor device insertion events and automatically perform mount operations. The default mount point is located in the /media directory.

The /etc/auto_master file controls the behavior of automount. View this file:

#
# Automounter master map, see auto_master(5) for details.
#
/net		-hosts		-nobrowse,nosuid,intr
#/media		-media		-nosuid,noatime,autoro
#/-		-noauto

File description:

Option
Description

-hosts

Queries remote NFS servers and maps their exported shares

-media

Queries devices that are not yet mounted but contain valid file systems. Typically used to access files on removable media

-noauto

Mounts file systems configured as noauto in fstab(5)

-null

Prevents automountd(8) from mounting anything

To automatically mount removable media, remove the comment symbol at the beginning of the /media line in the /etc/auto_master file, as follows:

After that, add the following content to the device state monitoring daemon configuration file /etc/devd.conf:

Note

This should not be added between existing comments.

Enable autofs(4) to start automatically at boot by adding the following line to /etc/rc.conf:

Each automountable file system will have a corresponding directory under /media/. The directory is named after the file system label. If the label is missing, the directory name will be based on the device node. View the mounted files:

The file system is automatically mounted on first access and automatically unmounted after being idle for a period of time. You can also manually unmount automounted devices:

Unresolved Issues

Chinese Character Garbling

Append -L=zh_CN.UTF-8 to the end of the /media line in /etc/auto_master. Note that -L=zh_CN.UTF-8 is a proprietary parameter of mount_msdosfs(8), and mount programs for other file systems cannot recognize this parameter, which will cause other devices to fail to mount.

References:

DSBMD Automount

DSBMD (Desktop Scriptable Block Device Manager Daemon) is a media and file system type detection daemon for FreeBSD. It uses a client-server architecture that allows clients to mount storage devices in a controlled manner. The default configuration can automatically detect and mount removable media.

Installing DSBMD

The DSBMD system consists of a daemon and clients, which can be installed in the following ways:

  • Install using the pkg package manager:

  • Or compile and install using the Ports system:

Clients can be selectively installed based on actual needs. In a desktop environment, the dsbmc graphical client is recommended for ease of use.

Configuring DSBMD

Technical Note

The DSBMD system is divided into two components: the daemon and the client. The client sends requests to DSBMD to mount, unmount, or eject media, and can also set the read speed of CD/DVD drives; the daemon receives and executes these requests. The daemon is a privileged system process with permissions to perform all operations, while the client, as a regular user process, is limited by system permission settings. Mount requests from users with insufficient permissions are verified by the daemon against user and group settings in the configuration file before deciding whether to allow them.

The daemon configuration file is located at /usr/local/etc/dsbmd.conf.

By default, members of the wheel and operator user groups can mount devices. If you need to grant mount permissions to other users, modify the relevant configuration items in the configuration file.

To enable the daemon, run the following commands:

Qt Client

The dsbmc client only sends requests to the daemon when it is running, so the client program needs to be started in the desktop environment.

After starting dsbmc, its icon can be observed in the system tray area.

System Tray

Open the main window, click preferencesgeneral settings in sequence, and check automatically mount devices to enable the automount feature.

Graphical Interface
Settings Automount

After inserting removable media such as a USB drive, the system desktop will display a mount notification:

Insert Mount Notification

The mount point is located in the /media directory by default, and the owner of the mount point is the client user who initiated the mount request.

Mount Information

Xfce Autostart Configuration

In the Xfce desktop environment, you can configure dsbmc to start automatically. Click SettingsSession and Startup, and configure as follows:

Autostart at Boot

Command-Line Client

Start the dsbmc-cli command-line client:

Common parameters include:

Parameter
Description

-e

Eject device

-m

Mount device

-u

Unmount device

You can add the following command to your shell startup configuration file or desktop startup file (such as the ~/.xinitrc file or ~/.xprofile file):

This configuration starts dsbmc-cli in the background and enables automounting. The -a parameter enables automount mode, where the client continuously monitors device events and automatically performs corresponding operations. This method does not provide graphical interface notifications.

Daemon Configuration Details

The default configuration usually meets basic usage needs; if you need more fine-grained control over mounting, you need to modify the daemon's configuration file, located at /usr/local/etc/dsbmd.conf.

usermount Configuration Item Description

The usermount configuration item controls whether devices can be mounted as a regular user:

The configuration file enables the usermount option by default, but for it to take effect, vfs.usermount must also be enabled in the system kernel parameters. Add the following content to the /etc/sysctl.conf file:

  • When usermount is enabled, the mount program executes as a regular user; when usermount is not enabled, the mount program executes as the root privileged user.

  • Regardless of whether usermount is enabled, the owner of the mount point is always the client user who initiated the request.

User Authorization for Automounting

By default, members of the operator and wheel user groups are allowed to connect:

By modifying the allow_users and allow_groups configuration items, you can manage authorized users for the automount feature.

Modifying Mount Point and File Directory Access Permissions (Using NTFS as an Example)

Taking the NTFS file system as an example, you can modify the file access permissions to 640 (rw-r-----) and the directory access permissions to 750 (rwxr-x---).

The NTFS mount configuration includes two command forms: when usermount is enabled, ntfs_mount_cmd_usr is used; otherwise, ntfs_mount_cmd is used. Example:

Here, the file permission mask fmask=137 and directory permission mask dmask=027 are specified in the mount options for ntfs-3g, which control the permissions of files and directories after mounting.

Changed Mount Permissions

File Structure

References

Last updated