LibreELEC entware installation (opkg / optware)
Author Artem Butusov · Published on May 26th, 2017
Contents
Why?
LibreELEC is perfect linux distro for running Kodi almost everywhere.
LibreELEC has a powerful add-on system and it also has docker container support so technically you could run everything you need inside docker container.
But sometimes it is not enough. All (or almost all) Linux distros have their own package manager with set of well known packages (prebuilt binaries or scripts to build from source code).
Well, LibreELEC has its own build system and you could use it to add support for other packages but in that case you will have to rebuild almost whole LibreELEC.
Building customized version of LibreELEC could be overkill if you just need to install something like Midnight Commander or cron, right?
Here is one possible solution - use entware: https://github.com/Entware/Entware
entware is an tiny and minimalistic user-space prefix (/opt) environment designed for embedded systems with tiny package manager.
There are other optware-like alternatives, but I found that entware is supported better than others.
Alternatives:
- optware / optware-ng: http://www.nslu2-linux.org/wiki/pmwiki.php?pagename=Optware/HomePage/
- entware-ng: no more an option, merged with entware
- entware-ng-3.x: no more an option, merged with entware
Fix LibreELEC image
To be able to easy work with entware we will need folder in root /opt. LibreELEC uses read only root filesystem so we will have to fix system image.
My LibreELEC is installed on SD card and I also have OS X on my laptop.
Prerequisites:
- OS X (but it could be Linux too but instruction how to install squashfs is different)
- Homebrew package manager installed: https://brew.sh
- In terminal:
brew install squashfs
Actions:
- Disconnect SD card
- Connect SD card to OS X
- Connected volume should have label “LIBREELEC”
- Open terminal
cd /Volumes/LIBREELEC
mkdir -p new/opt
mksquashfs new SYSTEM -all-root
rm -rf new
- Thats it, now SYSTEM image should have /opt directory and you could connect SD card back to your media player
- You will need to do this step each time you will update LibreELEC system image.
Connect to LibreELEC over SSH
Enable SSH access in LibreELEC configuration or during setup. Remember hostname, by default, it is LibreELEC.
Run from terminal: ssh root@LibreELEC.local (or CustomHostname.local)
Install entware
Root filesystem is still unreadable, but /storage has read-write access, so we could install entware into, for example, /storage/opt and bind /opt to /storage/opt (thats why we created /opt in the root).
You could find correct install script url here: https://github.com/Entware/Entware/wiki/Alternative-install-vs-standard. In my case I will use AARCH64 standard install script (for ODROID-C2).
Install opkg:
mkdir -p /storage/opt
mount -o bind /storage/opt /opt
wget -O - http://bin.entware.net/aarch64-k3.10/installer/generic.sh | sh
export PATH=$PATH:/opt/bin:/opt/sbin
opkg update
# expr is used in opkg init scripts and is not available in busybox provided by LibreELEC
opkg install coreutils-expr
Make /opt bind persistent:
Run: nano -w /storage/.config/system.d/opt.mount
Please note, filename opt.mount make sense here (systemd rule): /{name} -> {name}.mount.
[Unit]
DefaultDependencies=no
Conflicts=umount.target
Before=local-fs.target umount.target
[Mount]
What=/storage/opt
Where=/opt
Type=none
Options=bind
[Install]
WantedBy=local-fs.target
Enable mount point to be activated on reboot:
systemctl enable opt.mount
Fix profile to have entware available in SSH session by default and enable unicode:
Run: nano /storage/.profile
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export PATH=$PATH:/opt/bin:/opt/sbin
Now you could reboot LibreELEC and test if changes are persistent. After reboot you should be able to:
- connect to LibreELEC over SSH
- see that
/optis mounted.ls /optshould show files (test for /opt bind) opkg listshould show list of available packages (test for PATH in profile)
Enable SSH with certificate
Run on local machine:
nano ~/.ssh/config
Paste configuration to use alternative username when you are connecting to LibreELEC (we assume default hostname here):
Host libreelec.local
User root
Run on local machine:
cat ~/.ssh/*.pub
Login to libreelec thru ssh:
ssh root@libreelec.local
Copy the open key you would like to use.
nano -w ~/.ssh/authorized_keys
Paste the open key.
Save.
Exit SSH session and try to login again:
ssh libreelec.local
This time it should not ask for password.
Usage
Now you could install packages available in entware with opkg package manager.
opkg listwill show list of available packages.opkg list | grep packagewill help you to find needed package.opkg install packagewill install package- some packages are designed to be daemonized, for example cron.
- init scripts are located here: /opt/etc/init.d
- you could start service with /opt/etc/init.d/SXX{name} start
- you could stop service with /opt/etc/init.d/SXX{name} stop
- services should be also wrapped into systemd config files to persist their state on reboot
opkg uninstall packagewill uninstall package
Examples
midnight commander (application)
Install mc: opkg install mc
Thats it :-)
cron (service)
Install cron: opkg install cron
Wrap service into systemd config: nano -w /storage/.config/system.d/cron.service
[Unit]
Requires=network-online.service
[Service]
Type=oneshot
ExecStart=/opt/etc/init.d/S10cron start
ExecStop=/opt/etc/init.d/S10cron stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Auto start service on reboot: systemctl enable cron.service
Start service now: systemctl start cron.service
This is a perfect example how easy could be to install binary package with entware.
dnsmasq (service)
Below is example how to setup dnsmasq with ads blacklist.
Download ads domains blacklist in hosts file format:
cd /opt/etc && wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
Install dnsmasq: opkg install dnsmasq-full
Run: nano -w /opt/etc/dnsmasq.conf
server=8.8.8.8
server=8.8.4.4
addn-hosts=/opt/etc/hosts
Wrap service into systemd config: nano -w /storage/.config/system.d/dnsmasq.service
[Unit]
Requires=network-online.service
[Service]
Type=oneshot
ExecStart=/opt/etc/init.d/S56dnsmasq start
ExecStop=/opt/etc/init.d/S56dnsmasq stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Auto start service on reboot: systemctl enable dnsmasq.service
Start service now: systemctl start dnsmasq.service
Now you could set for any device at home main DNS server address to LibreELEC ip address and all (almost) ads will be removed.
Another perfect example how easy is entware.
vsftpd (service)
By default, LibreELEC has no ftp support but ftp could be useful for some iOS/Android apps with bad samba support, VLC, for example.
Here we could setup guest read-only ftp with a few commands:
Install vsftpd: opkg install vsftpd-ext
Run: nano -w /opt/etc/vsftpd/vsftpd.conf
# defaults - everything else could be disabled
anonymous_enable=YES
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
listen=YES
# overrides
anonymous_enable=YES
local_enable=NO
anon_root=/media
no_anon_password=YES
hide_ids=YES
pasv_min_port=40000
pasv_max_port=50000
ftp_username=nobody
This config will make vsftpd share all mounted devices.
Wrap service into systemd config: nano -w /storage/.config/system.d/vsftpd.service
[Unit]
Requires=network-online.service
After=network-online.service
[Service]
Type=oneshot
ExecStart=/opt/etc/init.d/S49vsftpd start
ExecStop=/opt/etc/init.d/S49vsftpd stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Auto start service on reboot: systemctl enable vsftpd.service
Start service now: systemctl start vsftpd.service