Mounting USB storage stick

I am trying to mount a USB storage stick following these instructions https://docs.resin.io/runtime/runtime/#mounting-external-storage-media. I am using systemd and tried using systemd .mount files. My USB stick is formatted in FAT, and below is my mnt-storage.mount file

[Unit]
Description = External USB stick storage

[Mount]
What = LABEL=Verbatim
Where = /mnt/storage
Type = fat
Options = rw,relatime,data=ordered

[Install]
WantedBy = multi-user.target

The folder /mnt/storage is created but when I copy a file to this folder it is not copied to the USB stick. What’s wrong with my setup ? Maybe I cannot use FAT format ?

1 Like

Hey, you can use the web terminal or resin ssh to go into your container and check the status of that service by systemctl status mnt-storage.mount.

In this case, you had actually 3 issues with that service file:

  1. FAT labels are all uppercase (the error logged by systemd was mount: can't find LABEL=Verbatim, so have to update that
  2. The file system type’s name is not fat, but vfat (the error logged by systemd was mount: unknown filesystem type 'fat'
  3. The options there are from ext4, I think, and not the proper options for vfat. See the available options in this doc (the error logged was mount: wrong fs type, bad option, bad superblock on /dev/sda1)

With all these changes, here’s the working version of your mnt-storage.mount service file:

[Unit]
Description = External USB stick storage

[Mount]
What = LABEL=VERBATIM
Where = /mnt/storage
Type = vfat
Options = rw

[Install]
WantedBy = multi-user.target

Below is the output of systemctl status mnt-storage.mount

● mnt-storage.mount - External USB stick storage
   Loaded: loaded (/etc/systemd/system/mnt-storage.mount; enabled)
   Active: failed (Result: exit-code) since Mon 2017-04-10 19:09:31 UTC; 14h ago
    Where: /mnt/storage
     What: LABEL=V
  Process: 41 ExecMount=/bin/mount -n LABEL=Verbatim /mnt/storage -t fat -o rw,relatime,data=ordered (code=exited, status=32)

Apr 10 19:09:31 367f711 systemd[1]: mnt-storage.mount mount process exited, code=exited status=32
Apr 10 19:09:31 367f711 systemd[1]: Failed to mount External USB stick storage.
Apr 10 19:09:31 367f711 systemd[1]: Unit mnt-storage.mount entered failed state.
Apr 10 19:09:38 367f711 mount[41]: mount: unknown filesystem type 'fat'
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

Yes, you are hitting the no. 2 error mentioned above, that the proper file system name is not fat but vfat.

Could you give a shot copy-pasting the fixed up mnt-storage.mount as shown above into your service file, and try that?

Below the output of systemctl status mnt-storage.mount after the fix

● mnt-storage.mount - External USB stick storage
   Loaded: loaded (/etc/systemd/system/mnt-storage.mount; enabled)
   Active: active (mounted) since Tue 2017-04-11 09:51:55 UTC; 1min 26s ago
    Where: /mnt/storage
     What: /dev/sda1
  Process: 41 ExecMount=/bin/mount -n LABEL=Verbatim /mnt/storage -t vfat -o rw (code=exited, status=0/SUCCESS)

Apr 11 09:51:55 367f711 systemd[1]: Mounted External USB stick storage.
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable. 

Apparently it worked :slight_smile: Thanks a lot

The USB might have been corrupted try contacting your USB provider. If that does not work out then look for third party software’s including SysInfoTools Software, Aryson Technologies. They work out fantastically.

I have done the same solution and it works nicely with LABEL=STORAGE and naming different USB sticks to STORAGE
but when I unplug a USB stick and reinsert it I get input output errors.
If i reboot the machine it works nicely again.

This is after I reinserted a USB drive

----snap dmesg output
[314008.563247] usb-storage 1-1.2:1.0: USB Mass Storage device detected
[314008.595727] scsi host6: usb-storage 1-1.2:1.0
[314010.535236] scsi 6:0:0:0: Direct-Access SMI USB DISK 1100 PQ: 0 ANSI: 4
[314010.547511] sd 6:0:0:0: [sda] 31211520 512-byte logical blocks: (16.0 GB/14.9 GiB)
[314010.548022] sd 6:0:0:0: Attached scsi generic sg0 type 0
[314010.548968] sd 6:0:0:0: [sda] Write Protect is off
[314010.549013] sd 6:0:0:0: [sda] Mode Sense: 43 00 00 00
[314010.550391] sd 6:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn’t support DPO or FUA
[314010.562474] sda: sda1
[314010.569243] sd 6:0:0:0: [sda] Attached SCSI removable disk

An ls works nicely so the mount seems to be working

root@88110ad:/usr/src/app# ls /mnt/storage/

Also syctemctl likes it

root@88110ad:/usr/src/app# systemctl status mnt-storage.mount
● mnt-storage.mount - External USB stick storage
Loaded: loaded (/etc/systemd/system/mnt-storage.mount; enabled)
Active: active (mounted) since Fri 2017-08-11 12:07:10 UTC; 1h 9min ago
Where: /mnt/storage
What: /dev/sdb1
Process: 44 ExecMount=/bin/mount -n LABEL=STORAGE /mnt/storage -t vfat -o rw (code=exited, status=0/SUCCESS)

Aug 11 12:07:10 88110ad systemd[1]: Mounted External USB stick storage.
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

But when trying to write it fails

root@88110ad:/usr/src/app# touch /mnt/storage/test.txt
touch: cannot touch ‘/mnt/storage/test.txt’: Input/output error
root@88110ad:/usr/src/app#

@JoachimLindborg, hmm, Input/output errors usually mean a corrupted disk, but as you said you can write to it fine if the usb stick already present at boot? You have tried an alternate usb stick right?

yes 3 different ones. And they work nicely in other machines

Gotta ask the stupid questions :blush: Let me try reproduce over here :+1:

1 Like

Hey @JoachimLindborg,

I managed to reproduce this, restarting the service fixes it, so you could have a udev rule to do that as a temporary work around. But it’s probably just a .mount option that we are missing, will try dig into the docs a little more and let you know.

Let me know if you make any progress in the meantime.

2 Likes

I’m on a raspberry pi 3b+ and not able to mount a usb stick due to mount: can't find LABEL=USBSTORAGE

Here’s my mnt-storage.mount file:

[Unit]
Description = External USB SD Card

[Mount]
What = LABEL=USBSTORAGE
Where = /mnt/storage
Type = vfat
Options = rw

[Install]
WantedBy = multi-user.target

And if I change the WHAT parameter to /dev/sda1, it works fine:

[Unit]
Description = External USB SD Card

[Mount]
What = /dev/sda1
Where = /mnt/storage
Type = vfat
Options = rw

[Install]
WantedBy = multi-user.target

Should I be adding something somewhere to first create the label before mnt-storage is started?

Another big question: Is there a way to replace /mnt/data on the resin boot partition with an external USB mount?

3 Likes