Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB storage automount #8

Open
kevinmehall opened this issue Apr 9, 2015 · 1 comment
Open

USB storage automount #8

kevinmehall opened this issue Apr 9, 2015 · 1 comment

Comments

@kevinmehall
Copy link
Member

http://wiki.openwrt.org/doc/techref/block_mount
http://wiki.openwrt.org/doc/uci/fstab

@johnnyman727
Copy link
Contributor

So I've been thinking about how we might want to standardize the target of the mounting. The easiest thing would be to let OpenWRT use the default automounting behavior but that would get confusing between /mnt/sda1 and /mnt/sdb1.

Imagine a user first plugs in a storage device in the bottom USB port. The hotplug loading would mount it on /mnt/sda1. Then the user plugs in another flash drive in the top usb port - this device would be mounted at /mnt/sdb1. As soon as the user reboots the Tessel, suddenly the top USB device is mounted at /mnt/sda1 and the bottom is at /mnt/sdb1 because OpenWRT auto mounts the top USB port first! Admittedly, the chance that someone will plug in two flash drives AND they plug in the first one on the bottom is not likely but it seems like we should avoid this scenario if possible.

I think the better route would be to set up rules to mount the device at /mnt/DEVICE_NAME. The user can use an OS to give a name to their flash drive and know that it will always be loaded at /mnt/DEVICE_NAME. If they have two flash drives with the same label, we can either override the first one or mount it at /mnt/DEVICE_NAME_1. The biggest problem here is that some devices don't have a name (actually called LABEL when running block info) at all...

So here are the options as I see it:

  1. Mount to /mnt/DEVICE_NAME
  2. Determine (somehow?) which USB port it's plugged into and mount to /mnt/usb_1 and /mnt/usb_2 (this actually might be best if it's not too ugly to implement)
  3. Let the system autoload to /mnt/sda1 and /mnt/sdb1 as described above

Below is the implementation information I've gleaned from reading the pages Kevin linked to:

There are separate processes for mounting a USB device on boot and on hotplug.

Mounting on hotplug

  1. Add a mounting-related dependency to the openWRT build: block-mount
  2. Add a script in /etc/hotplug.d/mount that will detect the label of the plugged in device add an entry to/etc/config/fstab` using UCI.

Mounting on boot

  1. Make sure fstab is enabled: /etc/init.d/fstab enable
  2. We need to edit /etc/config/fstab to automount:
config 'global' 'automount'
        option 'anon_mount' '1'

The problems I'm facing now is that I can't think of an elegant way to load a block device to /mnt/LABEL_NAME if it's plugged in on boot. I don't think you can have variables in /etc/config/fstab. It would be nice if you could do something like:

sda_label = $(mount list | some_way_to_find_sda_label)
sdb_label = $(mount list | some_way_to_find_sdb_label)

config 'mount'
        option 'target'   '/mnt' + $(sda_label)
        option 'device'   '/dev/sda1'
        option 'options'  'rw,sync'
        option 'enabled'  '1'
        option 'enabled_fsck' '1'

config 'mount'
        option 'target'   '/mnt' + $(sdb_label)
        option 'device'   '/dev/sdb1'
        option 'options'  'rw,sync'
        option 'enabled'  '1'
        option 'enabled_fsck' '1'

Another option is to just create a separate init.d script that uses block mount to determine if any flash devices are plugged in and use uci to create fstab entries. This is easier for me just because I know how to write shell scripts - I'm less familiar with making dynamic fstab files (or if it's even possible).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants