Hello everyone,
using Tinycore Linux on an Igel TC device, I tried modifying the UDEV rules according to the given hints in this forum. USB sticks are recognized but I'm experiencing quite some problems.
TC is installed on a CF card getting mounted as sda1 at boot. So when I plug in a new stick, the contents of the freshly plugged in USB stick fill up my /mnt-Folder, sda1 is removed or overwritten and after unplugging, contents still stay in /mnt.
What do I do wrong?
I assure, that the xxx and yyy scripts are correctly copied and also the 98-tc.rules is identically to the given information.
Thanks for your help
mindmachine
EDIT AS OF 2013-03-16Rich developed a working script to mount USB devices with ntfs/fat/fat32 aso. filesystems when plugged in. There is also a working unmount script to remove mountpoints and devices after unplugging. Please note, that using these scripts may (or better will) be a risc for your USB-sticks, as there is no working routine in Linux to avoid data loss. It might well be, that your sticks get unreadable after plugging out. If your stick already has got any problems (speaking in terms of being unclean), it won't get mounted, and it would get refused by the driver. Using ntfsfix would be partially helpful in this case but it is widely recommended to use a windows chkdsk command to repair it first. Thanks to tinypoodle for this important hint and the given explanations. You can find these later in this thread.
So integrity of your data is at risk if you use the following method
Anyway, here is what to do:
Download and install ntfsprogs to be run at boottime.
Remove ro-ntfs-driver from kernel, so the correct driver will be used:
sudo modprobe -r ntfs
Change "/etc/udev/rules.d/98-tc.rules":
KERNEL=="ram*", SUBSYSTEM=="block", GOTO="tc.rules_end"
KERNEL=="loop*", SUBSYSTEM=="block", GOTO="tc.rules_end"
ACTION=="add", SUBSYSTEM=="block", RUN+="/bin/sh -c '/bin/echo %k >> /tmp/automountqueue'"
ACTION=="remove", SUBSYSTEM=="block", RUN+="/bin/sh -c '/usr/local/sbin/usb-umount %k'"
LABEL="tc.rules_end"
Create the following scripts in "/usr/local/sbin"
usb-mount:
#!/bin/sh
QUEUE=/tmp/automountqueue
[ ! -e "$QUEUE" ] && mkfifo $QUEUE
while true
do
for i in `cat $QUEUE`
do
echo `date +"%T"`" Request to mount $i" >> /home/tc/mounttime
rebuildfstab
i=$(cat /etc/fstab | grep -w $i | cut -c 6-9) # we check fstab to avoid getting e.g. sdb1/ returned
echo `date +"%T"`" Cat returned $i" >> /home/tc/mounttime
[ -z $i ] && continue
echo `date +"%T"`" Mounting $i" >> /home/tc/mounttime
mntcommand="mount /dev/$i /mnt/$i"
grep $i /etc/fstab | grep -q ntfs
[ 0 -eq $? ] && mntcommand="/usr/local/bin/ntfsmount /dev/$i /mnt/$i"
grep -q $i /etc/mtab
[ 0 -ne $? ] && $mntcommand >>/home/tc/mount.txt 2>&1
done
echo `/usr/local/bin/date +"%T"`" Done" >> /home/tc/mounttime
done
If you don't care for data integrity and need usb devices get mounted in any case, replace
[ 0 -eq $? ] && mntcommand="/usr/local/bin/ntfsmount /dev/$i /mnt/$i"
by
[ 0 -eq $? ] && mntcommand="/usr/local/bin/ntfsmount -o force /dev/$i /mnt/$i"
and your devices will get mounted if dirty or not. You might have to use a forensic tool afterwards to rescue your data (encase, xways...)!!!
usb-umount:
#!/bin/sh
for i in $(cat /etc/fstab | grep $1 | cut -c 6-9) ## create correct variable i in case partition number is missing
do
[ -z $i ] && continue
umount /mnt/$i
sleep 1
rmdir /mnt/$1
rebuildfstab
done
Make the scripts executable:
chmod +x /usr/local/sbin/usb-mount
Relodad Udev-Rules:
sudo udevadm control --reload-rules
Add a line in your /opt/bootlocal.sh file:
/usr/local/sbin/usb-mount.sh &
Don't forget to make changes persistant!
Try if it works by either rebooting or by running the usb-mount script by hand (use "sh /usr/local/sbin/usb-mount &" so it will run in background).
Good luck!