You are not logged in.
Pages: 1
I have a system running SliTaz and I need to automatically mount a device when it is plugged in, run a script, then dismount the device.
This is for automatic backup of a headless system.
I found a udev rule that works perfectly on a similar Fedora setup, but it does not seem to do anything on the SliTaz install...
Is there something I must change to make it work on SliTaz?
Here is my udev rule:
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0024", KERNEL=="sd[a-z]", NAME:="%k", SYMLINK:="backupdevice", OPTIONS="last_rule"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0024", ACTION=="add", KERNEL=="sd[a-z]1", SYMLINK:="backuppartition", GROUP:="users", NAME:="%k"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0024", ACTION=="add", KERNEL=="sd[a-z]1", RUN+="/bin/mount -t auto -o rw,noauto,async,dirsync,noexec,nodev,noatime /dev/%k /media/backup-drive"
SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0024", ACTION=="add", KERNEL=="sd[a-z]1", RUN+="/usr/local/bin/usb_backup.sh" OPTIONS="last_rule"SUBSYSTEMS=="usb", ATTRS{idVendor}=="8087", ATTRS{idProduct}=="0024", ACTION=="remove", KERNEL=="sd[a-z]1", RUN+="/bin/mount -l /media/backup-drive", OPTIONS="last_rule"
Offline
Are you using 4.0 or rolling?
in rolling I had the issue, that I did not get usbmodswitch to switch the modem automatic - I have to do this with a script
I could not find out, what was the problem - it sounds quite similar.
Its on my list to look into, as soon, as I have time - try to change the udev log level to debug in /etc/udev.conf and see what
grep udev /var/log/messages gives
also compare the udev.conf of Slitaz with Fedora, perhaps there is someting you can find...
but my issue is from last autumn... so maybe it is repaired in the meantime
Offline
Thanks for the suggestions. I will check it out and reply back with findings.
Offline
Well, there's nothing of interest different between the two udev.conf files.
The system has no /var/log/messages file. I'm not sure why there's no system logger on this installation but this appears to be the case.
Is there some alternative solution to run a script when a USB device is plugged in?
Offline
Have you tested the mount commands and run the scripts you expect udev to execute manually from terminal as root?
Slitaz uses busybox ash shell and applets for utilitys such as mount.
They are not fully compatible with the GNU versions and the shells you find on the full size distros.
Offline
That is what I initially believed to be the problem. I did have to make some considerable modifications to make my script run on the busybox shell but it does run now if I execute it manually.
To be safe, I removed my udev rule and replaced it with one that simply runs a script to echo a line of text to a file.
This rule never triggers either.
Offline
there are more alternatives - how I solved it
make a new file (eg backup.desktop) in /home/tux/.local/share/applications
put the script backup.sh with the mount part eg. in /home/tux/.backup
backup.desktop should be something like
[Desktop Entry]
Encoding=UTF-8
Name=backup
Exec=tazbox su /home/tux/.backup/backup.sh
Icon=????
Type=Application
Categories=System;Application;
take care with the mount option - because normally Spacefm should automount the usb device - this could also cause the problem, that your rule is not executed???
and is it true, that new rolling has no /var/log/massages ??
Offline
The problem comes also with pcmanfm : no autodetection for usb's neither for internal disks
Offline
Kultex: I have created the .desktop file and linked it to backup script. How do I get this to autoexecute though?
I have noticed that udevd is not running on boot. I see hald, however.
I manually started udevd but still the rules are not executed.
Offline
@Iricher
I gave you the .desktop solution, because if somebody is sticking in the usb stick manually, he just could run the desktop entry, which you will find in the menu under system.
if it is a server with no monitor, this will not work
for automatisation I think, it think only udev can do it - maybe also udevil, but I do not know udevil so good - maybe the 4 last options in the udvil.conf???
http://ignorantguru.github.io/udevil/udevil.conf.txt
If you dont sucseed, maybe I can look into it in 10 days...
@vergote rolling is working with spacefm and udevil - if you want to use pcmanfm you have to install udisks - but you should deinstall spacefm and udevil
Offline
I am finally making progress!
It does not seem to handle the same rule options as Fedora does... If I add SYMLINK to the rule it will not process, the subsystem is block and not usb.
It runs my scripts but not properly... I make a script that mounts the drive and touches a log file. When udev triggers the rule, the script touches the log file but does not mount the drive. If I manually run the script, the drive is mounted... Curious.
I will post any updates.
Offline
When udev tries to mount the drive, it instead mounts what looks like some default slitaz filesystem stuff...
README boot/ index.html md5sum style.css (README containts SliTaz GNU/Linux license, etc)
Again, if I run the mount script from shell, it executes correctly and mounts the drive.
When it is executed by udev rule, it mounts the SliTaz contents I mentioned earlier...
No ideas how to proceed now.
Offline
still I dont know which version 4.0 or rolling
Offline
My apologies. SliTaz 4.0, not rolling.
Offline
sorry, with 4.0 I cannot help - I did not use 4.0 as there is no i486 support - I swiched very early to rolling.
try it with rolling - its for me more stable and quicker
new rolling has some bugs:
pango is still broken you have to run a post_install command: - find the shell (quite easy)
# /usr/bin/pango-querymodules > /etc/pango/pango.modules
start X new with strg+alt+backspace
then you have to install bash, because spacefm now grouses when bash i not installed....
alternativ you can use a iso I did month ago - http://forum.slitaz.org/topic/testing-iso-with-kernel-3250 it is my dayli os and I am verry happy with it
Offline
Coming back to post solution incase anyone else ever runs into something similar.
It appears the root of my problem was Busybox mount utility.
What I did is add this line at the beginning of my mount script:
[c]exec >/home/tux/udev.out 2>&1[/c]
this revealed the error message: "mount: mounting /dev/sdb1 on /mnt/backup failed: No such device"
I played around with mount (adding -t ntfs-3g, adding the drive to fstab and doing mount -a, etc) to no avail.
Finally I instead tried to mount the drive using ntfs-3g utility with
[c]ntfs-3g /dev/sdb1 /mnt/backup[/c] (I am using a symlink instead of sdb1, just for readability sake I type sdb1)
which works perfectly via udev. Strange that mount command worked from shell but not from udev, but ntfs-3g appears to work.
Thank you everyone who helped!
Offline
Pages: 1
[ Generated in 0.020 seconds, 7 queries executed - Memory usage: 1.56 MiB (Peak: 1.77 MiB) ]