StevoB
Posts: 5
Joined: Sat Dec 09, 2017 4:32 pm

Unable to use NTFS partition with USB-OTG g_mass_storage module

Sat Dec 09, 2017 5:08 pm

Hi,

I'm currently trying to set a NTFS partition configured on my RPi Zero W to be accessible from my PC as as USB Mass Storage Media. It seems possible using the g_mass_storage USB-OTG module.

This basic test below works fine with my device, it mounts as a small floppy drive on my Windows 10 PC :

sudo dd if=/dev/zero of=/piusb.bin bs=512 count=2880
sudo mkdosfs /piusb.bin
sudo modprobe g_mass_storage file=/piusb.bin stall=0

However, I cannot mount the NTFS partition I want :

sudo modprobe g_mass_storage file=/dev/mmcblk0p3 stall=0
OR
sudo modprobe g_mass_storage file=/home/pi/MEDIA stall=0

Any ideas why this isn't working?

System Configuration :

System updated through apt-get update/upgrade on 2017-12-05

Release information :

uname -r
4.9.59+

cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"
NAME="Raspbian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

Current partitions (all are working fine) :

/dev/mmcblk0p1 ... 41.5M c W95 FAT32 (LBA)
/dev/mmcblk0p2 ... 8G 83 Linux
/dev/mmcblk0p3 ... 111G 7 HPFS/NTFS/exFAT

/dev/mmcblk0p2 on / type ext4 (rw,noatime,data=ordered)
/dev/mmcblk0p1 on /boot type vfat (rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,errors=remount-ro)
/dev/mmcblk0p3 on /home/pi/MEDIA type fuseblk (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)


Thanks for the support

ebaierl
Posts: 35
Joined: Wed Jun 01, 2016 10:05 pm
Location: Wherever we happen to be
Contact: Website Facebook Twitter

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Sun Dec 10, 2017 12:44 am

Try this:
https://gist.github.com/etes/aa76a6e9c80579872e5f

Raspbian doesn't have NTFS read built in, have to add it after market.

StevoB
Posts: 5
Joined: Sat Dec 09, 2017 4:32 pm

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Sun Dec 10, 2017 1:58 am

ebaierl wrote:
Sun Dec 10, 2017 12:44 am
Try this:
https://gist.github.com/etes/aa76a6e9c80579872e5f

Raspbian doesn't have NTFS read built in, have to add it after market.
Thanks for the info ebaierl but I've already did that, the NTFS partition is working fine already. As listed before :

/dev/mmcblk0p3 ... 111G 7 HPFS/NTFS/exFAT
/dev/mmcblk0p3 on /home/pi/MEDIA type fuseblk (rw,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)


The NTFS partition is correctly mounted and I've been able to copy files onto it.

However, I cannot make this partition available to a PC using the g_mass_storage USB-OTG module... :(

d_older
Posts: 119
Joined: Mon Jun 25, 2012 5:04 pm
Location: East Yorkshire, UK

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Sun Dec 10, 2017 10:19 am

Hi StevoB,

Is the partition already mounted when you issue the command

"sudo modprobe g_mass_storage file=/dev/mmcblk0p3 stall=0" ?

I'm not sure what happens when 2 process attempt to control the same filesystem.

I thinks the reason for the "/home/pi/MEDIA stall=0" after mounting blk0p3 on the Pi fail is that it is offering a directory and not a block device / image file.

Hope this helps,

Dave

User avatar
thagrol
Posts: 1888
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Sun Dec 10, 2017 2:17 pm

Some stuff to consider:
  1. g_mass_storage expects either a file or a block device. A directory won't work.
  2. The USB host must support your chosen filesystem.
  3. Both sides expect exclusive acess to the backing store when it is mounted so simultaneous read/write access will cause file corruption. Read only access from one side with simultaneous read/write access on the other will also do unpredictable things. This is because there is no way for either side to inform the other of changes and both sides using caching.
  4. Simultaneous read only acess from both sides is OK.
  5. With a windows USB host, I've found it best to create the backing store on the pi but not format it. Formatting is then done from the windows host.
Raspbian does have ntfs read built in. It doesn't have ntfs read/write support. You need to

Code: Select all

sudo apt install ntfs-3g
to get it.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

StevoB
Posts: 5
Joined: Sat Dec 09, 2017 4:32 pm

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Mon Dec 11, 2017 2:49 am

thagrol wrote:
Sun Dec 10, 2017 2:17 pm
Some stuff to consider:
  1. g_mass_storage expects either a file or a block device. A directory won't work.
  2. The USB host must support your chosen filesystem.
  3. Both sides expect exclusive acess to the backing store when it is mounted so simultaneous read/write access will cause file corruption. Read only access from one side with simultaneous read/write access on the other will also do unpredictable things. This is because there is no way for either side to inform the other of changes and both sides using caching.
  4. Simultaneous read only acess from both sides is OK.
  5. With a windows USB host, I've found it best to create the backing store on the pi but not format it. Formatting is then done from the windows host.
Raspbian does have ntfs read built in. It doesn't have ntfs read/write support. You need to

Code: Select all

sudo apt install ntfs-3g
to get it.
Hi thagrol,

I've tried what you suggested:

1 - I've remounted the NTFS partition as read-only. I did try to echo something in a test file and the error message confirms to me the read-only status. This new configuration fixes simultaneous writes accesses.
2 - I've tried many times to use the block device "/dev/mmcblk0p3" with g_mass_storage without success.
sudo modprobe g_mass_storage file=/dev/mmcblk0p3
3 - On my setup, g_mass_storage ONLY works with files, not block devices.

Is there anybody who succeeded to use g_mass_storage with a block device?

Thanks

User avatar
thagrol
Posts: 1888
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Mon Dec 11, 2017 1:05 pm

StevoB wrote:
Mon Dec 11, 2017 2:49 am
Is there anybody who succeeded to use g_mass_storage with a block device?
Yep, on several PIs.

In /boot/config.txt:

Code: Select all

device=dwc2

In /etc/rc.local:

Code: Select all

modprobe g_mass_storage file=/dev/mmcblk0p3

No references to g _mass_storage anywhere else (/etc/modules, /etc/modprobe.d, etc)

I'm mostly using windows USB hosts so tend to format the store from that side rather than from linux on the pi.

Oh, all the PIs I've done this on are running jessie, not stretch. I've also has this working with "removable=1" andd passing the backing store via /sys/...
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

StevoB
Posts: 5
Joined: Sat Dec 09, 2017 4:32 pm

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Mon Dec 11, 2017 3:06 pm

Well, the steps seems really straight forward to me. I've been through all of this with the exception I'm currently running Stretch, not Jessie. I guess this might be why I'm having thos e problems.

Thanks for the help.

Steve

User avatar
thagrol
Posts: 1888
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Wed Dec 13, 2017 11:42 pm

OK, I've managed to find a spare SD card and experiment with stretch.
The gadget partition is recognised on my windows 10 box but if it hasn't yet been formatted it doesn't show up in "This PC" It does show in device manager.

The trick seems to be to open "Computer Management" (right click start button, pick from the menu) look for "Disk Management" and format it there.

Win10 seems to be OK with it formatted on linux (FAT16, zero in gadget mode, format done by gparted on a PI running jessie)
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

broe23
Posts: 903
Joined: Thu Jan 28, 2016 9:35 pm
Location: Central IL
Contact: Website

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Thu Dec 14, 2017 2:03 am

Any storage device you want to share between Linux and Windows, needs to be formatted Fat32.
Ren: Now listen, Cadet. I've got a job for you. See this button? Ren: Don't touch it! It's the History Eraser button, you fool! Stimpy: So what'll happen? Ren: That's just it. We don't know. Maybe something bad, maybe something good.

User avatar
thagrol
Posts: 1888
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: Unable to use NTFS partition with USB-OTG g_mass_storage module

Thu Dec 14, 2017 12:18 pm

broe23 wrote:
Thu Dec 14, 2017 2:03 am
Any storage device you want to share between Linux and Windows, needs to be formatted Fat32.
That's not correct. You can use any filesystem that both can understand: FAT12, FAT16, FAT32, XFAT, NTFS, EXT2 (if you have installed drivers on windows), etc...

Edit:
If you're thinking of /boot, that does have to be FAT but not because of windows. It's because of boot code internal to the cpu/gpu on the PI expect it.
Attempts to contact me outside of thes forums will be ignored unless signed in triplicate, sent in, sent back, queried, lost, found, subjected to public enquiry, lost again, and finally buried in soft peat for three months and recycled as firelighters

Return to “General discussion”