LXDE & udev on Raspbian --Run script on USB Drive when plugged - linux

Running LXDE on Raspbian.
I want to run a script on a usb flash drive when the device is plugged. Any flash drive, not a specific one.
This is to provide code updates to customers without requiring a keyboard or mouse attached to one of several rpis in a system (they have displays but no input devices). The customer will download a file to a thumbdrive on his own device and then insert it in one of four rpis in the system. The script will "do what it needs" to backup old files and scp new ones to the correct hosts and remote directories in the system
I can write a udev rule that creates a symlink to the flash drive when plugged. The symlink shows up under /dev But, I can't cd into that symlink--I probably have to do a mount first.
By observation, LXDE seems to automount a USB flash drive in /media when plugged. I don't see the name of the mount point (e.g. /media/B85D-6433) when using:
udevadm info -a -p $(udevadm info -q path -n /dev/sda1) | grep -i 6433
or
udevadm info -a -p $(udevadm info -q path -n /dev/sda1) | grep -i B85D
So, I can't figure out where the LXDE will mount the drive without first knowing its name.
1) Is there a way to determine the name of the directory under /media that LXDE will use for the mount point? I could keep a list of what was in /media before and after the plug event and determine it that way, but maybe there's a better way?
2) Instead, should I mount the symlink under /dev to a different place then excecute the script on the usb drive via this new mount point?
3) Other way?
Thanks!

Related

Load root filesystem from USB device

I'm trying to make a fast reboot to the other Linux system. First step is kernel loading, I make it with
sudo kexec --append='$(cat /proc/cmdline)' -l new_kernel.img --reuse-cmdline
sudo kexec -e
It works fine, but loads only kernel, not entire system.
How can I mount an *.img file with OS resources, located at USB as /? Preferable during kernel loading, but afterwards mount is still suitable. *.img format is not necessary, it can be unpacked before
As stark said, pivot root() was the call I was searching for. Commands to make a USB located at /dev/sdb1 a root directory:
sudo -s
mkdir /newroot
mount /dev/sdb1 /newroot
cd /newroot
mkdir oldroot
pivot_root . oldroot/
switch_root() deletes all files at the previous root dir, also there are few other differences, this answer might be useful

How to make an incremental backup with rsync from ext4 to xfs network drive?

I'm on Ubuntu 14.04.
I try to make an incremental backup of some files on my Ubuntu HD (ext4) to a Buffalo network HD (XFS).
My script mounts the Buffalo HD with this command :
sudo mount.cifs //192.168.1.12/Sauvegardes /mnt/Sauvegardes -o username=myusername,password=mypassword
After the disk is mounted, I use rsync trying to make an incremental backup with rsync and --link-dest. Each day, when the script is launched, all the folders change according to actual date of the day. Here is an example when the script is launched on 2017-03-09. It should check on 2017-03-08 backup if files already exist :
sudo rsync -arR --link-dest="/mnt/Sauvegardes/racine_2017-03-08" --timeout=30 /home/flooder/Sauvegardes/ /mnt/Sauvegardes/racine_2017-03-09/
The problem : rsync doesn't seem to check on the --link-dest destination. It copies all the files all the day. So the disk will be full quickly and the backup is very very long each day...
Would you have an idea for me?
Should I mount the network drive an other way?
Do I have the right rsync command?
I have mounted my network disk with this line instead. It works well now. If the file already exists in --link-dest, only an hard link is created. Second pass is very very quick!
sudo mount -t cifs //192.168.1.12/Sauvegardes /mnt/Sauvegardes -o username=myusername,password=mypassword,uid=1000,gid=1000
uid and gid are those of my logged user.

How to make usbmount use /etc/fstab configuration

I'm using a Debian wheezy stable and I'm trying to automatically mount a specific usb device in a designated directory when it's plugged (not at boot time or with the mount command).
I know how to mount my device in the directory I want with /etc/fstab and the mount -a command with this /etc/fstab:
UUID="xxxxxxxxxxxxxxxx" /media/myFolder ntfs auto,exec,rw,user,suid,uid=1000 0 0
I also know how to use usbmount to mount a device when it is plugged.
My problem is that usbmount mounts the device in a folder /media/usbX and not in the directory specified in fstab.
I didn't find how to change the configuration of usbmount to make it respect the /etc/fstabfile.
Is it possible and if so how can I do it?
Check out MOUNTPOINTS in /etc/usbmount/usbmount.conf.
# Mountpoints: These directories are eligible as mointpoints for
# removable storage devices. A newly plugged in device is mounted on
# the first directory in this list that exists and on which nothing is
# mounted yet.
MOUNTPOINTS="/media/usb0 /media/usb1 /media/usb2 /media/usb3
/media/usb4 /media/usb5 /media/usb6 /media/usb7"

Using Optware packages and startup scripts on dd-wrt router

I'm trying to run a mumble server (umurmur) on my dd-wrt router (Buffalo WZR-HP-AG300H). I flashed one of the recent community versions of dd-wrt on the device (SVN Rev.: 23320), it has an Atheros CPU inside.
After that I mounted a USB pendrive into the filesystem using these guides (Guide 1, Guide 2) and created writable directories. Here is my startup-script saved to nvram (via web-gui)
EDIT: USB pendrive should be partioned before using it with DD-Wrt.
#!/bin/sh
sleep 5
insmod mbcache
insmod jbd
insmod ext3
mkdir '/mnt/part1'
mkdir '/mnt/part2'
mount -t ext3 -o noatime /dev/sda5 /mnt/part1 # /dev/sda5 -> partition on USB pendrive
mount -t ext3 -o noatime /dev/sda7 /mnt/part2 # /dev/sda7 -> partition on USB pendrive
swapon /dev/sda6 # /dev/sda6 -> partition on USB pendrive
sleep 2
if [ -f /mnt/part1/optware.enable ];then
#mount -o bind /mnt/part2 /mnt/part1/root
mount -o bind /mnt/part1 /jffs
mount -o bind /mnt/part1/etc /etc
mount -o bind /mnt/part1/opt /opt
mount -o bind /mnt/part1/root /tmp/root
else
exit
fi
if [ -d /opt/usr ]; then
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/lib:/usr/lib:/opt/lib:/opt/usr/lib:/jffs/usr/lib:/jffs/usr/local/lib
export PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/jffs/bin:/opt/bin:/opt/sbin:/opt/usr/bin:/opt/usr/sbin
export IPKG_INSTROOT=/opt
else
exit
fi
The script works well and I can use opkg to install packages. I can also run umurmur manually but I'm struggling on making umurmur autostart. I recognized that the umurmur startup script placed in /opt/etc/init.d/ requires arguments like start and stop but it seems they are called without any arguments.
Another way described here did not work too.
Has anyone a working solution on problems like these? Please help!
Optware runs on Broadcom routers only. Your's has an Atheros chipset.
Taken from this page: Link
Its unclear i the page you referred to has changed - and indeed my setup is fairly different to yours, but to get scripts working on startup I did the following -
mkdir -p /jffs/etc/config
copy script into /jffs/etc/config directory, renaming it to end with .startup
chmod 755 /jffs/etc/config/scriptname.startup

Mounting a directory?

I want to mount a particular folder as /system.
I tried mount -t ext2 -o loop /sd-ext/rom/system /system
I get mount: mounting /sd-ext/rom/system /system failed: Block device required
Im using android, so im limited to android shell and busybox.
I'm not familiar with Android, but if you want to mount a directory instead of a device you have to use mount with the --bind option.
If it's really a file then maybe your Android has no loop device support. Do you have any /dev/loop* devices?

Resources