Skip to content

Instantly share code, notes, and snippets.

@hobbsAU
Last active October 29, 2016 17:03
Show Gist options
  • Save hobbsAU/80515fd1b177acc19aa6 to your computer and use it in GitHub Desktop.
Save hobbsAU/80515fd1b177acc19aa6 to your computer and use it in GitHub Desktop.
OpenElec systemd-nspawn Container

Description

OpenELEC runs Kodi, an award-winning free and open source (GPL) software media player and entertainment hub for digital media. For more info see http://kodi.tv . The base system has been designed and built from the ground up to be as efficient as possible – consuming only tiny disk and memory footprints and providing cutting edge hardware support to deliver a set-top box experience.

In order to run software above the base OpenELEC distribution with minimal impact to the OpenELEC base, one alternative is to use a container.

I have chosen to use systemd-nspawn instead of chroot. There are really no downsides as long as you can configure the required kernel config options and have a basic working knowledge of systemd.

Installation

File Locations

  • MyContainer.service as .config/system.d/MyContainer.service

Configuration

  1. Create MyContainer.service and adapt to your needs. At least check the following settings:

    • --link-journal=host
    • --directory=/var/lib/container/MyContainer
  2. Create a link to the container by executing the following command:

    ln -s /storage/data/MyContainer /var/lib/container/
  3. I am going to use the Debian Jessie 8.1 minimal release as a base container platform. Create the container on an alternate host running Linux with debootstrap installed:

    sudo debootstrap --arch=amd64 stable  ./MyContainer/
    sudo tar -czf MyContainer.tar.gz ./MyContainer
  4. Copy and deploy the container to the OpenELEC host:

    cd /storage/data/
    tar -xzf MyContainer.tar.gz
    rm MyContainer.tar.gz
  5. Add and enable the container at boot

systemctl enable MyContainer.service
  1. Check, start, check and stop the container
/usr/bin/systemd-nspawn  --keep-unit --boot --link-journal=host --directory=/var/lib/container/MyContainer
Ctrl-] (Press ^] three times within 1s to kill container.)
systemctl start MyContainer
systemctl show MyContainer
systemctl stop MyContainer
  1. You should now have a working container. Time to login and setup the Debian minimal distribution. First I will perform a system update, followed by installing some key applications and also changing the root password.

Note: if you wish to change mirror please edit the /etc/apt/sources.list from within the container.

/usr/bin/systemd-nspawn --keep-unit --boot --link-journal=host --directory=/var/lib/container/MyContainer
apt-get update
apt-get dist-upgrade
apt-get install ssh openssh-server sudo
passwd root
sed -i 's/Port 22/Port 2222/g' /etc/ssh/sshd_config
dpkg-reconfigure tzdata
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
[Unit]
Description=Container MyContainer
Documentation=man:systemd-nspawn(1)
[Service]
ExecStart=/usr/bin/systemd-nspawn --quiet --keep-unit --boot --link-journal=host --directory=/var/lib/container/MyContainer
KillMode=mixed
Type=notify
RestartForceExitStatus=133
SuccessExitStatus=133
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment