Kodi in LXC containers

lxc

(Test) #1

Hi guys!

I am using LXC for several things and I would like to install kodi on it. The problem is that I can not send image or audio from the containter to the HDMI and also I can not use the GPU acceleration.
Any one can help me with this issue?

I have been googling for long time and I had not find any correct way to do that.

Thanks a million for your help


#2

Have you tried this?

It comes up among the first when you google for “lxd”, “graphics”, “gui”, “gpu”.


(Test) #3

Hi Simos,

Yes. I tried it but I got stuck here:

$ lxc config set guiapps raw.idmap “both $UID 1000”

This is what I tried:

test@raspberrypi:~ $ lxc config set guiapps raw.idmap “both $UID 1000”
-bash: lxc: command not found
test@raspberrypi:~ $ lxc-config
Usage: lxc-config -l: list all available configuration items
lxc-config item: print configuration item
test@raspberrypi:~ $ lxc-config -l
lxc.default_config
lxc.lxcpath
lxc.bdev.lvm.vg
lxc.bdev.lvm.thin_pool
lxc.bdev.zfs.root

Thanks a million for your response.


#4

I guess you are using the stock version of LXD that comes with your image.
Try

lxc --version

It should say something like 2.18, which is a version with IDMAP and other required features.


(Test) #5

Hi,

This is the result:

test@raspberrypi:~ $ lxc --version
-bash: lxc: command not found

I have found this. I hope it helps.

test@raspberrypi:~ $ lxc-cgroup --version
1.0.6

I installed lxc doing apt-get install lxc from my raspberry pi 2b running Raspbian:

test@raspberrypi:~ $ uname -a
Linux raspberrypi 4.9.35-v7+ #1014 SMP Fri Jun 30 14:47:43 BST 2017 armv7l GNU/Linux

Thanks.


(Idef1x) #6

Please note that the guide to get it working is with lxd, wich is different than lxc


#7

Indeed, that appears to be the issue.

@test_mess: You are using LXC 1, while the guide I gave you is for LXD (an easier and improved version of LXC 1).
Unless you have a very specific reason to use LXC 1, I suggest to use LXD instead.


(Test) #8

Hi,
I will try to convert my lxc to lxd and then try to follow the manual. I hope I can convert it without lose anything.

Thanks for the help.


(Deshi) #9

Hi test_mess,

I know this thread is a little old but I need your help.
I’m trying to create a lxd container for kodi on my server ubuntu 14.04 LTS.

I can’t use docker because I initially install the server with en 32bit install.

Can you share how you build the kodi image for lxd ?

Thanks


#10

Are you trying to install Kodi as a media server on Ubuntu 14.04 (trusty)?

If so, there are 32-bit packages for Kodi at the PPA at http://ppa.launchpad.net/team-xbmc/ppa/ubuntu/pool/main/k/kodi/
and you can therefore install using the official instructions at https://kodi.wiki/view/HOW-TO:Install_Kodi_for_Linux

Is this for use at your own network? If it is your own network, you can configure the LXD container to get an IP from your router so that the container is readily accessible at the local network.
There are two ways to do this, see what works for Ubuntu 14.04
https://blog.simos.info/how-to-make-your-lxd-container-get-ip-addresses-from-your-lan/
https://blog.simos.info/how-to-make-your-lxd-containers-get-ip-addresses-from-your-lan-using-a-bridge/

If it is not your own network, then you would need to open up ports to make the Kodi LXD container accessible to the network.


(Deshi) #11

Hi simos, thanks for the quick reply.

I want an instance of kodi on my server just for the possibility to update libraries from the server, I already have mysql databases on the server.
I want the clients (rpi), at home, when they start to have acces not only to the common databases but to “updated” databases. Updates loclally are way too long.

The ideal for me would be to have some sort of kodi running on the server, with updates setup in a cron or with a command from ssh.


#12

In that respect, just install in a LXD container the latest Kodi from the PPA as the official instructions say.
Then, you would need to figure out which network ports Kodi is using, so that you can add iptables rules and get connectivity to the Kodi container.

Here is the iptables command. Set three parameters, and then change the $PORT to each port that needs to be opened.

PORT=80 SERVER_IP=your_server_ip CONTAINER_IP=your_container_ip INTERFACE=your_server_network_interface sudo -E bash -c 'iptables -t nat -I PREROUTING -i $INTERFACE -p TCP -d $SERVER_IP --dport $PORT -j DNAT --to-destination $CONTAINER_IP:$PORT -m comment --comment "forward to network port"'

Replace

  • PORT: the network port. In the example it shows port 80 (www).
  • SERVER_IP: the server’s IP address.
  • CONTAINER_IP: the container’s IP address (use lxc list to find it).
  • INTERFACE: the server network interface. Probably eth0 or something similar.

(Deshi) #13

Ok simos, I think I get most of this…

So, after install and init of lxd, the container I have to build is an OS actually :
lxc launch ubuntu:16.04 MyFirstLXD
lxc exec MyFirstLXD – apt-get install kodi

Then edit iptables like you showed, then run kodi
lxc exec MyFirstLXD – run kodi
and feed it with commands
lxc exec MyFirstLXD – xbmc-send --action ‘UpdateLibrary(video)’

Am I getting it right ?
Sorry if all that sounds stupid but I’m recreational Linuxian


#14

Overall looks good. Here are more detailed instructions.

Launch the container.

$ lxc launch ubuntu:16.04 MyKodiContainer
Creating MyKodiContainer
Starting MyKodiContainer   

Follow the instructions at https://kodi.wiki/view/HOW-TO:Install_Kodi_for_Linux#Installing_Kodi_on_Ubuntu-based_distributions (they say not to install the kodi from the Ubuntu repositories because it is an old version). We add the Kodi PPA, then perform a package index update so that Ubuntu knows the additional packages from the new Kodi PPA. Finally, we install the new Kodi.

$ lxc exec MyKodiContainer -- add-apt-repository ppa:team-xbmc/ppa
$ lxc exec MyKodiContainer -- apt update
$ lxc exec MyKodiContainer -- apt install kodi

Now, Kodi is installed in an LXD container on the server.

Then, Kodi needs two ports, port 8080 TCP and port 9777 UDP. The iptables commands are:

PORT=8080 PROTO=tcp SERVER_IP=your_server_ip CONTAINER_IP=your_container_ip INTERFACE=your_server_network_interface sudo -E bash -c 'iptables -t nat -I PREROUTING -i $INTERFACE -p $PROTO -d $SERVER_IP --dport $PORT -j DNAT --to-destination $CONTAINER_IP:$PORT -m comment --comment "forward to Kodi network port 8080 TCP"'

PORT=9777 PROTO=udp SERVER_IP=your_server_ip CONTAINER_IP=your_container_ip INTERFACE=your_server_network_interface sudo -E bash -c 'iptables -t nat -I PREROUTING -i $INTERFACE -p $PROTO -d $SERVER_IP --dport $PORT -j DNAT --to-destination $CONTAINER_IP:$PORT -m comment --comment "forward to Kodi network port 8080 TCP"'

Now, you can run Kodi in a way that does not start the GUI. I am not familiar with that process.
If you can provide me with some instructions (find a website that shows the commands), I can continue with the rest.

The command to run Kodi would look like this. Compare with the command you gave earlier.

$ lxc exec MyKodiContainer -- sudo --user ubuntu --login  kodi --standalone

You would need to do some Kodi configuration first. I do not know whether kodi --standalone is the proper way to run Kodi on a server. If you want to run any other Kodi command, just prepend the first part lxc exec MyKodiContainer -- sudo --user ubuntu --login

If you can find the rest of the steps to get Kodi working on a server, I am happy to write a complete guide.


(Deshi) #15

Wahoo simos thanks a lot that helps !!!

My starting point for trying to pull this off was these links regarding a headless kodi (first in french just for reference lol)
https://forum.mpdb.tv/index.php/topic,31096.0.html
https://hub.docker.com/r/celedhrim/kodi-server/
https://github.com/Celedhrim/docker-kodi-server

I even tried the part about building the container myself but it didn’t work, I think for 2 reasons

  1. the version of docker for 32bit is too old
  2. the image Celedhrim based it on might be 64bit

You are right about the configuration of kodi, in the docker guide you have to create a profile that kodi will use, which I’ve already done, but at some time you’ll have to tell the container where to look for it.

I think that in order to update the libraries (Video and Music) kodi needs at least to know

  1. what the sources to use (their paths)
  2. what type of info to put in it (what scraper to use)
  3. and the location of the mysql databases

Thanks again


#16

I had a closer look to all this, and especially the docker-headless repository.

What I found is that Kodi does not come officially with a --headless parameter.
The docker-headless script adds a patch for a --headless parameter and then compiles from scratch all of Kodi. There must be some background as to why Kodi does not include this elemental patch for a --headless parameter.

Here are a few ways forward.

  1. Adapt the docker-headless script to apply the patch and recompile Kodi from source in order to have a --headless parameter. This would work fine, and it would be the solution if the two following are not viable.
  2. Set up X2Go on the server so that Kodi runs with a GUI. Then, you can configure Kodi through the GUI. Note that there will be no graphics acceleration, therefore you would only be able to use the menus, not play videos. There is a pending guide on X2Go that should come out shortly (@bmullan, would Kodi work with X2Go?)
  3. Create a snap package of Kodi, one that has the --headless option built-in. There is already a beta package for Kodi, and can be installed according to the instructions at http://www.omgubuntu.co.uk/2017/05/kodi-popular-media-center-now-available-snap-app Using the same snap configuration, it would be easy to generate a variant that has the --headless patch (snapcraft.yaml).

I think the snap package (option 3) would be the easier to do. It would require to take the snapcraft.yaml, remove anything that is graphics related, add the patch for --headless and that’s it. See https://forum.snapcraft.io/t/kodi-snap-call-for-testing/838/11 for more on this.


(Deshi) #17

And… now you lost me… lol

I’ll look at the snap option. Apparently I’ll first need

  1. to upgrade my server to 16.04
  2. check if there is a stable version, because “–edge” install kodi 18. It’s not stable yet and I’ll probably have database versions problems
  3. find that “headless patch”
  4. figure out that snapcraft.yaml
  5. then build a snap package with 3. and 4. into it.

That might be fun, see you in a week ! lol

P.S : stupid question of the year : Wouldn’t it be easier to find a way to “migrate” my OS to 64bit and use docker from the beginning ?


#18

I asked at https://forum.snapcraft.io/t/kodi-snap-call-for-testing/838/17?u=simos if there is anyone that can help with creating a snap for kodi-headless. Should be easy to do, and once done, it would be much better than using Docker.

If you can migrate to 64-bit, docker/kodi-headless is also an option. Though, it would require to reinstall all from scratch.


(Deshi) #19

Ok then, it would be nice indeed if someone from snapcraft could help.

To be honnest I’m kind of scared to reinstall everything with a 64bit OS, mostly because of the raid5 I have with mdadm etc…

The real question is why didn’t I use 64bit from the start in 2012 when I built the server…

The forum is blocked from where I am now but I’ll check it in the evening.

Thanks again


(Deshi) #20

Hi simos,

I’m still not able to deal with this on my own, I was wondering if you had any news from the snapcraft crew ?