# devfs restart Causes Warning, Mounting USBs is Awful Experience



## BawdyAnarchist (Sep 6, 2020)

I'm following the 17.4 Handbook guide for USBs.  I understand about /etc/devfs.rules and /etc/rc.conf requirements.  I add `devfsrules_localrules=5]` , and then in rc.conf `devfs_system_ruleset="localrules"`.  I do ALL of the other stuff as well.  `vfs.usermount=1`.  Double, triple, quadruple check. Reboot...

But when I apply `service devfs restart` I get the following:


```
/etc/rc.d/devfs: WARNING: devfs_set_ruleset: you must specify a ruleset number
/etc/rc.d/devfs: WARNING: devfs_apply_ruleset: you must specify a ruleset
```

So I tried just setting rc.conf to one of the predefined rulesets "jail", for example.  Same deal.  So I looked in /etc/defaults/rc.conf, and saw an option for `devfs_set_rulesets=""`, so I tried adding `devfs_set_rulesets=""` to a few different values, each time restarting devfs.  Values: "localrules" "5" "/etc/devfs.rules" "/etc/fstab" and each time it did nothing, except for sometimes throw additional errors.  I tried enabling debugging.  Nothing useful, it loads all the rules, and then the exact same 2 warnings at the bottom.  

While the rest of my FreeBSD experience has been quite good, mounting and automounting USBs has been awful, and consistently awful (I've reinstalled a few times).  The documentation seems to be incomplete, and apparently just wrong.  Finding out a straightforward way to mount ext4 USBs is like pulling teeth.  Yeah I get it now, `pkg install fusefs-lkl` `fuse_load="YES"`, because the inbuilt function in the kernel doesn't work well.  There's like 5 different things going on that I can't really make sense of ... autofs automount automountd autoumount lklfuse.  COULD SOMEONE POSSIBLY UPDATE THE HANDBOOK??

I'm sorry if I sound angry or frustrated.  But while the other snags I've hit were user error or just having to learn the system's intricacies, I'm pretty sure the warnings being thrown here aren't due to lack of following the handbook or reasonable attempted troubleshooting.  I've read perhaps a dozen different manpages on this stuff with very little progress.  YES, I have been reading/searching through forum posts.  NO, very little has been useful expect this one: https://forums.freebsd.org/threads/...g-with-zfs-root-freebsd-12.70401/#post-424036


----------



## kpedersen (Sep 6, 2020)

I tend to not bother with the usermount stuff. I even think OpenBSD had the right idea removing it :/

Have you considered just using sudo? With a small bit of config in your sudoers file you could even set it up so that a password is never asked for mount related commands.

I wrote an awk script (that re-runs itself with sudo if it detects that it is not being run as root) that lists all available devices and partitions, and if called with an argument will mount it under /mnt/<device><partition>. A bit of a pain to write initially but you only need to do it once!

Also, try to mount using the native tools first (i.e a msdosfs partition) and get that working before you move onto fuse. Since fuse is largely userland it introduces a few quirks (possibly to the usermount stuff you are experiencing)


----------



## BawdyAnarchist (Sep 6, 2020)

I'm doing this in a bhyve VM, with pci passthrough for the USB bus.  This protects the host OS, and helps to isolate the hardware controllers in the case of potentially malicious mass storage devices.

I will be ssh'ing into the VM from jails where I want the desired files to go.

Thanks for your suggestions, maybe I will use them as a workaround if absolutely necessary.  But in reality, there are still 2 fundamental problems: 

1.  Whether from host or from bhyve VM, setting `devfs_system_ruleset="<rulename>"` seems broken, after running `service devfs restart`

and

2.  The Handbook on USB mass storage devices is overly complicated, incomplete, and wrong


----------



## roper (Sep 7, 2020)

Using sysutils/fusefs-ntfs from packages
I have in /etc/rc.conf

```
devfs_system_ruleset="localrules"
```

in /etc/sysctl.conf

```
vfs.usermount=1
```
in /etc/devfs.conf

```
[localrules=1]
add path 'da/*' mode 0660 group operator
```
and in /boot/loader.conf

```
fuse_load="YES"
```
and haven't experienced any issues, but I don't automount anything. I issue `mount` and `umount` commands as needed.


----------



## BawdyAnarchist (Sep 7, 2020)

roper said:


> Using sysutils/fusefs-ntfs from packages
> I have in /etc/rc.conf
> 
> ```
> ...



ok... have you tried `service devfs restart` ?  I too have fuse_load in loader.conf
did you miss the part where I talk about automounting?


----------



## roper (Sep 7, 2020)

You're attempting to restart the service as a user but you'll need root for that.


----------



## BawdyAnarchist (Sep 7, 2020)

roper said:


> You're attempting to restart the service as a user but you'll need root for that.



No, I definitely am root


----------



## roper (Sep 7, 2020)

Here a service restart was successful but I received the error messages you cited on an attempt to restart the service as a user. Have you changed any file permissions on /etc/devfs.conf or /etc/rc.d/devfs?


----------



## BawdyAnarchist (Sep 7, 2020)

Nope.  It's a brand new virtual machine.  But I get the same error as root on the host as well ... luckily I don't need to change host devfs system rules


----------



## mark_j (Sep 7, 2020)

BawdyAnarchist said:


> I'm following the 17.4 Handbook guide for USBs.  I understand about /etc/devfs.rules and /etc/rc.conf requirements.  I add `[devfsrules_localrules=5]` , and then in rc.conf `devfs_system_ruleset="localrules"`.  I do ALL of the other stuff as well.  vfs.usermount=1.  Double, triple, quadruple check. Reboot...
> 
> But when I apply `service devfs restart` I get the following:
> 
> ...


Is your user a member of the operator group? If not, it must be.
Could you list all the da* devices, please?
Did you type this correctly: *[devfsrules_localrules=5]* ??
The two should match, so enabling "*localrules*" in /etc/rc.conf is not matching your rule name *devfsrules_localrules*.

And as kpedersen pointed out, rightly I think, I'd steer away from user mounted stuff.


----------



## BawdyAnarchist (Sep 7, 2020)

Ok that was it.  As you said, "devfsrules_localrules."  Somehow I had it in my head that the full name _was_ "localrules," even with the prepending "devfsrules_" in the devfs.rules file. Basically, it needs to be the same in both rc.conf and devfs.rules ...

*[localrules=5] *with rc.conf entry *devfs_system_ruleset="localrules" * ...or...
*[devfsrules_localrules=5] *with rc.conf entry *devfs_system_ruleset="devfsrules_localrules"*

Thank you for your help.


----------



## BawdyAnarchist (Sep 7, 2020)

I am going to make user enabled usb though.  As I've said before, this is a bhyve VM with pci passthrough for the USB.  Not network connected, except for the tap going to my selected jail for the ssh operation (all on one host).

I intend to ssh into the machine for copying files to jails on the host.  So either I have to enable usermount usb, enable ssh root logins, or set up sudo/doas so I can mount after login from ssh.  The simpler solution is to allow usermount


----------



## mark_j (Sep 7, 2020)

BawdyAnarchist said:


> Ok that was it.  As you said, "devfsrules_localrules."  Somehow I had it in my head that the full name _was_ "localrules," even with the prepending "devfsrules_" in the devfs.rules file. Basically, it needs to be the same in both rc.conf and devfs.rules ...
> 
> *[localrules=5] *with rc.conf entry *devfs_system_ruleset="localrules" * ...or...
> *[devfsrules_localrules=5] *with rc.conf entry *devfs_system_ruleset="devfsrules_localrules"*
> ...


No problems. Sometimes it just takes someone else to look over your work to find the bleeding obvious.
I know, I've been there before.


----------



## ekvz (Sep 7, 2020)

Not entirely related but i wonder if https://github.com/IgnorantGuru/udevil could be ported to FreeBSD. In my opinion it's pretty much priceless when it comes to mounting devices as an user. When i get the time i might even do it myself. Considering it's possible/practical at all of course.


----------



## GhettoBSD (Oct 30, 2020)

I just ran across this myself: I found I didn't have the file /etc/devfs.rules


```
/etc/rc.d/devfs: WARNING: devfs_set_ruleset: you must specify a ruleset number
/etc/rc.d/devfs: WARNING: devfs_apply_ruleset: you must specify a ruleset
```

I created the file /etc/devfs.rules and added what I needed for virtualbox:


```
[system=10]
add path 'usb/*' mode 0660 group operator
```

Then I ran

```
GhettoNAS [~] > service devfs restart
```

And that worked for me.


----------

