# USB flash drive woes



## Eponasoft (Jan 20, 2010)

This has been bugging me for awhile now so I figured I would try to fix it since I'm installing FreeBSD on another system right now, and the user is gonna need it.

The issue is automounting flash drives in a normal account. My user account is in both wheel and operator. I'm using FreeBSD 7.2 and KDE 3.5. When I insert the flash drive, KDE pops up a dialog asking what to do with the inserted volume, but then I get an error message from mount_msdosfs saying that the operation is not permitted. In order to fix it, I've read that the mount point should be chown'd to the user account. Well, the system won't let me do that.

Anyways, if anyone can help out in this case, just tell me what I need to post that will shed some light on this issue...conf files, directory settings, etc...I just want to get it working. Thanks.


----------



## J65nko (Jan 20, 2010)

Simplest way is to create a mount point/directory in your home directory. For FreeBSD specifically see http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/usb-disks.html

For an OpenBSD and NetBSD perspective:mounting an USB device as normal non-root user in OpenBSD


----------



## DutchDaemon (Jan 20, 2010)

Isn't this the [cmd=]sysctl vfs.usermount=1[/cmd] stuff? My Kingston sticks automount under /media, which is root:wheel-owned. (/media/KINGSTON is created there, to be precise, and that one has my user:user permissions). I can use them fine as 'normal user', including mounting and unmounting, reading and writing.


----------



## Eponasoft (Jan 21, 2010)

Pretty much all of this was already done on my system, though I hadn't gotten this far with the system I'm working on right now. The thing is that I want things to automount; I don't want to have to mount it manually, as the user of this system is not going to be able to do that (she's not exactly computer-savvy). If I start up X with KDE3.5 as the superuser, everything works as I want it to work. Now...I have created subdirectories inside of /mnt and chown'd them correctly. I'm currently waiting for OOo to finish building (holy hell this takes forever!), but after rebooting, how can I get the system to automount to /mnt/username? The above links didn't shed any light on that, unfortunately...I've read a little about sysutils/automount...is this an option, and if so, how? Thanks.


----------



## DutchDaemon (Jan 21, 2010)

For the record: my Kingston sticks do automount (an icon pops up on my XCFE desktop, and I can right-click it to unmount). I don't think I've done much more than setting that sysctl and adding some rules to PolicyKit.conf.


----------



## Eponasoft (Jan 21, 2010)

After OOo finally finished building, I rebooted and checked to see if the flash drive would automount...not only did it not automount but I didnÂ´t even get the dialog. Also, the CDROM almost worked, it could not mount but at least it was detected. What kind of changes did you make to policykit.conf to get everything to work? I have the CDROM working on my own system, but I do not remember how I got it working.


----------



## kpedersen (Jan 21, 2010)

Hmm what I usually do for Xfce / gnome / kde is...

in rc.conf

```
hald_enable="YES"
dbus_enable="YES"
```

in Policykit.conf

```
<match user="root"> <----- remove
  <return result="yes"/>
</match> <------ remove
```

in /etc/fstab

```
proc           /proc       procfs  rw  0   0
```

Yes... HAL uses procfs 

Then after a reboot. Everything seems to automount no problem

Basically, it doesnt seem that the user needs to mount anything... It is all handled by HAL. therefor, the usermount stuff is not important.


----------



## SirDice (Jan 21, 2010)

kpedersen said:
			
		

> in Policykit.conf
> 
> ```
> <match user="root"> <----- remove
> ...


This will basically allow all users everything. If that's not what you want this might be a better solution:


```
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->

<!DOCTYPE pkconfig PUBLIC "-//freedesktop//DTD PolicyKit Configuration 1.0//EN"
"http://hal.freedesktop.org/releases/PolicyKit/1.0/config.dtd">

<!-- See the manual page PolicyKit.conf(5) for file format -->

<config version="0.1">
    <match user="root">
        <return result="yes"/>
    </match>
    <define_admin_auth group="wheel"/>
    <match action="org.freedesktop.hal.storage.mount-removable">
        <match user="dice">
                <return result="yes"/>
        </match>
    </match>
    <match action="org.freedesktop.hal.storage.mount-fixed">
        <match user="dice">
                <return result="yes"/>
        </match>
    </match>
    <match action="org.freedesktop.hal.storage.eject">
        <match user="dice">
                <return result="yes"/>
        </match>
    </match>
</config>
```

Change the "match user" accordingly.


----------



## DutchDaemon (Jan 21, 2010)

Mine is:


```
<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->

<!DOCTYPE pkconfig PUBLIC "-//freedesktop//DTD PolicyKit Configuration 1.0//EN"
"http://hal.freedesktop.org/releases/PolicyKit/1.0/config.dtd">

<!-- See the manual page PolicyKit.conf(5) for file format -->

<config version="0.1">
    <match user="dutchd|root">
	<return result="yes"/>
    </match>

    <define_admin_auth group="wheel|operator"/>

<match action="org.freedesktop.hal.power-management.shutdown">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.power-management.reboot">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.power-management.suspend">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.power-management.hibernate">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.storage.eject">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.storage.mount-fixed">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.storage.mount-removable">
    <return result="yes"/>
</match>

<match action="org.freedesktop.hal.storage.unmount-others">
    <return result="yes"/>
</match>

</config>
```


----------



## Eponasoft (Jan 21, 2010)

OK thanks a lot everyone...IÂ´ll give this a go and see if it works.


----------



## kpedersen (Jan 21, 2010)

Since we are talking about HAL,
Does anyone know the future of it within FreeBSD?
Isn't it meant to become depricated?
How did automount use to work before we got HAL?


----------



## Eponasoft (Jan 21, 2010)

OK this all worked for the USB drive. I can now insert it, find it in Â¨Storage MediaÂ¨, write files to it, and safely remove it. That helped a ton.  KDE doesnÂ´t pop up a dialog for it though, but that is not really a huge issue. However, I am still having problems with the CDROM...it is detected, and shows up in Â¨Storage MediaÂ¨, but I cannot mount it as a normal user...


----------



## DutchDaemon (Jan 21, 2010)

See if you can glean something from the docs in /usr/local/share/PolicyKit/policy/.

For the record: when I insert a CD into my internal CD/DVD reader/writer on my laptop, I do get a pop-up in XFCE:


```
Failed to mount "User Manual".
mount_cd9660: /dev/acd0: Operation not supported by device.
```

The icon does show up on the desktop though.

Syslog is *stumm* about it.


----------



## Eponasoft (Jan 21, 2010)

OK...IÂ´m assuming that this is the correct file...

/usr/local/share/PolicyKit/policy/org.freedesktop.hal.storage.policy


```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policyconfig PUBLIC
 "-//freedesktop//DTD PolicyKit Policy Configuration 1.0//EN"
 "http://www.freedesktop.org/standards/PolicyKit/1.0/policyconfig.dtd">

<!-- 
Policy definitions for HAL's drives/media mechanims.

Copyright (c) 2007 David Zeuthen <david@fubar.dk>

HAL is licensed to you under your choice of the the Academic Free
License Version 2.1, or the GNU General Public License version 2. Some
individual source files may be under the GPL only. See COPYING for
details.
-->

<policyconfig>

  <action id="org.freedesktop.hal.storage.mount-fixed">
    <description>Mount file systems from internal drives.</description>
    <message>System policy prevents mounting internal media</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep_always</allow_active>
    </defaults>
  </action>
  
  <action id="org.freedesktop.hal.storage.mount-removable">
    <description>Mount file systems from removable drives.</description>
    <message>System policy prevents mounting removable media</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>
  
  <action id="org.freedesktop.hal.storage.unmount-others">
    <description>Unmount file systems mounted by other users.</description>
    <message>System policy prevents unmounting media mounted by other users</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep_always</allow_active>
    </defaults>
  </action>
  
  <action id="org.freedesktop.hal.storage.eject">
    <description>Eject removable media.</description>
    <message>System policy prevents ejecting removable media</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>
  
  <action id="org.freedesktop.hal.storage.crypto-setup-fixed">
    <description>Set up decryption for encrypted fixed storage devices.</description>
    <message>System policy prevents accessing encrypted fixed media</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>auth_admin_keep_always</allow_active>
    </defaults>
  </action>

  <action id="org.freedesktop.hal.storage.crypto-setup-removable">
    <description>Set up decryption for encrypted removable storage devices.</description>
    <message>System policy prevents accessing encrypted removable media</message>
    <defaults>
      <allow_inactive>no</allow_inactive>
      <allow_active>yes</allow_active>
    </defaults>
  </action>

</policyconfig>
```


----------



## mfaridi (Jan 21, 2010)

DutchDaemon said:
			
		

> Mine is:
> 
> 
> ```
> ...



what I must do when I have three user for example bob,john,robert and I want all of them can mount USB and umount it


----------



## DutchDaemon (Jan 21, 2010)

[cmd=]man 5 PolicyKit.conf[/cmd] - user/match/EXAMPLES.


----------



## mfaridi (Jan 21, 2010)

DutchDaemon said:
			
		

> PolicyKit.conf(5) - user/match.



so I must do this

```
<config version="0.1">
    <match user="bob|robert|john|root">
        <return result="yes"/>
```


----------



## kpedersen (Jan 21, 2010)

to get the cdrom auto mounting...

make sure the cdrom entry has been removed from /etc/fstab

and then HAL should be able to mount it when a new cd is inserted

I assume this is because if it is mounting something and it is found in HAL, it tried to mount it as the current user.. Which will generally fail.

http://www.freebsd.org/gnome/docs/halfaq.html


> NOTE: Volumes that you wish to manage using hal should NOT be listed in /etc/fstab. This is especially true for CD devices and floppy disk devices.



The HAL faq on this site is really useful for Xfce even though it is orientated to gnome.


----------



## DutchDaemon (Jan 21, 2010)

> make sure the cdrom entry has been removed from /etc/fstab



Well spotted. I _always_ forget about the interplay between HAL and fstab!


```
Jan 21 18:09:00 box hald: mounted /dev/acd0 on behalf of uid 1001
Jan 21 18:09:09 box hald: unmounted /dev/acd0 from '/media/User Manual' on behalf of uid 1001
```

All desktop functions (notification, ejecting, icon) working just dandy. Thanks for the reminder.


----------



## Eponasoft (Jan 21, 2010)

OK, /etc/fstab had it set like that when fbsd was installed. IÂ´ve removed it, and will test it out after rebooting (building GIMP at the moment, another fun time indeed). Thanks for the hint...I bet itÂ´ll work now.


----------



## DutchDaemon (Jan 21, 2010)

Reboot isn't necessary!


----------



## Eponasoft (Jan 21, 2010)

Yep, that seems to be the case, as when I popped in a CD, it automatically mounted it as the normal user and I could view its contents. No reboot required.


----------



## DutchDaemon (Jan 22, 2010)

Well, then we're done here


----------



## Beno Kurniawan (Jan 29, 2018)

Dear Sir,
I have looking how to mount usb as user on KDE, and by reading this thread I finally succeed. I wonder if you could share how to mount ntfs format external hardisk? It cannot be mounted even though I have install fusefs-ntfs and enable fuse. Tried to do what written on handbook about vfs.usermount=1 and autofs, this takes me unable to mount usb which previously works. So I undo all the steps back to the state where I can mount the usb sticks.
Thanks in advance for your kind help.
Regards,
Beno


----------

