FAQ SearchLogin
Tuxera Home
View unanswered posts | View active topics It is currently Mon Apr 12, 2021 21:37



Post new topic Reply to topic  [ 3 posts ] 
automount USB with usermapping located on windows C drive 
Author Message

Joined: Sat Jul 02, 2016 18:15
Posts: 2
Post automount USB with usermapping located on windows C drive
Hi, I have some USB disks with NTFS partitions.
And I have on my computer an internal harddisk with a user mapping.
Reading the documentation I get the understanding that on each disk a usermapping file should exist.
Or the usermapping is defined
in the /etc/fstab with the usermapping option, e.g.

###### this is the master with usermapping
UUID=1111111111111111 /windows/C ntfs-3g users,gid=users,fmask=133,dmask=022,locale=de_DE.UTF-8 0 0
#####
UUID=9999999999999999 /windows/pt0 ntfs-3g usermapping=/windows/C/.NTFS-3G/UserMapping,locale=de_DE.UTF-8,nofail,x-systemd.requires=/windows/C 0 0
UUID=8888888888888888 /mnt/pt1 ntfs-3g usermapping=/windows/C/.NTFS-3G/UserMapping,locale=de_DE.UTF-8,nofail,x-systemd.requires=/windows/C 0 0

I would like to use an automount. Instead experiences with udev suggest that this does not work. Stated in this forum too:"Auto mounting NTFS partition with working permissions".

Now the question: Is there a solution nevertheless?
Maybe: check if a usermap file exist on the new disk, if required (e.g. file is different from the central place) copy from central place to the disk and remount it.
Do an automount not based on udev but on something else. Which is a candidate, maybe autofs?
Thank you in advance for reading and any suggestions or/and examples.
Regards


Sat Jul 02, 2016 19:14
Profile
NTFS-3G Lead Developer

Joined: Tue Sep 04, 2007 17:22
Posts: 1286
Post Re: automount USB with usermapping located on windows C drive
Hi,

Code:
UUID=8888888888888888 /mnt/pt1 ntfs-3g usermapping=/windows/C/.NTFS-3G/UserMapping,...

Getting the usermapping file at boot time from another partition tends to fail because systemd starts the mountings in parallel and the device is not available early enough. I assume this is why you have set the option "x-systemd.requires=/windows/C", which I have not tested myself. To determine whether the file can be read, use a file with no contents and check the syslog for an error. There could be permissions or SELinux problems.
Quote:
Now the question: Is there a solution nevertheless?
Maybe: check if a usermap file exist on the new disk, if required (e.g. file is different from the central place) copy from central place to the disk and remount it.

Having the usermapping file on the device being mounted works for sure for drives automounted on pluging them, at least when the usermapping file is at the standard location .NTFS-3G/UserMapping. This obviously has to be managed on the first use.
Quote:
Do an automount not based on udev but on something else. Which is a candidate, maybe autofs?

I have not examined any alternative.

Regards

Jean-Pierre


Sat Jul 02, 2016 22:12
Profile

Joined: Sat Jul 02, 2016 18:15
Posts: 2
Post Re: automount USB with usermapping located on windows C drive
Hi Jean-Pierre,
thanks for the response.
[quote I assume this is why you have set the option "x-systemd.requires=/windows/C",][/quote]
True - this is the intension.

Quote:
Having the usermapping file on the device being mounted works for sure for drives automounted on pluging them, at least when the usermapping file is at the standard location .NTFS-3G/UserMapping. This obviously has to be managed on the first use.

I worked this week to get it run with udev and udisks and 2 scripts on my laptop with openSUSE leap 42.1 4.1.26-21-default.
It looks like working :lol:
The udev ruiles file is
Code:
cat 86-ntfs-mount-lagrange.rules
#  based on https://www.axllent.org/docs/view/auto-mounting-usb-storage/
#
#  mount ntfs with usermap
#
#  2016-07-06
#
#            ignore windows C  Mounted via fstab and the other four primary partitions
KERNEL=="sda[1-5]", GOTO="media_by_label_auto_mount_end" 
#            ignore anything but ntfs
ENV{ID_FS_TYPE}!="ntfs", GOTO="media_by_label_auto_mount_end"
#
# Call ntfs-3g-check-um     to check the file usermapping,
# i.e. if not existing or different to the file located  at windows C copy from windows C.
ACTION=="add", RUN+="/usr/local/sbin/ntfs-3g-check-um %k"
#
# Mount the device 
#      e.g. udisksctl mount  --block-device /dev/sda9
ACTION=="add", RUN+="/usr/bin/udisksctl mount  --block-device /dev/%k", RUN+="/usr/bin/touch /tmp/ntfs-mount-usermap--udisksctl-mount---dev-%k"
#
# Exit 
LABEL="media_by_label_auto_mount_end"



Code:
cat lcmin1
#!/usr/bin/sh
#
#   script to see every 5 second if  text file is available - more than 1 line.
#   timeout to be checked by calling routine, e.g. with gnu timeout.
e
#  parameter 1: name of textfile
#  version 2016-07-08
x=1
while [ $x ==  1 ]
do
  # get number of lines
  number=`wc -l $1|cut -f1 -d' '`
  if [ $number -gt 1 ]         
    then
      x=0
    else
      sleep 5
      #/usr/bin/touch  "/tmp/lcmin1--`date`"
    fi
done


and the large script

Code:
cat ntfs-3g-check-um
#!/usr/bin/sh
#   wait to  read  ntfs-3g usermap file
# from windows C and partition of device $1
# if neccesary copy it
#
# call with 1 parameters:
#  1.)  device  e.g. sdb1
#
# version 1.0
# date 2016-07-08

# directory of master wih usermap, e.g. the windows prepared C drive. Nota bene: for this drive this script should not be called.
winmaster='/windows/C'
#filename  of the usermap, e.g. .NTFS-3G/UserMapping -  without leading /
umname=.NTFS-3G/UserMapping
# flagcpre == flag - copy and remount
flagcpre=0
# flagreplace   replace usermap if different to master; 0 == no
flagreplace=0

#
if [ -f "$winmaster/$umname" ];then
         echo "ntsf-3g-um INFO $winmaster/$umname exists."
else
        #
        # wait to read file
        #
        /usr/bin/touch /tmp/start-wait-ntsf-windowsC--for-dev-$1
        /usr/bin/timeout 90s  /usr/local/sbin/lcmin1 $winmaster/$umname
        /usr/bin/touch /tmp/end-wait-ntsf-windowsC--for-dev-$1
fi
#
# mount device and store name
# from debug we see
# ++ /usr/bin/udisksctl mount --block-device /dev/sdb1
# + winchecktemp1='Mounted /dev/sdb1 at /mnt/elements.'
# Therefore the 8th character must be a '/'
winchecktemp1="`/usr/bin/udisksctl mount  --block-device /dev/$1`"
if [ "${winchecktemp1:8:1}x" != "/x" ]
then
        # expected is an absolute filename, but it is not!
        echo 'ntsf-3g-um ERROR: cannot mount block-device /dev/'"$1"
        exit 1
# else  nothing to do, OK
fi
winchecktemp="`echo $winchecktemp1 | cut -d' ' -f4`"
echo $winchecktemp
# last character is . (a dot)  -- subtract it
winchecktemplen=`echo   ${#winchecktemp}-1|bc`
wincheck=`echo ${winchecktemp:0:$winchecktemplen}`
#
# wait to read file
/usr/bin/touch "/tmp/start-wait-ntsf-3g-um--for-dev-$1-`echo $wincheck/$umname | tr / _`"
/usr/bin/timeout 60s  /usr/local/sbin/lcmin1 $wincheck/$umname
/usr/bin/touch /tmp/end-wait-ntsf-3g-um--for-dev-$1

if [ -f "$wincheck/$umname" ]
   then
     # echeo "ntsf-3g-um  INFO: $wincheck/$umname exists."
     diff  $winmaster/$umname  $wincheck/$umname > /dev/null 2>&1
     if [ $? != 0 ]
     then
        echo "ntsf-3g-um  INFO: The um files differ"
        if [ $flagreplace !=0 ]
                then
                        mv $wincheck/$umname   $wincheck/${umname}`ls $wincheck/${umname}* | wc -l `
                        flagcpre=1
                else
                        echo "ntsf-3g-um  INFO: Different usermap found: `ls -l  $wincheck/${umname}`"
                fi
#       else
#               no diff  -- ok
     fi
else
    echo "ntsf-3g-um: $wincheck/$umname does not exist. create it." > /dev/stderr
    flagcpre=1
fi
#
if [ $flagcpre  == 1 ]
then
    #        copy
    #   cp "$winmaster/$umname" "$wincheck/$umname"
    #   BUT honour directory structure - this is done with tar/untar
    #
    cd $winmaster
    tar cf - "$umname" | ( cd "$wincheck"  && tar -xvf -  )
    #  remount new disk so that usermap is used
    #  but      mount -o remount /dev/$1 $wincheck ##### not supported 2016-06 #####
    umount $wincheck
    /usr/bin/udisksctl mount  --block-device /dev/$1
    echo "Remount /dev/$1 $wincheck  done"
fi



The directories are
Code:
/usr/local/sbin
/etc/udev/rules.d


I have posted these in the hope they are useful. Usage is as always on your own risk.
Maybe there are some proposals for refinements.

Regards
RfMMshFL


Sat Jul 09, 2016 19:27
Profile
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Original forum style by Vjacheslav Trushkin.