Auto mount and unmount USB drive

Colleagues, I want to use a very small computer as a music player.
Is it possible to configure the system so that when disconnecting a USB flash drive, there is no need to separately issue a command to unmount it?
Since this is a player, the flash drive can be mounted in read-only mode. Like a CD.

How to do this correctly and gracefully?

Ogogon.
 
Colleagues, I want to use a very small computer as a music player.
Is it possible to configure the system so that when disconnecting a USB flash drive, there is no need to separately issue a command to unmount it?
Since this is a player, the flash drive can be mounted in read-only mode. Like a CD.

How to do this correctly and gracefully?

Ogogon.
whaT i did was to edit /etc/auto_master.conf to
/net -hosts -nobrowse,nosuid,intr
/media -media -nosuid,noatime,autoro
#/- -noauto

and added
#notify 100 {
# match "system" "GEOM";
# match "subsystem" "DEV";
# action "/usr/sbin/automount -c";
};

to /etc/devd.conf

it works for me.
 
This section of the handbook should be helpful. I've started using the handy built in configs of the latest Plasma to allow it to configure the user mount settings.

https://docs.freebsd.org/en/books/handbook/disks/#usb-disks
As I understand it, your answer falls into the "read the documentation!" genre.
Unfortunately, you did not answer my question specifically, but suggested looking for an answer in the thematic section of the documentation. Unfortunately, there is not much benefit from such advice, since I knew about the existence of the documentation before receiving it.
But I didn't find the answer there. It's either not there, or it's hiding there very cleverly.
Perhaps the information is there, but I did not find it. And therefore I ask you - tell me in which section of this chapter it is said about the possibility of deleting read-only file devices without calling the utility for their unmounting.
I remember that in the nineties, either on ISС, or on SCO, or on SunOS there was such a mount mode for read only devices. It was not considered canonical to disconnect it without dismountling, but it was known that it did not cause any negative consequences in the system's work, except for some swearing in syslog.
 
Do I understand the current situation correctly?

1. I need to train the devd so that connected flash drives are mounted as read-only.
2. Next, I calmly read their contents.
3. Having finished reading, I calmly and without a twinge of conscience take out the flash drive.
4. The devd is triggered belatedly and shouts "Force dismount!" about her.
5. My application should handle the error "All files and device have disappeared somewhere!" in non hysterical manner as routine case.
 
I am sorry for not adding the specific area of concern that is addressed in the handbook. It will be section 20.4.2. This section describes how devices and be automatically mounted and removed.

Code:
20.4.2. Automounting Removable Media

USB devices can be automatically mounted by uncommenting this line in /etc/auto_master:

/media        -media        -nosuid

Then add these lines to /etc/devd.conf:

notify 100 {
    match "system" "GEOM";
    match "subsystem" "DEV";
    action "/usr/sbin/automount -c";
};

Reload the configuration if autofs(5) and devd(8) are already running:

# service automount restart
# service devd restart

autofs(5) can be set to start at boot by adding this line to /etc/rc.conf:

autofs_enable="YES"

autofs(5) requires devd(8) to be enabled, as it is by default.

Start the services immediately with:

# service automount start
# service automountd start
# service autounmountd start
# service devd start

Each file system that can be automatically mounted appears as a directory in /media/. The directory is named after the file system label. If the label is missing, the directory is named after the device node.

The file system is transparently mounted on the first access, and unmounted after a period of inactivity. Automounted drives can also be unmounted manually:

# automount -fu

This mechanism is typically used for memory cards and USB memory sticks. It can be used with any block device, including optical drives or iSCSILUNs.
 
Back
Top