What's new

Cannot open TUN/TAP dev error

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Stephen Becker

Occasional Visitor
Short question: what is the best script to run the modprobe tun command to ensure tun devices are setup after reboot? It does not appear to work correctly when included in services-start

Long version with background:
I am using fastd to setup an IP tunnel to another Asus-Merlin router, but ran into an issue where the service does not start correctly after a reboot. The error says "could not open TUN/TAP device file: No such file or directory"

The command modprobe tun creates /dev/tun and /dev/net/tun allowing the service to start, however, only when I run the command manually. I have tried adding that command to /jffs/scripts/services-start before Entware is called, but it does not work. It creates /dev/tun but not /dev/net/tun.

I suspect either a kernel mod has not yet loaded, or the firmware does something shortly after boot that resets network devices.

Any advice on how to fix this? I could probably have the script sleep an arbitrary amount of time before running modprobe and starting Entware, but I would like a more graceful solution. Also not entirely sure if the services-start script blocks anything else on the router that may make sleeping just postpone the same issue.
 
Here is a services-start script I got working. It did not work until I added those longer sleeps. For some reason with a simple 1 second sleep it was testing positive for the mod loading, but then the mod would unload again. Probably something the firmware was doing at the same time.


Code:
#!/bin/sh

RC='/opt/etc/init.d/rc.unslung'
sleep 30

i=12
until [ "$(lsmod | grep tun)" ] ; do
  i=$(($i-1))
  if [ "$i" -lt 1 ] ; then
    logger "Could not load tun mod"
    break
  fi
  modprobe tun
  sleep 10
done

i=30
until [ -x "$RC" ] ; do
  i=$(($i-1))
  if [ "$i" -lt 1 ] ; then
    logger "Could not start Entware"
    exit
  fi
  sleep 1
done

$RC start
 
Last edited:

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top