devd based AUTOMOUNTER

Crivens

Thanks for input.

I have two things I would like to share/suggest.

One thing that got me was the hard coded user name in the config file. I had to set up a labtop (no spelling mistake, a laptop for lab work) which is used by more than one user. Since each user has his own preferences, there can not be one standard user for that machine. But now this static configuration line does not work. So I replaced that one with this line:
Code:
USER=`ls -l /tmp/Xrootenv|cut -w -f 3`
This is giving me the currently runnig X user. This is most likely not elegant, but it works well for now. Maybe this can be a suggestion for improvements. Also, this only works with X running, but if you are running in console mode, you may also know how to use the rectrangular assortment of rectangular things in front of you to spell the magic invocation needed to mount a file system. ;)

I do not have /tmp/Xrootenv file on my machine, what generates it?

As for checking the user which runs X11, this seems to be able to check who started the X11 server:

Code:
% pgrep X | tail -1
1180

% ps -o ppid -p 1180 | tail -1
1179

% ps -o user -p 1179 | tail -1
vermaden
The second point is that I have tried to use PEFS with removable media. It would be a good add-on if the automounter would, after mounting, check for a hint on the device and then use the correct key file to mount the content with PEFS, in some sensible way.
Any proposition how to find out which key to use for which media?
 
Crivens

Thanks for input.

...

Your method resolves to PID 1 on my system. I am using xdm, running from /etc/ttys. Maybe that one sets up the Xrootenv?
It seems this is not so easy :( Any idea how to do this, without using some daemon or *kit? maybe /usr/bin/last might be a way to find out who is active on :0. That may work.

How to check for the keys might simply be a text file holding the name of the key which may then be located in $USER/.pefs_keys/$contents_of_that_file.key. Would that work?

I think encryption, expecially of removable media, is really important and some easy way to do so is needed. Whenever I can not find one of the pendrives I use I start to worry what may be on that thing and if it may be a problem if that data is showing up where it does not belong. And I guess I am not alone with that.
 
Your method resolves to PID 1 on my system. I am using xdm, running from /etc/ttys. Maybe that one sets up the Xrootenv?
It seems this is not so easy :( Any idea how to do this, without using some daemon or *kit? maybe /usr/bin/last might be a way to find out who is active on :0. That may work.

So now we have detected X11 'owner' for xdm and 'manual start', now we will have to add checks for lxdm, pcdm, kdm, gdm, .... its not the right way I think.

I will introduce other option, GROUP option as an addon to USER option, this way automount can set g+w bit with group on the mount point, so a user that is in that group will be able to write there.

How to check for the keys might simply be a text file holding the name of the key which may then be located in $USER/.pefs_keys/$contents_of_that_file.key. Would that work?

So we can introduce an option for PEFS key files, what about GELI ... or GDBE ... or other forms of encryption? IMHO currently encryption is out of scope for automount, create some simple scripts for yourself with start/stop option for this drive (and possibly others) and job done.

I think encryption, expecially of removable media, is really important and some easy way to do so is needed. Whenever I can not find one of the pendrives I use I start to worry what may be on that thing and if it may be a problem if that data is showing up where it does not belong. And I guess I am not alone with that.
I definitely agree and I use GELI on devices that I whink need encryption, but such a drive is useless on other operating systems, Mac OS X, Windows or even Linux does not support GELI ...
 
It was a quick attempt to adapt the settings, but I know the way to determinate the correct X user is not fool proof. Maybe the last way is better, it would also keep file manager working for the user, would it?

I really think I need to spend time with the start/stop parts of devd myself, so I can get the crypto working.

And thank you all for your time to read and respond.
 
Hi all!
I have two system with FreeBSD 10.1. And a flesh drive with the NTFS.
One of them is:
Code:
$ uname -v
FreeBSD 10.1-STABLE #1 r275939: Sat Dec 20 14:15:25 YEKT 2014  cyrax@mobi.digital-freak.home:/usr/obj/usr/src/sys/MOBI  i386
And installed sysutils/automount 1.5.3 and sysutils/fusefs-ntfs 2015.3.14.
All disks with NTFS works perfect.
Also:
Code:
$ file -k -b -L -s /dev/da0s1 | sed -E 's/label:\ \".*\"//g'
DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS  ", sectors/cluster 8, Media
descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 63, dos < 4.0 BootSector
(0x0); NTFS, sectors/track 63, physical drive 0x80, sectors 15663311, $MFT start cluster
786432, $MFTMirror start cluster 2, bytes/RecordSegment 2^(-1*246), clusters/index block 1,
serial number 02eaa77e7aa77a9cb; contains Microsoft Windows XP/VISTA bootloader
BOOTMGR

Second is:
Code:
$ uname -pv
FreeBSD 10.1-STABLE #1 r281993: Sun Apr 26 14:53:21 YEKT 2015  root@cyrax.digital-freak.home:/usr/obj/usr/src/sys/CYRAX  amd64
sysutils/automount 1.5.3 and sysutils/fusefs-ntfs 2015.3.14 are installed. But disks with NTFS is not mounted.
I tried these:
Code:
# /usr/local/sbin/automount da0s1 attach
printf: .30000000000000000000: expected numeric value
usage: sleep seconds
mount_msdosfs: /dev/da0s1: Invalid argument
And file shows me:
Code:
$ file -k -b -L -s /dev/da0s1 | sed -E 's/label:\ \".*\"//g'
DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS  ", sectors/cluster 8, Media
descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 63, dos < 4.0 BootSector
(0x0), FAT (1Y bit by descriptor); NTFS, sectors/track 63, physical drive 0x80, sectors
15663311, $MFT start cluster 786432, $MFTMirror start cluster 2, bytes/RecordSegment
2^(-1*246), clusters/index block 1, serial number 02eaa77e7aa77a9cb; contains Microsoft
Windows XP/VISTA bootloader BOOTMGR\012- DOS/MBR boot sector DOS/MBR boot
sector dBase IV DBT of  .DBF, block length 63488, next free block index 1318081259, next
free block 1677812736, next used block 1677943810
 
Fixed.

Try now.
Code:
$ /usr/local/sbin/automount --version
automount 1.5.5 2015/06/06
It is correct?

Not work. I paste __fstype() function to another file and added printing values of ${TYPE} variable:
Code:
$ ./test da0s1
FAT

$ gpart show -p da0
=>  63  15667137  da0  MBR  (7.5G)
  63  15663312  da0s1  ntfs  [active]  (7.5G)
  15663375  3825  - free -  (1.9M)

I tried these small changes of __fstype() function:
Code:
--- test.orig   2015-06-06 14:40:46.061868000 +0500
+++ test   2015-06-06 14:41:06.749376000 +0500
@@ -39,14 +39,14 @@
  TYPE=UFS
  return
  fi
-  if echo "${TYPE}" | grep -q 'FAT'
+  if echo "${TYPE}" | grep -q 'NTFS'
  then
-  TYPE=FAT
+  TYPE=NTFS
  return
  fi
-  if echo "${TYPE}" | grep -q 'NTFS'
+  if echo "${TYPE}" | grep -q 'FAT'
  then
-  TYPE=NTFS
+  TYPE=FAT
  return
  fi
  fi
and it is works for me.
Code:
$ ./test da0s1
NTFS
 
I have a memory stick with Xubuntu (ext4). When I try to mount it, it mounts, but USER option is ignored. I searched the thread, but found no similar problems.
Code:
2015-06-28 10:52:46 /dev/da0: random wait for '0.3' seconds before 'attach' action
2015-06-28 10:52:46 /dev/da0: attach
2015-06-28 10:52:46 /dev/da0: filesystem not supported or no filesystem
2015-06-28 10:52:47 /dev/da0s1: random wait for '1.4' seconds before 'attach' action
2015-06-28 10:52:47 /dev/da0s1: attach
2015-06-28 10:52:47 /dev/da0s1: fsck.ext4 /dev/da0s1: clean, 190669/3858432 files, 1181850/15424896 blocks
2015-06-28 10:52:47 /dev/da0s1: mount (ext4)
Code:
root@darkstar:~ # ls -lAF /media
total 4
dr-xr-xr-x  22 root  wheel  4096 27 Jun 23:53 da0s1/
Code:
root@darkstar:~ # chown abishai:wheel /media/da0s1/
chown: /media/da0s1/: Function not implemented
Is it really not implemented or I miss something ?
 
Ext4 is mounted, if I remember correctly, using a fuse driver. It may be possible that "chown" is not part of that implementation.
 
Having seen that automount works well for external drives, how can I get it to work on my *internal* ones as well?
Can I use automount for that at all, or do I have to stick to /etc/fstab?
Can I just do something like this in /usr/local/etc/devd/automount_devd.conf:
Code:
notify 100 {
  match "system" "DEVFS";
  match "type" "CREATE";   
  match "cdev" "(ada|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev attach";
};

notify 100 {
  match "system" "DEVFS";
  match "type" "DESTROY";
  match "cdev" "(ada|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev detach";
};
Where "ada" is my internal drive?

I do not use labels, where are labels located?
Suppose you have a msdosfs formatted partition. Also suppose that when you formatted that partition you gave it the name "MYDRIVE".
If that partition exists on an internal drive or if you connect an external drive that contains that partition, a directory named "msdosfs" appears in the /dev/ directory. If you take a look inside that /dev/msdosfs/ directory you should get the following output:
Code:
[CMD]$ ls /dev/msdosfs[/CMD]
MYDRIVE

The same thing goes for drives that are formatted with NTFS.
When I take a look inside the /dev/ntfs folder on my own computer (as you can see, I have labeled 3 NTFS partitions), I get the following output:
Code:
[CMD]ls /dev/ntfs/[/CMD]
Acer       Data      RECOVERY

All of those 3 partitions are on 2 internal disks. To me, using labels makes it easier to mount partitions when needed, as I don't have to remember which device node I have to type when I want to mount a partition. A couple of examples:
Instead of having to type mount_ntfs-3g /dev/ada1p4 /mnt, I can type mount_ntfs-3g /dev/ntfs/Data /mnt. Instead of writing mount_ntfs-3g /dev/ada0p4 /mnt I can write mount_ntfs-3g /dev/ntfs/Acer /mnt.
 
Having seen that automount works well for external drives, how can I get it to work on my *internal* ones as well?
Can I use automount for that at all, or do I have to stick to /etc/fstab?
Can I just do something like this in /usr/local/etc/devd/automount_devd.conf:
Code:
notify 100 {
  match "system" "DEVFS";
  match "type" "CREATE"; 
  match "cdev" "(ada|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev attach";
};

notify 100 {
  match "system" "DEVFS";
  match "type" "DESTROY";
  match "cdev" "(ada|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev detach";
};
Where "ada" is my internal drive?

Just add 'ada' to the existing 'da|mmcsd' set so it will become 'da|mmcsd|ada' set:

Code:
notify 100 {
  match "system" "DEVFS";
  match "type" "CREATE"; 
  match "cdev" "(da|mmcsd|ada)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev attach";
};

notify 100 {
  match "system" "DEVFS";
  match "type" "DESTROY";
  match "cdev" "(da|mmcsd|ada)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev detach";
};

Suppose you have a msdosfs formatted partition. Also suppose that when you formatted that partition you gave it the name "MYDRIVE".
If that partition exists on an internal drive or if you connect an external drive that contains that partition, a directory named "msdosfs" appears in the /dev/ directory. If you take a look inside that /dev/msdosfs/ directory you should get the following output:
Code:
[CMD]$ ls /dev/msdosfs[/CMD]
MYDRIVE

The same thing goes for drives that are formatted with NTFS.
When I take a look inside the /dev/ntfs folder on my own computer (as you can see, I have labeled 3 NTFS partitions), I get the following output:
Code:
[CMD]ls /dev/ntfs/[/CMD]
Acer       Data      RECOVERY

All of those 3 partitions are on 2 internal disks. To me, using labels makes it easier to mount partitions when needed, as I don't have to remember which device node I have to type when I want to mount a partition. A couple of examples:
Instead of having to type mount_ntfs-3g /dev/ada1p4 /mnt, I can type mount_ntfs-3g /dev/ntfs/Data /mnt. Instead of writing mount_ntfs-3g /dev/ada0p4 /mnt I can write mount_ntfs-3g /dev/ntfs/Acer /mnt.

I agree that mounting based on labels would be far better... but not all filesystems have labels... the automount will have to check for labels and then to check which labels are on which drives/partitions and then mount some existing labels and non existing drives/partition after the labelled ones have been mounted... or first mount new label and then mount all other newly detected drives/partitions hoping that they would fail to mount one over another because its already mounted ;)

I have other idea in my mind... to create symlink with label in /media, so if something was mounted as /media/da0s1 and it has label 'DATA' then a symlink would be created as /media/DATA -> /media/da0s1... but I will have to add tracking of adding and removing links... and take care of overlapping labels, first time it would be 'DATA' the second one would probably be 'DATA72345' ('DATA${RANDOM}')... will have to think about it ;)

...also if there is no label then serial number + partition can be used ;)
 
I tried the automount script on my NTFS partitions. It turned out I had to make a couple of changes for the script to work:
I had to change the line
Code:
if echo "${TYPE} | grep -q 'FAT'"
to
Code:
if echo "${TYPE} | grep -q 'FAT (32 bit)'"
This was because my NTFS partitions seemed to be identified as FAT partitions. At least, messages from dmesg -a kept on saying that fsck_msdosfs could not check that partition for errors. Changing "FAT" to "FAT (32 bit)" in the if statment above seemed to fix that problem.
I think that what caused my NTFS partition to be identified as an FAT partition was the following (correct me if I am wrong): "FAT (1Y bit by descriptor)"
The following "code" is the output of dmesg -a when the automount script mounts one of my NTFS partitions:
Code:
DOS/MBR boot sector, code offset 0x52+2, OEM-ID "NTFS  ", sectors/cluster 8, Media descriptor 0xf8, sectors/track 63, heads 255, hidden sectors 1807747072, dos < 4.0 BootSector (0x80), FAT (1Y bit by descriptor); NTFS, sectors/track 63, sectors 2099281919, $MFT start cluster 786432, $MFTMirror start cluster 2, bytes/RecordSegment 2^(-1*246), clusters/index block 1, serial number 03e34075634071117
That "broke" the possibility of automounting my USB drive which was an msdosfs formatted drive.
To work around that, I added yet another change:
Code:
if echo "${TYPE}" | grep -q 'MSDOS'
  then
  TYPE=FAT
  return
  fi
So therefore I propose the following code:
Code:
  if echo "${TYPE}" | grep -q 'MSDOS'
  then
  TYPE=FAT
  return
  fi
  if echo "${TYPE}" | grep -q 'FAT (32 bit)'
  then
   TYPE=FAT
   return
  fi
  if echo "${TYPE}" | grep -q 'NTFS'
  then
  TYPE=NTFS
  return
  fi
Also beware that when using NTFS-3G, mount might fail because NTFS-3G thinks that the NTFS partitions is in an unsafe state.
As a tips, if you don't want/need RW access to those partitions, you can add "-o ro" to the command that mounts the NTFS volume:
Code:
if which ntfs-3g 1> /dev/null 2> /dev/null # sysutils/fusefs-ntfs
then
  __wait_for_device ${DEV}
  if ntfs-3g -o recover -o remove_hiberfile -o ro ${OPTS} ${DEV} ${MNT}
  then
    ADD=1
  else
    # make nested mount try because sometimes second mount works
    if ntfs-3g -o recover -o remove_hiberfile -o ro ${OPTS} ${DEV} ${MNT}
    then
      ADD=1
    else
      __log "${DEV}: mount failed (ntfs) 'ntfs-3g ${OPTS} ${DEV} ${MNT}'"
    exit 1
  fi
fi
 
(...)

So therefore I propose the following code:
Code:
  if echo "${TYPE}" | grep -q 'MSDOS'
  then
  TYPE=FAT
  return
  fi
  if echo "${TYPE}" | grep -q 'FAT (32 bit)'
  then
   TYPE=FAT
   return
  fi
  if echo "${TYPE}" | grep -q 'NTFS'
  then
  TYPE=NTFS
  return
  fi

Close ...

You are referring to 1.5.3 which is in Ports, 1.5.4 from GITHUB already has that switched, but I merged Your ideas anyway just in case so latest 1.5.5 looks like that:

Code:
  if echo "${TYPE}" | grep -q 'NTFS'
  then
    TYPE=NTFS
    return
  fi
  if echo "${TYPE}" | grep -q 'MSDOS'
  then
    TYPE=FAT
    return
  fi
  if echo "${TYPE}" | grep -q 'FAT (32 bit)'
  then
    TYPE=FAT
    return
  fi
  if echo "${TYPE}" | grep -q 'FAT'
  then
    TYPE=FAT
    return
  fi
 
Hi!

I am using automount with partial success. Mounting usb and firewire external drive with ufs and fat partitions works great but automount for CD/DVD doesn't work and I don't have any error message.
Code:
automount.conf
USERUMOUNT=YES
ATIME=NO
REMOVEDIRS=YES
# FM="nautilus --browser --no-desktop"
USER=fernandel
ENCODING=en_US.UTF-8
CODEPAGE=cp437

And automount_devd.conf:
Code:
notify 100 {
  match "system" "DEVFS";
  match "type" "CREATE";
  match "cdev" "(da|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev attach";
};

notify 100 {
  match "system" "DEVFS";
  match "type" "DESTROY";
  match "cdev" "(da|mmcsd)[0-9]+.*";
  action "/usr/local/sbin/automount $cdev detach";
};

Code:
pkg info |grep fuse
fusefs-exfat-1.0.1  Full-featured exFAT FS implementation as a FUSE module
fusefs-ext4fuse-0.1.3,1  EXT4 implementation for FUSE
fusefs-libs-2.9.5  FUSE allows filesystem implementation in userspace
fusefs-ntfs-2016.2.22_1  Mount NTFS partitions (read/write) and disk images

Thank you.
 
Back
Top