Almost certainly not. Access from the USB host is low level access via a subset of SCSI commands (that's how USB mass storage works). The USB host will be doing it's own read and write caching (linux and windows do, I assume Macs do too but don't have one) so without ejecting the drive everything in those caches will be lost.
Code: Select all
modprobe g_mass_storage file=/piusb.bin stall=0 ro=1 removable=1Not that I'm aware of. Might be Mac OS thing.Linux_01 wrote: ↑Tue Mar 17, 2020 11:33 am@thagrol, thank you for the quick response.
Now there two concerns:
A) I have found that when I load the drive with read only, I am able to disconnect and reconnect the USB drive at Host side:But if I make it read and write then I am not able to reconnect the USB Drive after disconnecting it without ejecting at the host side.Code: Select all
modprobe g_mass_storage file=/piusb.bin stall=0 ro=1 removable=1
So wanted to know is there any workaround to reconnect the drive successfully or am I missing something?
No, and yes.B) After copying data into the USB Drive, at Pi Zero side I am do see the data unless and until I unmount and remount the drive.
Is it possible to view the contents on the go? Again am I missing something.
That's likely to do more harm than good. It looks to me that the OP is using a file for the backing store and that file is located on the root partition. Making that partition read only will also prevent the USB host from writing to the shared storage.PiGraham wrote: ↑Tue Mar 17, 2020 2:30 pmMaybe it would help if you set Raspbian as read-only on the Pi0. If read access can be shared safely and the host needs write access then removing write access from Raspbian might help.
There is an option for than in Buster.
viewtopic.php?f=63&t=253104&p=1549229#p1549117
Not necessarily.
OS corruption is only a risk with unsafe removeal if the zero is not seperately powered. It's also a risk if the zero is only powered from the host and the host is switched off without first shutting down the Pi.
I've done a few projects with various USB gadgets, yes. Not done any sudden removal testing recently or to any major extent. Most of the issues are not specific to the mass storage gadget, they're related to how modern file systems and disc access work.You sound familiar with this. Have you tried sudden removal and re-insertion of a Pi0 as mass storage gadget?
Not really. Sudden removal is a problem for any storage device where the host (and sometimes the device itself) uses write caching. It's not specific to USB or the Pi zero(w).I'm assuming this is not an issue with standard USB memory so it's something do with the Pi0.
We don't know for certain that it is trashing the backing store. It might be something related to Mac OS.
Code: Select all
Mar 17 16:41:35 Jha-RPi-USBDrive-01 kernel: [ 524.476447] dwc2 20980000.usb: new device is high-speed
Mar 17 16:41:35 Jha-RPi-USBDrive-01 kernel: [ 524.488071] dwc2 20980000.usb: new address 18
Mar 17 16:41:36 Jha-RPi-USBDrive-01 kernel: [ 524.496830] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage
Mar 17 16:42:43 Jha-RPi-USBDrive-01 kernel: [ 591.934334] dwc2 20980000.usb: new device is high-speed
Mar 17 16:42:43 Jha-RPi-USBDrive-01 kernel: [ 591.946505] dwc2 20980000.usb: new address 19
Mar 17 16:44:40 Jha-RPi-USBDrive-01 kernel: [ 709.023131] dwc2 20980000.usb: new device is high-speed
Mar 17 16:44:40 Jha-RPi-USBDrive-01 kernel: [ 709.034635] dwc2 20980000.usb: new address 20
Mar 17 17:04:04 Jha-RPi-USBDrive-01 kernel: [ 1873.382496] dwc2 20980000.usb: new device is high-speed
Mar 17 17:04:04 Jha-RPi-USBDrive-01 kernel: [ 1873.394712] dwc2 20980000.usb: new address 21
Mar 17 17:04:11 Jha-RPi-USBDrive-01 kernel: [ 1880.407365] dwc2 20980000.usb: new device is high-speed
Mar 17 17:04:11 Jha-RPi-USBDrive-01 kernel: [ 1880.419197] dwc2 20980000.usb: new address 22
Mar 17 17:04:14 Jha-RPi-USBDrive-01 kernel: [ 1883.434226] dwc2 20980000.usb: new device is high-speed
Mar 17 17:04:14 Jha-RPi-USBDrive-01 kernel: [ 1883.446854] dwc2 20980000.usb: new address 23
Mar 17 17:04:17 Jha-RPi-USBDrive-01 kernel: [ 1885.671076] dwc2 20980000.usb: new device is high-speed
Mar 17 17:04:17 Jha-RPi-USBDrive-01 kernel: [ 1885.682040] dwc2 20980000.usb: new address 24Code: Select all
root@Jha-RPi-USBDrive-01:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 7.3G 3.2G 3.7G 47% /
devtmpfs 213M 0 213M 0% /dev
tmpfs 217M 0 217M 0% /dev/shm
tmpfs 217M 3.3M 214M 2% /run
tmpfs 5.0M 4.0K 5.0M 1% /run/lock
tmpfs 217M 0 217M 0% /sys/fs/cgroup
/dev/mmcblk0p1 44M 23M 21M 52% /boot
/dev/loop0 197M 13M 185M 7% /mnt/usb_share
tmpfs 44M 0 44M 0% /run/user/1000I still suspect this is a Mac OS related problem so can't offer further help.Linux_01 wrote: ↑Wed Mar 18, 2020 12:28 pmWhen I connect the Pi as USB thumb drive for the 1st time to the MAC book, it detects and able to transfer the data.
If I disconnect the Pi from MAC book without ejecting it an dthen reconnect MAC doesn't detect where as at Pi end logs shows it detects the reinsertion but cannot map:Here you could see Pi has initially detected and not later on.Code: Select all
Mar 17 16:41:35 Jha-RPi-USBDrive-01 kernel: [ 524.476447] dwc2 20980000.usb: new device is high-speed Mar 17 16:41:35 Jha-RPi-USBDrive-01 kernel: [ 524.488071] dwc2 20980000.usb: new address 18 Mar 17 16:41:36 Jha-RPi-USBDrive-01 kernel: [ 524.496830] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage Mar 17 16:42:43 Jha-RPi-USBDrive-01 kernel: [ 591.934334] dwc2 20980000.usb: new device is high-speed Mar 17 16:42:43 Jha-RPi-USBDrive-01 kernel: [ 591.946505] dwc2 20980000.usb: new address 19 Mar 17 16:44:40 Jha-RPi-USBDrive-01 kernel: [ 709.023131] dwc2 20980000.usb: new device is high-speed Mar 17 16:44:40 Jha-RPi-USBDrive-01 kernel: [ 709.034635] dwc2 20980000.usb: new address 20 Mar 17 17:04:04 Jha-RPi-USBDrive-01 kernel: [ 1873.382496] dwc2 20980000.usb: new device is high-speed Mar 17 17:04:04 Jha-RPi-USBDrive-01 kernel: [ 1873.394712] dwc2 20980000.usb: new address 21 Mar 17 17:04:11 Jha-RPi-USBDrive-01 kernel: [ 1880.407365] dwc2 20980000.usb: new device is high-speed Mar 17 17:04:11 Jha-RPi-USBDrive-01 kernel: [ 1880.419197] dwc2 20980000.usb: new address 22 Mar 17 17:04:14 Jha-RPi-USBDrive-01 kernel: [ 1883.434226] dwc2 20980000.usb: new device is high-speed Mar 17 17:04:14 Jha-RPi-USBDrive-01 kernel: [ 1883.446854] dwc2 20980000.usb: new address 23 Mar 17 17:04:17 Jha-RPi-USBDrive-01 kernel: [ 1885.671076] dwc2 20980000.usb: new device is high-speed Mar 17 17:04:17 Jha-RPi-USBDrive-01 kernel: [ 1885.682040] dwc2 20980000.usb: new address 24
Never had a problem doing that. Check the cable and make sure that when using a single cable it's plugged into the data port on the zero.Moreover I am using separate cable for power supply and data transfer because if I use only one USB cable connected in Data port it will only provide power supply will not work to transfer data.
You can't re-partition it while it's running so you'll need another linux box or another SD card to boot from and a card reader.Linux_01 wrote: ↑Wed Mar 18, 2020 12:40 pmAnd I am using a file to save the data not partition for testing purpose I have 8GB memory card:How can I again partition my rootCode: Select all
root@Jha-RPi-USBDrive-01:~# df -h Filesystem Size Used Avail Use% Mounted on /dev/root 7.3G 3.2G 3.7G 47% / devtmpfs 213M 0 213M 0% /dev tmpfs 217M 0 217M 0% /dev/shm tmpfs 217M 3.3M 214M 2% /run tmpfs 5.0M 4.0K 5.0M 1% /run/lock tmpfs 217M 0 217M 0% /sys/fs/cgroup /dev/mmcblk0p1 44M 23M 21M 52% /boot /dev/loop0 197M 13M 185M 7% /mnt/usb_share tmpfs 44M 0 44M 0% /run/user/1000
Code: Select all
Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 24.927265] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 24.983265] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 25.039293] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.094999] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.150778] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.206651] dwc2 20980000.usb: new device is high-speed
Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.297716] dwc2 20980000.usb: new address 7
Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.323644] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage
Mar 19 11:17:22 Jha-RPi-USBDrive-01 kernel: [ 26.070905] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready
Mar 19 11:17:22 Jha-RPi-USBDrive-01 kernel: [ 26.692068] FAT-fs (loop0): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.Code: Select all
fsck.vfat -a /piusb.binTryLinux_01 wrote: ↑Thu Mar 19, 2020 6:01 amToday I checked connecting only one USB cable to the pi and MAC and it works.
Pi is able to get the power as well as able to transfer the data.
Also able to reconnect and mount the USB Drive at MAC after disconnecting abruptly with following fsck message in the logs:I have formatted files system as vfat and file storage name is "piusb.bin"Code: Select all
Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 24.927265] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 24.983265] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:20 Jha-RPi-USBDrive-01 kernel: [ 25.039293] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.094999] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.150778] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.206651] dwc2 20980000.usb: new device is high-speed Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.297716] dwc2 20980000.usb: new address 7 Mar 19 11:17:21 Jha-RPi-USBDrive-01 kernel: [ 25.323644] g_mass_storage gadget: high-speed config #1: Linux File-Backed Storage Mar 19 11:17:22 Jha-RPi-USBDrive-01 kernel: [ 26.070905] IPv6: ADDRCONF(NETDEV_CHANGE): wlan0: link becomes ready Mar 19 11:17:22 Jha-RPi-USBDrive-01 kernel: [ 26.692068] FAT-fs (loop0): Volume was not properly unmounted. Some data may be corrupt. Please run fsck.
Tried executing:With no luck.Code: Select all
fsck.vfat -a /piusb.bin
Please suggest how shall I go further?
Code: Select all
sudo fsck.vfat /dev/loop0Two cables could be a problem. If the Pi0 remains powered as you disconnect and reconnect to a host maybe it fails to reinitialise as it would on a single connection with data and power. IDK, just a thought.