
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
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