HOW TO - Using LTSP to PXE boot media centers.
#1
If this is acceptable I’d like to get this post into the tips tricks and how-tos. Thank you much for reading.

This write up is intended to share my method of using PXE booting for multiple media centers around my home. I utilize the LTSP software. Their page is located here. https://ltsp.org/

This guide is written for Ubuntu 18.04. Some changes are being made in Ubuntu 20.04 with how LTSP works. When I begin to migrate my systems I intend to update this guide as needed.

This guide is for specifics to LTSP & Kodi. Setting up MariaDB / Mysql, Isc-Dhcp-Server, and an NFS server can be found easily via google or your favorite search engine.

Requirements:
File server or NAS capable of NFS sharing
Local MariaDB or Mysql server
Local DHCP server (I use isc-dhcp-server. I don’t find dnsmasq to offer what I need)
Ubuntu server 18.04 server to host the pxe boot environment (all of the above can be hosted on the same machine or separately)
Clients that are capable of pxe boot
Wired networking (gigabit preferred)

LXD NOTE:
If creating this ltsp server inside of an LXD container you will need to make appropriate changes to the container configuration. On the host the following changes will be required to make the container work for LTSP.
Code:
lxc config set $CONTAINER security.privileged true
lxc config set $CONTAINER security.nesting true

You will need a static ip in the container for this to work. I do it via netplan inside the container. Make sure this is outside your dhcp range on your dhcp server. Netplan config as follows. Adjust as needed to your environment. This is just mine copied straight to this guide. This requires a bridge on the server. Not a bridge specific to lxd. When running your lxd init you should decline the first option of bridge and connect to existing bridge for this to work.
First part is my netplan config for my server. 2nd part is netplan config inside the container.
Code:
network:
 version: 2
 renderer: networkd
 ethernets:
  enp2s0:
   dhcp4: false
   dhcp6: false
 bridges:
  br0:
   interfaces: [enp2s0]
   dhcp4: false
   dhcp6: false
   addresses: [192.168.1.2/24]
   gateway4: 192.168.1.1
   nameservers:
    addresses: [192.168.1.246]
Code:
network:
 version: 2
 renderer: networkd
 ethernets:
  eth0:
   dhcp4: false
   dhcp6: false
   addresses: [192.168.1.240/24]
   gateway4: 192.168.1.1
   nameservers:
    addresses: [192.168.1.246]

You will need to configure your locales and tzdata when in an LXD container as well.
Code:
dpkg-reconfigure tzdata
dpkg-reconfigure locales

Is helpful to install ssh inside the container so you can manage it directly.
Code:
apt install ssh

Configure as needed.

USERS:

Option 1:
If you need to add a regular user for ssh with sudo access to the container now is the time. You will most likely need to enable password authentication yes inside of etc/ssh/sshd_config. For my usage I have both a sudo user and root ssh access to the container as I run my upgrades on my containers all at once via a script in a loop. Adjust to enable what you need, set a root password if needed as well for root.
Option 2:
I use NIS in my home. Now is the time to configure that as well if you don’t intend to have a user specific to that container.

Restart the container to make sure everything is proper and good to go.

END LXD NOTE

Installing LTSP & Configuring :
On your Ubuntu 18.04 server add the greek schools ppa
Code:
add-apt-repository ppa:ts.sch.gr

Install the package ltsp-server along with a tftp server
Code:
apt install ltsp-server tftpd-hpa

Creation of the chroot can now begin. Run as root or with sudo through SSH so your environmental variables are set . Take note of the –chroot option. You can name your chroots. They are not required to be amd64 or i386. This allows a single server to serve as many images as necessary. Name what you wish. I named this one ltspmedia.
Code:
ltsp-build-client \
--purge-chroot \
--chroot ltspmedia \
--mount-package-cache \
--extra-mirror 'http://ppa.launchpad.net/ts.sch.gr/ppa/ubuntu bionic main' \
--apt-keys '/etc/apt/trusted.gpg.d/ts_sch_gr_ubuntu_ppa.gpg'

NOTE:

If this fails for something about improper variables then a step above was missed. Particularly the locales.

END NOTE

At this point the very first thing you need to do is make a couple changes to the chroot to ensure it pxe boots properly.

From the ltsp server host. Use your favorite text editor. I’m lazy and use nano.
Code:
sudo nano /opt/ltsp/ltspmedia/etc/ltsp/update-kernels.conf

Adjust the following lines.

Change
Code:
CMDLINE_LINUX_DEFAULT="init=/sbin/init-ltsp forcepae”

to
Code:
CMDLINE_LINUX_DEFAULT="init=/sbin/init-ltsp forcepae apm=off”

Also at the bottom of the file. Change
Code:
#IPAPPEND=2

to
Code:
IPAPPEND=2

NOTE:
The IPAPPEND change is for isc-dhcp-server. I haven’t a clue how dnsmasq works so that would need to be researched elsewhere.

END NOTE

Now run the following command.
Code:
sudo chroot /opt/ltsp/ltspmedia /usr/share/ltsp/update-kernels

Should see something about updating yaboot images.

Now your image is ready for actual configuration and usage.
Mount the appropriate folders for working within a chroot.
Code:
for folder in sys proc dev ; do
  sudo mount –bind /”$folder” /opt/ltsp/ltspmedia/”$folder”
done
Code:
sudo chroot /opt/ltsp/ltspmedia

Upon entering your chroot get your locales and tzdata done.
Code:
dpkg-reconfigure tzdata
dpkg-reconfigure locales

Install software necessary for Kodi into the chroot.
Code:
apt install software-properties-common
Code:
add-apt-repository ppa:team-xbmc/ppa
Code:
apt install kodi kodi-eventclients-kodi-send openbox ssh x11-xserver-utils nfs-common

NOTE:
I use Myth TV at home. As such you would need the proper plugin.
Code:
apt install kodi-pvr-mythtv

END NOTE

NOTE:
In my setup at home I have root ssh access enabled from the server so I can run various commands on the clients from my non privileged user via the crontab or command line. To accomplish this you will need to get an authorized_keys file from your server or main machine into the chroot /root/.ssh/ folder. On the host you will need to make sure this folder is pulled into the image when created. Edit the file @ /etc/ltsp/ltsp-update-image.excludes and remove the following line.
Code:
root/.*

Later when you try to ssh into the [email protected]client it should ask for confirmation then let you in no problems. Basically skipping the
Code:
ssh-copy-id [email protected]

This of course wouldn’t work since your client is booting a read only image from the server and you can’t write to anything in that root filesystem.

You can no unmount the proc sys and dev folders we mounted at the start.
Code:
for folder in proc sys dev ; do
  sudo umount /opt/ltsp/ltspmedia/”$folder”
done

Occasionally dev won’t umount. I haven’t bothered chasing why. As I run my ltsp server in a container I just restart the container and move on. If you are doing on bare metal restart the machine. If you find a way to umount if it’s stuck please post back with your solution.

Create this file in your chroot to enable cron to work properly from the lts.conf main configuration file. This will enable up to 20 crontabs to be loaded on a given client. I’m not even sure if the lts.conf can accept that many. But I figured why not.

Inside the chroot @ /etc/ltsp/crontabs
Code:
#!/bin/bash
# modified from script found @ https://help.ubuntu.com/community/UbuntuLTSP/ChrootCronjobs
## variables ##
TMPFILE=/tmp/crontab.tmp
## begin script ##
for job in 0{1..9} 10 1{1..9} 20 ; do
  JOB=$(getltscfg CRONTAB_"$job")
  if [[ -n "$JOB" ]] ; then
    echo >> "$TMPFILE"
    echo "$JOB" >> "$TMPFILE"
  fi
done
if [[ -f "$TMPFILE" ]] ; then
crontab "$TMPFILE"
fi
rm -f "$TMPFILE"


At this point complete your chroot image
Code:
sudo ltsp-update-image ltspmedia

This may take a bit depending on how strong your server is.

In the future any time a change is made inside the chroot of any kind you will need to run this command to make the image reflect that current chroot content. This includes config edits, updates, literally ANY change requires this to be run again.

The user folders for the chroot are actually users on the host. Create the folders as needed. Lets start with our living room user.
Code:
sudo adduser kodimain

For all kodi box users the password should be the same. As these are autologins without keyboard mouse access it isn’t a huge issue. This simply makes it easier to autologin for LTSP.

Make your /home/kodimain/.kodi/userdata folder and dump your advancedsettings.xml in it.

Here is my advancedsettings.xml.
Code:
<advancedsettings>
 <videodatabase>
  <type>mysql</type>
  <host>sql.mylan.home</host>
  <name>jygvideo</name>
  <port>3306</port>
  <user>kodi</user>
  <pass>kodi</pass>
 </videodatabase>
 <musicdatabase>
  <type>mysql</type>
  <host>sql.mylan.home</host>
  <name>ourmusic</name>
  <port>3306</port>
  <user>kodi</user>
  <pass>kodi</pass>
 </musicdatabase>
 <videolibrary>
 <importwatchedstate>true</importwatchedstate>
 <importresumepoint>true</importresumepoint>
</videolibrary>

These settings are unique to my configuration. This file and and how to configure along with setting up mysql to use it are found on the Kodi wiki. If you have multiple locations with each having it’s own video databases it’s as simple as changing the name of the db under the videodatabase section. Again in my case I’m currently running 3 video dbs at home. Guest room is one. Living room / master bedroom share one. And I have another running for my parent’s at their home across the yard.

Next for each dedicated Kodi machine user you will need to configure Openbox to autostart a few lines. Here is mine. It is the same across the dedicated users.

/home/kodimain/.config/openbox/autostart
Code:
kodi &
sleep 5
xset s off -dpms &



Almost there. Don’t give up now. Last steps.
Individual machines should have a static ip so the remote app can be set and not change. I do this via mac address inside of my dhcpd.conf file. Assuming you have the rest set up, this part is specific to ltsp.
Code:
# testing 18.04 bionic

group {
next-server 192.168.1.240;
option root-path "/opt/ltsp/ltspmedia";
if substring( option vendor-class-identifier, 0, 9 ) = "PXEClient" {
filename "ltsp/ltspmedia/pxelinux.0";
} else {
filename "ltsp/ltspmedia/nbi.img";
}
    host kodimain.mylan.home { # living room
        hardware ethernet xx:xx:xx:xx:xx:xx;
        fixed-address 192.168.1.42;
    }
}

next server is your ltsp server ip. The others are as follows. Any machine specified via mac address inside this group will check this ip for a pxe bootable image.

And finally. The LTS.conf. The file that does the proper boot magic. This also works via mac address. This file is going to be located at /var/lib/tftpboot/ltsp/ltspmedia/lts.conf
Code:
[Default]
LDM_DIRECTX = "true"
RCFILE_01 = "/etc/ltsp/crontabs"
KEEP_SYSTEM_SERVICES = "ssh"
CRONTAB_01 = "USER=root"
CRONTAB_02 = "00 00 * * 7 /bin/echo 3 > /proc/sys/vm/drop_caches"
CRONTAB_03 = "00 00 * * 7 /sbin/swapoff -a && /sbin/swapon -a
# this line is for debian & ubuntu 18.04. can’t explain it. Just found it after much searching and it
# fixed the occasional failure to boot
INIT_COMMAND_RM_NBD_CHECKUPDATE = "rm -rf /usr/share/ldm/rc.d/I01-nbd-checkupdate"

[media]
LDM_GUEST_LOGIN = "true"
LDM_LOGIN_TIMEOUT = "10"
LDM_SESSION = "openbox"
LDM_PASSWORD = "1981"

# main kodi living room

[xx:xx:xx:xx:xx:xx]
LIKE = "media"
LDM_USERNAME = "kodimain
HOSTNAME = "kodimain"

At this point it should be fully configured and ready to roll. Restart your isc-dhcp-server to make sure the changes are applied to the dhcp server.

Plug in your client, make sure it is configured to pxe boot and give it a shot. If it worked correctly Kodi should load right up. If you are loading from an existing database and your advancedsettings.xml is correct it should come right up. Kodi will work exactly the same as a bare metal install. Add sources, configure addons / plugins. You can even copy an existing /home/”$USER”/.kodi folder into the server user and it should up exactly as it was before the transfer.

Please post any problems you may have and we can try to sort them out.
Reply
 
Thread Rating:
  • 0 Vote(s) - 0 Average



Logout Mark Read Team Forum Stats Members Help
HOW TO - Using LTSP to PXE boot media centers.00
This forum uses Lukasz Tkacz MyBB addons.