Automount usb stick to /media/<LABEL> on jetson nano

Ive been googling and havent found a solution to the probelm.

In the current l4t image, usb memory sticks mount to /media/ in read only mode. Something like " /media/FF23-DG24 ". On a separate ubuntu machine, the same device auto mounts to /media/MyUSBStick (the label of the device). How do a configure this behavior on the nano as well as allow write access?

Thanks in advance

When the device is mounted it will show up somewhere in “/etc/mtab”. If you go through that list of everything mounted in “/media”, what does it show? This command will help:
grep 'media' /etc/mtab

on nano:
systemd-1 /media/F660-B20C autofs rw,relatime,fd=74,pgrp=1,timeout=0,minproto=5,maxproto=5,direct 0 0
/dev/sda1 /media/F660-B20C vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,errors=remount-ro 0 0

on user comp
/dev/sdb1 /media/user/USBSTICK vfat rw,nosuid,nodev,relatime,uid=1262,gid=2001,fmask=0022,dmask=0022,codepage=437,iocharset=iso8859-1,shortname=mixed,showexec,utf8,flush,errors=remount-ro 0 0

Does your Nano have this file?
/etc/udev/rules.d/99-nv-ufs-mount.rules

Yup

Copyright © 2019, NVIDIA CORPORATION. All rights reserved.

Mount UFS card when detected.

ACTION==“add”, KERNEL==“sd[a-z][0-9]”, SUBSYSTEM==“block”, RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media/%E{ID_FS_UUID}"

Unmount UFS card when removed.

ACTION==“remove”, KERNEL==“sd[a-z][0-9]”, SUBSYSTEM==“block”, RUN{program}+="/usr/bin/systemd-umount /media/%E{ID_FS_UUID}"

Those rules are not causing read-only mode. In fact the mount listed in mtab shows it as read-write ("rw"), but there is a stipulation that if there are filesystem errors in need of correction it reverts to read-only. I suspect that the reason it is read-only is due to errors which need to be corrected, e.g., due to pulling the USB memory stick while it was still mounted.

What happens if you first unmount, then filesystem check (might require first adding a package, “sudo apt-get install dosfstools”):

sudo umount /dev/sda1
sudo fsck.vfat /dev/sda1
# You could then reboot if fsck.vfat fixed an error.

Tried but no change. It is mounted as root on the nano, where as on the local machine it is mounted under my user name

drwxr-xr-x 3 root root 4096 Oct 19 12:47 .
drwxr-xr-x 22 root root 4096 Oct 1 15:16 …
drwxr-xr-x 6 root root 16384 Dec 31 1969 F660-B20C

Also, how to I modify the udev? I see it is configured to mount the device as %E{ID_FS_UUID} . Where can I look to find other parameters to pass and thus change it to the label?

I suggest you save a backup copy of “99-nv-ufs-mount.rules” somewhere safe, and then edit that file directly.

Was there anything found in need of correction from the fsck.vfat?

There might be a simpler way to go about this if just this one partition needs to be modified to mount differently. We could just put a mount line in fstab.

No change from the fsck.vfat command.

I could put in the line in fstab , but there will be multiple usb drives with the same label, different UUIDs

What is the specific use case? Do you have multiple USB sticks with the same layout, and any of them can be used on any of multiple Nanos? Or multiple USB sticks, with different UUIDs to be mounted differently? To be mounted in the same spot? Any detail you can provide about what you are working with and how you are wanting mount to occur would help.

End user plugs in any usb stick to a robot. The robot detects if a usb stick is there, and if so, records data to it. The end user is not computer savy, but should be able to change the label on usb stick.

I was able to get it to mount correctly by changing ID_FS_UUID to ID_FS_LABEL, but it is mounting as root and I cant write to it.

I see…what you need is to change mount options. I have not tested this, but essentially you will have three issues:

  • Mount point must be a consistent name without the UUID.
  • Mount point must be read-write for the user.
  • Mount options must make the partition read-write.

Is the user name always going to be the same? If so, then it simplifies life.

In the cause of needing a consistent mount point, the best method might be to let automount continue mounting via UUID naming, but to then add a symbolic link to a consistent name which is an alias for the UUID point.

Mount folder will always be /media/myusbstick (or similiar). User name is always nano (default L4T image).

How do I set the mount point for read write by the user, as well as make the partition read write? Tried chmod etc.

This is the initial “/etc/udev/rules.d/99-nv-ufs-mount.rules”:

# Mount UFS card when detected.
ACTION=="add", KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media/%E{ID_FS_UUID}"

# Unmount UFS card when removed.
ACTION=="remove", KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", RUN{program}+="/usr/bin/systemd-umount /media/%E{ID_FS_UUID}"

I am not doing this on an actual Jetson, so steps could be wrong. However, examine this edit to and see what happens:

# Mount UFS card when detected.
ACTION=="add", KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", RUN{program}+="/usr/bin/systemd-mount --no-block --automount=yes --collect $devnode /media/%E{ID_FS_UUID}, SYMLINK+='myusbstick'"

# Unmount UFS card when removed.
ACTION=="remove", KERNEL=="sd[a-z][0-9]", SUBSYSTEM=="block", RUN{program}+="/usr/bin/systemd-umount /media/%E{ID_FS_UUID}, SYMLINK-='myusbstick'"

(I’m not sure yet about remove, but see what happens…you might need to manually “sudo rm /media/myusbstick” between tests, but it should use normal rules and then add symbolic link “/media/myusbstick” pointing at the UUID naming)

EDIT: The main flaw in this is that it would use “myusbstick” on every “/dev/sda#” and every “/dev/sdb#”. If you have multiple devices of the sda prefix, then all would attempt to use the same symbolic link. Each would still properly mount on its UUID location.