Skip to main content

Adding a torrent client to a router with OpenWrt

Contents

So you want to add a torrent client to your OpenWrt router, so that you can download, for example, a Raspbian image using this method, save it to a previously connected and configured USB drive and access it from the local network?

Nothing simpler. For this purpose we will use Transmission.

Transmission Installation and Configuration

You can install it from the administration panel via a web browser (System > Software) or from the terminal:

opkg update
opkg install transmission-daemon transmission-web luci-app-transmission

The luci-app-transmission application will allow us to customize additional options from a web browser without the need to edit files from the terminal.

The transmission-daemon-openssl package is a program that will run in the background of our router, and transmission-web is a separate access to our program from a web browser to add or remove a downloaded file.

Let’s start by configuring the settings.

We go to our router’s control panel, then Services > Transmission.

OpenWrt > Services > Transmission

Before we mark the configuration as enabled (Enabled), let’s go through a few settings. The most important of them is where our files are to be saved.

In the Files and Locations section we enter the folder locations in Downloads locations. In my case it is on a USB drive mounted as /mnt/sda1. Additionally, I have enabled saving in-progress (incomplete) files in a separate folder (check Incomplete directory enabled).

In the Miscellaneous settings I changed the encryption from Preferred and Forced.

I also set up a blacklist (Blocklist) by selecting level1 or Bluetack from iBlocklist.

The rest I leave to your discretion.

Let’s check the Enable option at the beginning of the settings and click Save & Apply.


If your luci-app-transmission application returns information about missing Run daemon as user and Run daemon as group fields, which makes it impossible to save the settings, as shown below, you need to use terminal to fix it.

luci-app-transmission 21.02 non-empty value

sed -i '/"file": {/a\\t\t\t\t"/etc/passwd": [ "read" ],\n\t\t\t\t"/etc/group": [ "read" ],' /usr/share/rpcd/acl.d/luci-app-transmission.json
service rpcd restart

Transmission Startup

Unfortunately, at the moment, even though luci-app-transmission has the Enabled option set and should start transmission-daemon by default, it does not.

To run our program, from the terminal we put the command:

/etc/init.d/transmission start

Then we go to the transmission panel, by default http://192.168.1.1:9021/transmission/web/ where we add our torrent.

Transmission downloading raspbian buster full

To stop Transmission we can kill the process from the router administration panel System > Processes or from the terminal:

/etc/init.d/transmission stop

If you have any problems getting it to work, I recommend running the logread command from the terminal to analyze the errors.

If we want to manually change the settings in the file from the terminal, after stopping the daemon just edit /etc/config/transmission. Sometimes it can be necessary if we mess up the settings too much.

In the Config file directory section from the browser, or option config_dir in the configuration file, I recommend changing /tmp/transmission to /root/transmission. This will save the transmission daemon’s working folder in a permanent location, not a temporary one. This is important for the Blocklist file, which will remain on the router after it is restarted.

OpenWrt 22.03+ (23.05, 24.10) problem

As with any update, sometimes something breaks or stops working in the system.

Transmission versions 3.00 (OpenWrt 22.03) and 4.00 (OpenWrt 23.05) use something like procd_ujail and seccomp in their startup script. Without going into detail about what these packages are useful for, I’ll just focus on the fact that they cause a problem with Transmission (Issue #19376).

Open the configuration file does not save correctly. When saving files, an error related to lack of disk space is displayed or the torrent does not pass the final verification after downloading. In a word, a mess.

To fix this problem, you can remove the procd_ujail and procd_seccomp packages, however this is not always a good solution, as other packages on the system may require them to work, so they may be installed inadvertently or uninstallation (opkg remove ...) may fail.

Another solution, unfortunately also short term, is to modify the transmission start script. Fortunately (or not), transmission is not updated that often, so this solution may become a kind of long term solution.

First we need to stop the transmission.

/etc/init.d/transmission stop

Then we start editing the initialization file. For this purpose I use nano but you can also use the built-in vim.

nano /etc/init.d/transmission

Scroll down the file until you see the secomp_path and procd_add_jail sections, then comment (#) the appropriate lines as shown below.

OpenWrt 22.03, Transmission 3.0

#       seccomp_path="/etc/seccomp/transmission-daemon.json"
#       if [ -f "$seccomp_path" ]; then
#               procd_set_param seccomp "$seccomp_path"
#       fi

        if [ -z "$USE" ]; then
                procd_set_param limits core="0 0"
        else
                procd_set_param limits core="0 0" as="$USE $USE"
                logger -t transmission "Starting with $USE virt mem"
        fi

        [ -d "$web_home" ] && procd_set_param env TRANSMISSION_WEB_HOME="$web_home"
        [ "$ca_bundle" -gt 0 ] && procd_set_param env CURL_CA_BUNDLE="$ca_bundle_file"

#       procd_add_jail transmission log
#       procd_add_jail_mount "$config_file"
#       procd_add_jail_mount_rw "$config_dir/resume"
#       procd_add_jail_mount_rw "$config_dir/torrents"
#       procd_add_jail_mount_rw "$config_dir/blocklists"
#       procd_add_jail_mount_rw "$config_dir/stats.json"
#       procd_add_jail_mount_rw "$download_dir"
        web_home="${web_home:-/usr/share/transmission/web}"
#       [ -d "$web_home" ] && procd_add_jail_mount "$web_home"
#       [ -f "$ca_bundle_file" ] && procd_add_jail_mount "$ca_bundle_file"
        procd_close_instance
}

OpenWrt 23.05+ (24.10), Transmission 4.00

#       seccomp_path="/etc/seccomp/transmission-daemon.json"
#       if [ -f "$seccomp_path" ]; then
#               procd_set_param seccomp "$seccomp_path"
#       fi

        if [ -z "$USE" ]; then
                procd_set_param limits core="0 0"
        else
                procd_set_param limits core="0 0" as="$USE $USE"
                logger -t transmission "Starting with $USE virt mem"
        fi

        [ -d "$web_home" ] && procd_append_param env TRANSMISSION_WEB_HOME="$web_home"
        [ "$ca_bundle" -gt 0 ] && procd_append_param env CURL_CA_BUNDLE="$ca_bundle_file"

#       procd_add_jail transmission log
#       procd_add_jail_mount "$config_file"
#       procd_add_jail_mount_rw "$config_dir/resume"
#       procd_add_jail_mount_rw "$config_dir/torrents"
#       procd_add_jail_mount_rw "$config_dir/blocklists"
#       procd_add_jail_mount_rw "$config_dir/stats.json"
#       procd_add_jail_mount_rw "$download_dir"
#       [ "$incomplete_dir_enabled" = "1" ] && procd_add_jail_mount_rw "$incomplete_dir"
#       [ "$watch_dir_enabled" = "1" ] && procd_add_jail_mount_rw "$watch_dir"
        web_home="${web_home:-/usr/share/transmission/public_html}"
#       [ -d "$web_home" ] && procd_add_jail_mount "$web_home"
#       [ -f "$ca_bundle_file" ] && procd_add_jail_mount "$ca_bundle_file"
        procd_close_instance
}

Make sure to comment out both seccomp and jail, because leaving seccomp will cause our transmission daemon to hang constantly.

We save our file and run transmission again.

/etc/init.d/transmission start

This way transmission will work correctly in OpenWrt series 22.03 and 23.05.

Regards.

Share on Threads
Share on Bluesky
Share on Linkedin
Share via WhatsApp
Share via Email

Comments & Reactions

Categories