0

I have an Orange Pi One with the Armbian OS. I want to use it to collect data from sensors 24/7. And be able to save the database to a flash drive.

Considering the presence of only one USB port, as well as a certain autonomy of the device, I would like to automate the process of copying the database. I would like to do this: a flash drive is inserted, auto-mounting occurs based on this event, the indicator begins to blink and automatic copying occurs, then automatic unmounting occurs, and the indicator begins to flash differently, signaling that the copying is completed and the flash drive can be removed.

The problem is the automatic mounting and unmounting of the flash drive.

  • First I decided to install the usbmount utility...
    sudo apt install usbmount
    
    But it apparently is not in the repository:
    Reading package lists... Done
    Building dependency tree... Done
    Reading state information... Done
    E: Unable to locate package usbmount
    
  • Then I tried to insert into the .sh called by the rule from /etc/udev/rules.d the command...
    #!/bin/sh
    sleep 15
    echo "mount runs" >> /mydir/log.txt
    echo MY_PASSWORD | sudo mount /dev/sda1 /flash
    
    The script runs successfully from the command line when the flash drive is connected. But starting from the rule, this script writes the text to the log.txt file, but does not mount the disk.

Then I read about /etc/fstab. In particular, this method.

  • I inserted the flash drive, executed the command
    lsblk -f
    
    and got the UUID
    NAME        FSTYPE FSVER LABEL      UUID        FSAVAIL FSUSE% MOUNTPOINTS
    sda
    ├─sda1      vfat   FAT32            0698-A3CF
    └─sda2      vfat   FAT16 VTOYEFI    3A23-0E50
    
  • Then I made changes to /etc/fstab, replacing only the UUID and timeouts (set to 15):
    UUID=0698-A3CF  /mnt/32GBkey  vfat  noauto,nofail,x-systemd.automount,x-systemd.idle-timeout=15,x-systemd.device-timeout=15
    
  • Then along with sudo I updated the changes:
    sudo systemctl daemon-reload && sudo systemctl restart local-fs.target
    
  • I unmounted the flash drive and pulled it out. The lsblk -f command showed that the flash drive is no longer there.

I restarted it and ran lsblk -f again. The flash drive is still recognized, but the MOUNTPOINTS column is still empty. The flash drive was not mounted.

What am I doing wrong?

1 Answer 1

0

As of [some releases ago], udev worker processes are slightly isolated – they run in a separate mount namespace among other things, which means that any mounts they make only exist in the world of that one process. (The same feature used by container software.) The intent is to discourage starting daemons directly off udev, as well as doing any "slow" things (all udev rule processing waits on the RUN to complete).

Additionally, because udev rule processing waits for RUN to complete before announcing the device "ready" to other software, this also includes systemd itself which may (depending on version) auto-unmount filesystems that it thinks were mounted from a device that's not yet plugged in (not announced by udev).

Instead, have the udev rule start a systemd service that performs the job, with systemctl --no-block start or even ENV{SYSTEMD_WANTS}.

1
  • How can I do this? Is it possible to do what I need? Is it possible to do automaticle backup when I insert my usb storage device? Commented Oct 30, 2024 at 19:29

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.