I work for a company with large manufacturing equipment. We have an industrial machine which outputs logs to a USB drive, and workers have to get to an undesirable position to occasionally retrieve the USB to get logs.
A solution was proposed to engage a Raspberry PI4, with a PoE hat, to use the g_mass_storage module to emulate a USB storage device, then make the files available as a read-only samba share to windows clients without having to go near the equipment.
Ultimately, I have this "working". I built an image file I created a file to use as the backing device:
I then created a "/etc/modprobe.d/g_mass_storage.conf" configuration with the content "options g_mass_storage file=/piusb.bin stall=0 ro=0 removable=0". This is working, and the device shows up as a USB device I can write to.
The third piece of this is the samba share, but before that, I made a mount point at "/mnt/usb_share". I am mounting this with the following fstab entry: "/piusb.bin /mnt/usb_share auto ro,loop 0 0"
This works, and ultimately, I can samba share it and it's "working". The mount point and the samba share are read-only, the only write should be from the device seeing this as a USB mass storage device. The issue is, when I write files to the USB, they do not show up in linux under /mnt/usb_share, and thus don't show up to samba, until something happens; it's as if writes to the .bin file are not instant, and if they are, they are not reflected in the mount point. I tried a forcible unmount/remount, and that did not make the files show up; one time ejecting the USB from the test computer made the files show up, and naturally a reboot made them show up.
Is there anything I can to do make writes from the USB storage instantly reflected in the bin and thus available read-only to the OS? Am I missing something obvious here?
A solution was proposed to engage a Raspberry PI4, with a PoE hat, to use the g_mass_storage module to emulate a USB storage device, then make the files available as a read-only samba share to windows clients without having to go near the equipment.
Ultimately, I have this "working". I built an image file I created a file to use as the backing device:
Code:
dd if=/dev/zero of=/piusb.bin bs=1M count=8192chmod 666 /piusb.bin# Format the image file to Fat32mkdosfs /piusb.bin -F 32 -IThe third piece of this is the samba share, but before that, I made a mount point at "/mnt/usb_share". I am mounting this with the following fstab entry: "/piusb.bin /mnt/usb_share auto ro,loop 0 0"
This works, and ultimately, I can samba share it and it's "working". The mount point and the samba share are read-only, the only write should be from the device seeing this as a USB mass storage device. The issue is, when I write files to the USB, they do not show up in linux under /mnt/usb_share, and thus don't show up to samba, until something happens; it's as if writes to the .bin file are not instant, and if they are, they are not reflected in the mount point. I tried a forcible unmount/remount, and that did not make the files show up; one time ejecting the USB from the test computer made the files show up, and naturally a reboot made them show up.
Is there anything I can to do make writes from the USB storage instantly reflected in the bin and thus available read-only to the OS? Am I missing something obvious here?
Statistics: Posted by surfrock66 — Thu Oct 02, 2025 5:18 pm — Replies 5 — Views 129