HOW-TO:Autostart Kodi for Linux: Difference between revisions

From Official Kodi Wiki
Jump to navigation Jump to search
m (Karellen moved page HOW-TO:HOW-TO:Autostart Kodi for Linux to HOW-TO:Autostart Kodi for Linux without leaving a redirect: Error in page name)
 
(31 intermediate revisions by 3 users not shown)
Line 1: Line 1:


<section begin="intro" /><big>Any or all or any combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop. Experiment inside VirtualBox before you apply any of these to your system and make a backup.</big><section end="intro" />
<section begin="intro" /><big>Any or all or a combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop. Experiment inside VirtualBox before you apply any of these to your system and make a backup.</big><section end="intro" />


__TOC__
__TOC__


== Switch to root ==
== Installing the X11 Window System ==
 
Even if you are using something like [https://github.com/graysky2/kodi-standalone-service Kodi Standalone Service], you still need use a WM or a DE that installs the '''x-window-manager''' software package.
 
To ensure you have this installed use the '''which''' command.


<pre>
<pre>
su
which x-window-manager
</pre>
</pre>


or
If there is no such package, you can use '''apt''' to search your Linux distributions repository.


<pre>
<pre>
sudo su
apt-cache search x-window-manager
</pre>
</pre>


== Create a Kodi user ==
This will generate a list of packages containing '''x-window-manager''', which cannot be installed alone. If you are not using a DE, you need to use a WM. And, you can also use a compositing WM like Compiz, for fast 3D effects.
 
[https://wiki.archlinux.org/index.php/Compiz Compiz - ArchWiki]


To use Kodi full-screen, you only have to create a standard user.
A note on using Kodi Standalone Service, this package runs Kodi as a '''systemd''' service and disables the login for user '''kodi''' and will not work when autologin is enabled. In fact, it will break the login process if you autologin user '''kodi''' and run Kodi Standalone Service at the same time. This package is installed automatically with the standard Kodi package when you install Kodi on Raspbian, but must be configured manually for all other Linux distributions. You can run the '''which''' command to find this package as well.


<pre>
<pre>
adduser kodi
which kodi-standalone
</pre>
</pre>


To remove the password use:
Be advised, Kodi Standalone Service still launches the Kodi GUI and still requires a WM even though it is running as a '''systemd''' service. When you install a WM such as '''xfwm4''' (the WM for XFCE4), the CLI will tell you if it provides the '''x-window-manager''' package.


<pre>
<pre>
passwd -d kodi
Setting up xfwm4 (4.12.4-1) ...
update-alternatives: using /usr/bin/xfwm4 to provide /usr/bin/x-window-manager (x-window-manager) in auto mode
</pre>
</pre>
If you do not see this message at the end of the installation, the WM you selected does not provide this software package and may not actually be a complete WM itself but only part of a package containing a WM.
For a great example on exactly how you would do this with '''xfwm4''', see this ArchWiki entry.
[https://wiki.archlinux.org/index.php/Xfwm XFWM - ArchWiki]
Most systems utilize the client version of the X11 software an Xsession requires.
For more X11 features and functionality, you may optionally upgrade to the server software packages for the X Window System.
<pre>apt install xauth xorg xinit xserver-xorg-core xserver-xorg xserver-common</pre>
The Ubuntu wiki is usually a good source of information.
[https://wiki.ubuntu.com/CustomXSession CustomXSession - Ubuntu Wiki]
Custom user sessions can be created with the X11 Window System to run scripts, autostart apps, and launch a WM or DE.
LightDM is used for autologin.


== Customize LightDM to autologin ==
== Customize LightDM to autologin ==
Line 46: Line 73:
</pre>
</pre>


Create a custom configuration file called '''50-myconfig.conf''' using '''nano''' or other CLI text editor.
Configure LightDM for autologin to boot directly to Kodi.


<pre>
<pre>
mkdir /etc/lightdm/lightdm.conf.d/
nano /etc/lightdm/lightdm.conf
nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf
</pre>
</pre>


Inside this new file add the following text.
Uncomment the following line.


<pre>
<pre>
[SeatDefaults]
#autologin-user=
autologin-user=kodi
</pre>
</pre>


On Raspbian, you can configure LightDM differently for autologin to boot directly to Kodi.
And add the user you want to autologin. The user is named '''kodi''' in this example.


<pre>
<pre>
nano /etc/lightdm/lightdm.conf
autologin-user=kodi
</pre>
</pre>


Uncomment the following line.
And then you can create /etc/lightdm/lightdm.conf.d/50-myconfig.conf, but ensure the settings in /etc/lightdm/lightdm.conf agree.
 
Create a custom configuration file called '''50-myconfig.conf''' using '''nano''' or other CLI text editor.


<pre>
<pre>
#autologin-user=
mkdir /etc/lightdm/lightdm.conf.d/
nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf
</pre>
</pre>


And add the user you want to autologin and autostart Kodi. The user is named '''kodi''' in this example.
Inside this new file add the following text.


<pre>
<pre>
[SeatDefaults]
autologin-user=kodi
autologin-user=kodi
</pre>
</pre>


You can alternately create /etc/lightdm/lightdm.conf.d/50-myconfig.conf, but should still ensure the settings in /etc/lightdm/lightdm.conf agree.
CTRL +O +Enter +X to save and exit from '''nano'''.


== Configure Kodi to autostart ==
== Configure Kodi to autostart ==


Configure Kodi to autostart.
Configure Kodi to autostart.
A)
<pre>
sudo sed -i "1i @kodi" /etc/xdg/lxsession/LXDE-pi/autostart
</pre>
B)


<pre>
<pre>
Line 93: Line 130:
[http://edoceo.com/gui/xfce-autostart-apps Autostart Apps in XFCE]
[http://edoceo.com/gui/xfce-autostart-apps Autostart Apps in XFCE]


The Raspberry Pi is a bit more of a tweak, but these are excellent links that will tell you how. The first link is the most helpful to making sure Kodi autostarts in Pi. There are many settings on the Pi that control boot, and the first link gives the best most trouble-free way to boot directly to Kodi. The others facilitate more tweaks and settings relevant to other uses of the X Window System.
And this link shows how to autostart an app in LXDE on Raspbian.
 
[http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui Auto running programs LXDE - Raspberry Pi Projects]
 
The Raspberry Pi is a bit more of a tweak, but these are excellent links that will tell you how. The first link is the most helpful to making sure Kodi autostarts in Pi, and utilizes a '''crontab'''. There are many settings on the Pi that control boot, and the first link gives the best most trouble-free way to boot directly to Kodi.  


[https://www.leowkahman.com/2016/03/05/lamp-stack-on-raspberry-pi-with-kodi-running-at-startup/ LAMP stack on Raspberry Pi with Kodi running at startup]
[https://www.leowkahman.com/2016/03/05/lamp-stack-on-raspberry-pi-with-kodi-running-at-startup/ LAMP stack on Raspberry Pi with Kodi running at startup]


[http://ozzmaker.com/enable-x-windows-on-piscreen/ Enable X Window System on PiScreen]
In the above link, the author describes using Crontab (short for "Cron table") to boot directly to Kodi.
 
<pre>
apt install cron
crontab -e
</pre>


[https://raspberrypi.stackexchange.com/questions/59310/remove-boot-messages-all-text-in-jessie Remove boot messages all text in Raspbian - Raspberry Pi Stack Exchange]
Cron will ask you to choose a text editor from available options. I choose option 2 for '''nano'''.  


[https://raspberrypi.stackexchange.com/questions/47823/how-to-prevent-autologin-of-gui How to prevent or allow autologin of GUI - Raspberry Pi Stack Exchange]
In the new Crontab, enter the following text.


[http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui Auto running programs LXDE - Raspberry Pi Projects]
<pre>
@reboot kodi --standalone
</pre>


And, if you would rather, it is easier to follow the process provided by this link to modify the Raspbian image before installing it onto the microSD card.
Raspbian has a repository package for everything, so kodi-standalone can be run as a package rather than a command argument. You do not have to install '''kodi-standalone''' with Apt.


[https://wiki.debian.org/RaspberryPi/qemu-user-static Modifying Raspbian with qemu-user-static]
<pre>
apt install kodi-standalone
</pre>


The above link describes removing the DE from a Raspbian image, though Raspbian Lite is a much better starting point for using Qemu for this purpose.
For instance, if I were to install '''kodi-standalone''' after installing the standard '''kodi''' package, this is the message I get.


You can also use the X11 Window System to autostart Kodi by placing a statup script in the /etc/X11/Xsession.d/ directory.
<pre>
root@raspberrypi:/home/pi# apt install kodi-standalone
Reading package lists... Done
Building dependency tree     
Reading state information... Done
Note, selecting 'kodi' instead of 'kodi-standalone'
kodi is already the newest version (2:18.7-1~buster).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@raspberrypi:/home/pi#
</pre>


[https://debian-administration.org/article/50/Running_applications_automatically_when_X_starts Running applications automatically when X starts]
That is because it used to a separate package, but since then it has been made into a command. It is really only a trivial difference, instead of using:


<pre>
<pre>
nano /etc/X11/Xsession.d/startup-local
@reboot kodi --standalone
</pre>
</pre>


Insert this text into the new file. Use CTRL + O + Enter + X to save the file.
You can use,


<pre>
<pre>
#!/bin/sh
@reboot kodi-standalone
/usr/bin/kodi  
</pre>
</pre>


If you have a WM, such as Blackbox you can add it here as well.  
One or the other, not both.
 
You could also consider using Crontab to run a script, much like described on this page in the section entitled "Run kodi in a window manager" if you scroll down the page.
 
[https://wiki.archlinux.org/index.php/Kodi Kodi - Run kodi in a window manager]
 
Instead your Crontab could look like this.


<pre>
<pre>
#!/bin/sh
@reboot startx
blackbox &
/usr/bin/kodi
</pre>
</pre>


Set permissions to make it executable. Use the ampersand to run an application in the background, such as a WM you only need to for the purpose of launching Kodi but not if you don't want to use the WM itself. Kodi will not launch without a DE or WM, but placing the ampersand "&" at the end of the command makes it run in the background where it can do its job out of sight. Also, make sure to start a WM or DE before running an application in the foreground. This is not necessary for apps running in the background.
And create an '''~/.xinitrc''' file.


<pre>
<pre>
chmod 755 /etc/X11/Xsession.d/startup-local
nano ~/.xinitrc
</pre>
</pre>


If Kodi is not installed at the standard path, find it using the '''which''' command.
The '''~/.xinitrc''' file should look like this.


<pre>
<pre>
which kodi
#!/bin/bash
kodi --standalone #(this is proper syntax for most Kodi installs)
#kodi-standalone #(this is the syntax that works on Raspbian, not other Pi operating systems)
sudo chvt 2
sleep 1
sudo chvt 1
</pre>
</pre>


This feature is available on X Window System operating systems most Linux distributions use the X Window System.
Make sure to make '''~/.xinitrc''' executable by running.
 
<pre>
chmod +rx ~/.xinitrc
</pre>


== Disable / enable the login prompt ==
To ensure no password is required by '''sudo''' for any user logging in when this script runs, you must edit /etc/sudoers or run the '''visudo''' command if it is installed to edit /etc/sudoers.


You can disable the graphical login prompt.
You can install '''visudo''' from your Linux distributions default repository.


<pre>
<pre>
systemctl set-default multi-user.target
apt install sudo
</pre>
</pre>


To enable it again use.
To use '''visudo''' simply run the command in the terminal.


<pre>
<pre>
systemctl set-default graphical.target
visudo
</pre>
</pre>


If you are using an autologin method associated with your DE or WM, you '''do not''' want to disable the graphical login.  
For any non-root users, create an entry in /etc/sudoers with '''nano'''.


Even if you are using something like [https://github.com/graysky2/kodi-standalone-service Kodi Standalone Service], you still need use a WM or a DE that installs the '''x-window-manager''' software package.
<pre>
nano /etc/sudoers
</pre>


To ensure you have this installed use the '''which''' command.
Create an entry on any line that is comfortable to you like shown here.


<pre>
<pre>
which x-window-manager
kodi ALL=NOPASSWD: /usr/bin/chvt
# pi ALL=NOPASSWD: /usr/bin/chvt #(if you do not add user kodi)
</pre>
</pre>


If there is no such package, you can use '''apt''' to search your Linux distributions repository.
The above example is for users '''pi''' and '''kodi'''.
 
If you decide not use a Cron table, you can always remove it again.


<pre>
<pre>
apt-cache search x-window-manager
crontab -r
</pre>
</pre>


This will general a list of packages containing '''x-window-manager''', which cannot be installed alone. If you are not using a DE, you need to use a WM. And, you can also use a compositing WM like Compiz, for fast 3D effects.
This is a quick reference for Crontab.
 
[http://www.adminschoice.com/crontab-quick-reference Crontab Quick Reference]
 
These linked pages facilitate more tweaks and settings relevant to other uses of the X Window System on Pi.
 
[http://ozzmaker.com/enable-x-windows-on-piscreen/ Enable X Window System on PiScreen]
 
Other things to tweak on Raspbian.
 
[https://yingtongli.me/blog/2016/12/21/splash.html Raspbian splash screen guide - Clean up the boot process]
 
[https://scribles.net/lightning-bolt-under-voltage-warning-on-raspberry-pi/ Under voltage warning and disabling splash screen on Raspbian]
 
[https://raspberrypi.stackexchange.com/questions/59310/remove-boot-messages-all-text-in-jessie Remove boot messages all text in Raspbian - Raspberry Pi Stack Exchange]
 
And, if you would rather, it is easier to follow the process provided by this link to modify the Raspbian image before installing it onto the microSD card.
 
[https://wiki.debian.org/RaspberryPi/qemu-user-static Modifying Raspbian with qemu-user-static]
 
The above link describes removing the DE from a Raspbian image, though Raspbian Lite is a much better starting point for using Qemu for this purpose.


[https://wiki.archlinux.org/index.php/Compiz Compiz - ArchWiki]
You can also use the X11 Window System to autostart Kodi by placing a startup script in the /etc/X11/Xsession.d/ directory.


A note on using Kodi Standalone Service, this package runs Kodi as a '''systemd''' service and disables the login for user '''kodi''' and will not work when autologin is enabled. In fact, it will break the login process if you autologin user '''kodi''' and run Kodi Standalone Service at the same time. This package is installed automatically with the standard Kodi package when you install Kodi on Raspbian, but must be configured manually for all other Linux distributions. You can run the '''which''' command to find this package as well.
[https://debian-administration.org/article/50/Running_applications_automatically_when_X_starts Running applications automatically when X starts]


<pre>
<pre>
which kodi-standalone
nano /etc/X11/Xsession.d/startup-local
</pre>
</pre>


Be advised, Kodi Standalone Service still launches the Kodi GUI and still requires a WM even though it is running as a '''systemd''' service. When you install a WM such as '''xfwm4''' (the WM for XFCE4), the CLI will tell you if it provides the '''x-window-manager''' package.
Insert this text into the new file. Use CTRL + O + Enter + X to save the file.  


<pre>
<pre>
Setting up xfwm4 (4.12.4-1) ...
#!/bin/sh
update-alternatives: using /usr/bin/xfwm4 to provide /usr/bin/x-window-manager (x-window-manager) in auto mode
/usr/bin/kodi
</pre>
</pre>


If you do not see this message at the end of the installation, the WM you selected does not provide this software package and may not actually be a complete WM itself but only part of a package containing a WM.
If you have a WM, such as Blackbox you can add it here as well.  


For a great example on exactly how you would do this with '''xfwm4''', see this ArchWiki entry.
<pre>
#!/bin/sh
blackbox &
/usr/bin/kodi
</pre>


[https://wiki.archlinux.org/index.php/Xfwm XFWM - ArchWiki]
Set permissions to make it executable. Use the ampersand to run each command in the background till the last line or your script will get stuck on the first line.


== Create custom Xsession script ==
<pre>
chmod 755 /etc/X11/Xsession.d/startup-local
</pre>


Most systems utilize the client version of the X11 software an Xsession requires requires.
If Kodi is not installed at the standard path, find it using the '''which''' command.


Upgrade to the server versions of the X Window System, if you want to utilize all the greatness of the X Window System.
<pre>
which kodi
</pre>


Because of the lack of documentation, it is probably better to find tweaks and hacks on wikis and support pages rather than forums. For instance, the Ubuntu wiki is usually a good source of information.
This feature is available on X Window System operating systems most Linux distributions use the X Window System.


[https://wiki.ubuntu.com/CustomXSession CustomXSession - Ubuntu Wiki]
== Create custom Xsession script ==


<pre>apt install xauth xorg xinit xserver-xorg-core xserver-xorg xserver-common</pre>
To create a custom Xsession script with a text editor we start with an '''xinitrc''' script. For more detail on how to create and use '''xinit''', there is a great guide available here.


Create a custom Xsession script with a text editor.
[https://en.wikibooks.org/wiki/Guide_to_X11/Starting_Sessions Guide to X11 - Starting Sessions - WikiBooks]


<pre>
<pre>
Line 223: Line 327:
<pre>
<pre>
#!/usr/bin/env bash
#!/usr/bin/env bash
exec gnome-session
exec gnome-session &
/usr/bin/kodi -fs  
/usr/bin/kodi -fs  
</pre>
</pre>
Line 238: Line 342:


<pre>
<pre>
sudo -H -u kodi bash -c "ln -s ~/.xinitrc ~/.xsession"
sudo -H -u kodi bash -c "ln -s ~/.xinitrc /home/kodi/.xsession"
</pre>
</pre>


You need to use '''sudo''' to run this command. If you do not have '''sudo''', install it.
Make sure the path goes to user's home directory. In this example, the user is '''kodi'''.
 
You need to use '''sudo''' to run this command. If you do not have '''sudo''', install it.  


<pre>
<pre>
Line 253: Line 359:
</pre>
</pre>


Remember you can modify use and reuse the '''~/.xinitrc''' file to configure '''~/.xsession''' as often as you want. That is the purpose of the file. It does nothing on its own until you associate it with a user. On some systems using a DE such as Gnome, not all systems using Gnome, it may be necessary for '''.xsession''' to be '''.xsessionrc'''. Though this is more likely the case for organization network computers than a personal one, where configurations may vary on a diversity of machines. Most of the time, it will be '''.xsession''' rather than '''.xsessionrc''' that you want to create.
On some systems using a DE such as Gnome, not all systems using Gnome, it may be necessary for '''.xsession''' to be '''.xsessionrc'''. Though this is more likely the case for organization network computers than a personal one, where configurations may vary on a diversity of machines. Most of the time, it will be '''.xsession''' rather than '''.xsessionrc''' that you want to create.
 
You can also create the '''.xsession''' script directly in the home directory, rather than link it from '''~/.xinitrc'''. This is necessary if you create multiple custom Xsession scripts for multiple users, and you do not in that case link '''~/.xinitrc''' to '''.xsession'''.


You must also autostart the X Window system, which differs somewhat from scenario to scenario. For most setups, all that is necessary is to edit the '''.bashrc''' file.
To enable multiple displays edit the '''.bashrc''' file.


<pre>
<pre>
Line 261: Line 369:
</pre>
</pre>


Add the following as shown.
Add the following text.
 
<pre>
if [[ ! $DISPLAY && $XDG_VTNR -le 3 ]]; then
  exec startx
fi
</pre>
 
For two monitors add the following as shown.
 
<pre>
if [[ ! $DISPLAY && $XDG_VTNR -le 2 ]]; then
  exec startx
fi
</pre>
 
For a single monitor use:


<pre>
<pre>
Line 289: Line 413:
This will create a new login option for the custom Xsession. Only this one entry is necessary for LightDM and X11 to find the '''~/.xsession''' script in each user's home directory.
This will create a new login option for the custom Xsession. Only this one entry is necessary for LightDM and X11 to find the '''~/.xsession''' script in each user's home directory.


== Xsession to boot to app / WM / DE ==
You can use any window manager or desktop enviroment with a custom Xsession script as long as it is installed.
 
You can use any window manager or desktop enviroment with a custom Xsession script as long as it is intalled.


You do this by creating '''~/.xinitrc''' script that contains the command to start the WM or DE.
You do this by creating '''~/.xinitrc''' script that contains the command to start the WM or DE.
Line 322: Line 444:


<pre>
<pre>
dpkg-reconfigure xserver-xorg-legacy
dpkg-reconfigure xserver-xorg-legacy  
</pre>
 
And / or...
 
<pre>
dpkg-reconfigure xserver-xorg
dpkg-reconfigure xserver-xorg
</pre>
</pre>


If both packages are installed, you must reconfigure both. Not all systems will use or require the legacy package to allow non-root users to start X.
When you reconfigure X11 with these commands, choose to allow non-root users (anybody) to start an Xsession. You should see your changes take effect after rebooting.
 
== Add a custom Grub entry ==
 
If you want to boot to the CLI and manually launch an app or boot directly to Kodi without a DE or WM, add a custom grub entry.
 
The right way to add a custom grub entry is to copy the menu entry you want to change or duplicate.
 
Copy the default Grub configuration file and open it with a text editor on your desktop. If you use a text editor on the CLI, the text will be cut off by the window when copying and pasting.
 
<pre>
cp /boot/grub/grub.cfg grub.cfg
gedit grub.cfg
</pre>
 
Copy the menu entry and paste it into '''40_custom''' with a text editor in the CLI.
 
<pre>
nano /etc/grub.d/40_custom
</pre>
 
Where the menu entry contains '''quiet splash''' change it to '''text''' instead.
 
You should also change the name of the entry!
 
I just appended mine with “CLI” for command line interface.
 
To update Grub:
 
<pre>
update-grub
</pre>
 
To launch a WM you can type its name. I use Enlightment 17 or Fluxbox. It must be installed.
 
<pre>
fluxbox
</pre>
 
You must have FluxBox installed. There are countless other window managers.
 
To launch a DE you enter the appropriate command. For Gnome desktop:
 
<pre>
gnome-session
</pre>
 
For KDE:
 
<pre>
startkde
</pre>
 
or
 
<pre>
plasma-desktop
</pre>
 
For XFCE:
 
<pre>
startxfce4
</pre>
 
For Mate:
 
<pre>
mate-session
</pre>
 
For LXDE:
 
<pre>
startlxde
</pre>


You can either manually launch your apps, boot right into them, or create an Xsession for each user. This is great when you want to create a Kodi user for running Kodi only, and for making sure you can still login to your DE with your regular user account. You can boot to any app full-screen this way, not just Kodi. You can create a custom Xsession script for any user, configured with any startup applications running in full-screen mode or normally.


By optionally creating a Grub menu entry, you can create a different Grub menu selection to boot only to the CLI and start an Xsession with a script or run commands manually.
[[Category:Linux]]

Latest revision as of 18:49, 26 April 2021

Any or all or a combination of these methods can be used to configure a Debian-based X Window System to boot directly to Kodi. This should work on any Linux using the X Window System, but these instructions are particular to Debian derivatives, such as Ubuntu. A server edition is best for running only Kodi, but this page assumes booting into a desktop OS, not a server distro. However, the instructions here can be used for a server distro with even less configuration than for a desktop. Experiment inside VirtualBox before you apply any of these to your system and make a backup.

Installing the X11 Window System

Even if you are using something like Kodi Standalone Service, you still need use a WM or a DE that installs the x-window-manager software package.

To ensure you have this installed use the which command.

which x-window-manager

If there is no such package, you can use apt to search your Linux distributions repository.

apt-cache search x-window-manager

This will generate a list of packages containing x-window-manager, which cannot be installed alone. If you are not using a DE, you need to use a WM. And, you can also use a compositing WM like Compiz, for fast 3D effects.

Compiz - ArchWiki

A note on using Kodi Standalone Service, this package runs Kodi as a systemd service and disables the login for user kodi and will not work when autologin is enabled. In fact, it will break the login process if you autologin user kodi and run Kodi Standalone Service at the same time. This package is installed automatically with the standard Kodi package when you install Kodi on Raspbian, but must be configured manually for all other Linux distributions. You can run the which command to find this package as well.

which kodi-standalone

Be advised, Kodi Standalone Service still launches the Kodi GUI and still requires a WM even though it is running as a systemd service. When you install a WM such as xfwm4 (the WM for XFCE4), the CLI will tell you if it provides the x-window-manager package.

Setting up xfwm4 (4.12.4-1) ...
update-alternatives: using /usr/bin/xfwm4 to provide /usr/bin/x-window-manager (x-window-manager) in auto mode

If you do not see this message at the end of the installation, the WM you selected does not provide this software package and may not actually be a complete WM itself but only part of a package containing a WM.

For a great example on exactly how you would do this with xfwm4, see this ArchWiki entry.

XFWM - ArchWiki

Most systems utilize the client version of the X11 software an Xsession requires.

For more X11 features and functionality, you may optionally upgrade to the server software packages for the X Window System.

apt install xauth xorg xinit xserver-xorg-core xserver-xorg xserver-common

The Ubuntu wiki is usually a good source of information.

CustomXSession - Ubuntu Wiki

Custom user sessions can be created with the X11 Window System to run scripts, autostart apps, and launch a WM or DE.

LightDM is used for autologin.

Customize LightDM to autologin

You can utilize the ability to customize LightDM data manager by changing the builtin custom configuration file 50-myconfig.conf using nano or another text editor. If you have no DE or WM you can install lightdm, but should make sure to do a bit of research before you do. Most versions of Linux use LightDM, but many server versions do not. For Ubuntu Server with no DE, for example, installing lightdm is okay and necessary. Changing the behavior of LightDM is done using a custom 50-myconfig.conf configuration file.

To see if you have lightdm use which.

which lightdm

If not, install it with apt.

apt install lightdm

Configure LightDM for autologin to boot directly to Kodi.

nano /etc/lightdm/lightdm.conf

Uncomment the following line.

#autologin-user=

And add the user you want to autologin. The user is named kodi in this example.

autologin-user=kodi

And then you can create /etc/lightdm/lightdm.conf.d/50-myconfig.conf, but ensure the settings in /etc/lightdm/lightdm.conf agree.

Create a custom configuration file called 50-myconfig.conf using nano or other CLI text editor.

mkdir /etc/lightdm/lightdm.conf.d/
nano /etc/lightdm/lightdm.conf.d/50-myconfig.conf

Inside this new file add the following text.

[SeatDefaults]
autologin-user=kodi

CTRL +O +Enter +X to save and exit from nano.

Configure Kodi to autostart

Configure Kodi to autostart.

A)

sudo sed -i "1i @kodi" /etc/xdg/lxsession/LXDE-pi/autostart

B)

mkdir -p ~/.config/autostart
ln -s /usr/bin/kodi ~/.config/autostart

This method of autostart requires a desktop environment or DE. This is done a bit differently by each DE. Some helpful links can easily be found in today's Web search using any search engine.

Autostart Apps in XFCE

And this link shows how to autostart an app in LXDE on Raspbian.

Auto running programs LXDE - Raspberry Pi Projects

The Raspberry Pi is a bit more of a tweak, but these are excellent links that will tell you how. The first link is the most helpful to making sure Kodi autostarts in Pi, and utilizes a crontab. There are many settings on the Pi that control boot, and the first link gives the best most trouble-free way to boot directly to Kodi.

LAMP stack on Raspberry Pi with Kodi running at startup

In the above link, the author describes using Crontab (short for "Cron table") to boot directly to Kodi.

apt install cron
crontab -e

Cron will ask you to choose a text editor from available options. I choose option 2 for nano.

In the new Crontab, enter the following text.

@reboot kodi --standalone

Raspbian has a repository package for everything, so kodi-standalone can be run as a package rather than a command argument. You do not have to install kodi-standalone with Apt.

apt install kodi-standalone

For instance, if I were to install kodi-standalone after installing the standard kodi package, this is the message I get.

root@raspberrypi:/home/pi# apt install kodi-standalone
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'kodi' instead of 'kodi-standalone'
kodi is already the newest version (2:18.7-1~buster).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
root@raspberrypi:/home/pi#

That is because it used to a separate package, but since then it has been made into a command. It is really only a trivial difference, instead of using:

@reboot kodi --standalone

You can use,

@reboot kodi-standalone

One or the other, not both.

You could also consider using Crontab to run a script, much like described on this page in the section entitled "Run kodi in a window manager" if you scroll down the page.

Kodi - Run kodi in a window manager

Instead your Crontab could look like this.

@reboot startx

And create an ~/.xinitrc file.

nano ~/.xinitrc

The ~/.xinitrc file should look like this.

#!/bin/bash
kodi --standalone #(this is proper syntax for most Kodi installs)
#kodi-standalone #(this is the syntax that works on Raspbian, not other Pi operating systems)
sudo chvt 2 
sleep 1
sudo chvt 1

Make sure to make ~/.xinitrc executable by running.

chmod +rx ~/.xinitrc

To ensure no password is required by sudo for any user logging in when this script runs, you must edit /etc/sudoers or run the visudo command if it is installed to edit /etc/sudoers.

You can install visudo from your Linux distributions default repository.

apt install sudo

To use visudo simply run the command in the terminal.

visudo

For any non-root users, create an entry in /etc/sudoers with nano.

nano /etc/sudoers

Create an entry on any line that is comfortable to you like shown here.

kodi ALL=NOPASSWD: /usr/bin/chvt
# pi ALL=NOPASSWD: /usr/bin/chvt #(if you do not add user kodi)

The above example is for users pi and kodi.

If you decide not use a Cron table, you can always remove it again.

crontab -r

This is a quick reference for Crontab.

Crontab Quick Reference

These linked pages facilitate more tweaks and settings relevant to other uses of the X Window System on Pi.

Enable X Window System on PiScreen

Other things to tweak on Raspbian.

Raspbian splash screen guide - Clean up the boot process

Under voltage warning and disabling splash screen on Raspbian

Remove boot messages all text in Raspbian - Raspberry Pi Stack Exchange

And, if you would rather, it is easier to follow the process provided by this link to modify the Raspbian image before installing it onto the microSD card.

Modifying Raspbian with qemu-user-static

The above link describes removing the DE from a Raspbian image, though Raspbian Lite is a much better starting point for using Qemu for this purpose.

You can also use the X11 Window System to autostart Kodi by placing a startup script in the /etc/X11/Xsession.d/ directory.

Running applications automatically when X starts

nano /etc/X11/Xsession.d/startup-local

Insert this text into the new file. Use CTRL + O + Enter + X to save the file.

#!/bin/sh
/usr/bin/kodi 

If you have a WM, such as Blackbox you can add it here as well.

#!/bin/sh
blackbox &
/usr/bin/kodi 

Set permissions to make it executable. Use the ampersand to run each command in the background till the last line or your script will get stuck on the first line.

chmod 755 /etc/X11/Xsession.d/startup-local

If Kodi is not installed at the standard path, find it using the which command.

which kodi

This feature is available on X Window System operating systems most Linux distributions use the X Window System.

Create custom Xsession script

To create a custom Xsession script with a text editor we start with an xinitrc script. For more detail on how to create and use xinit, there is a great guide available here.

Guide to X11 - Starting Sessions - WikiBooks

nano ~/.xinitrc

To run Kodi full-screen make sure the text reads:

#!/usr/bin/env bash
exec gnome-session &
/usr/bin/kodi -fs 

Replace the gnome-session with the DE or WM command you are using. See the last section for examples.

To make ~/.xinitrc executable use.

chmod +x ~/.xinitrc

Use sudo and the ~/.xinitrc file to configure ~/.xsession.

sudo -H -u kodi bash -c "ln -s ~/.xinitrc /home/kodi/.xsession"

Make sure the path goes to user's home directory. In this example, the user is kodi.

You need to use sudo to run this command. If you do not have sudo, install it.

apt install sudo

If you create a symbolic link and want to remove it, simply remove the existing .xsession file you created.

rm /home/kodi/.xsession

On some systems using a DE such as Gnome, not all systems using Gnome, it may be necessary for .xsession to be .xsessionrc. Though this is more likely the case for organization network computers than a personal one, where configurations may vary on a diversity of machines. Most of the time, it will be .xsession rather than .xsessionrc that you want to create.

You can also create the .xsession script directly in the home directory, rather than link it from ~/.xinitrc. This is necessary if you create multiple custom Xsession scripts for multiple users, and you do not in that case link ~/.xinitrc to .xsession.

To enable multiple displays edit the .bashrc file.

nano ~/.bashrc

Add the following text.

if [[ ! $DISPLAY && $XDG_VTNR -le 3 ]]; then
  exec startx
fi

For two monitors add the following as shown.

if [[ ! $DISPLAY && $XDG_VTNR -le 2 ]]; then
  exec startx
fi

For a single monitor use:

if [[ ! $DISPLAY && $XDG_VTNR -eq 1 ]]; then
  exec startx
fi

If you wish to remain logged in after quitting X, remove the exec from the above. Other configurations can be applied, but are irrelevant to autostarting Kodi.

Xinit Autostart X at login

If you are using LightDM and you just want to create a new login entry for user kodi, you must create a new file.

nano /usr/share/xsessions/custom.desktop

And insert the following text.

[Desktop Entry]
Name=Xsession
Exec=/etc/X11/Xsession

This will create a new login option for the custom Xsession. Only this one entry is necessary for LightDM and X11 to find the ~/.xsession script in each user's home directory.

You can use any window manager or desktop enviroment with a custom Xsession script as long as it is installed.

You do this by creating ~/.xinitrc script that contains the command to start the WM or DE.

For instance, if you are using FluxBox.

#!/usr/bin/env bash
exec fluxbox &
/usr/bin/kodi -fs

The -fs option is full-screen.

To run Gnome in the background, but launch Kodi in the foreground.

#!/usr/bin/env bash
exec gnome-session &
/usr/bin/kodi -fs

Use the ~/.xinitrc file to configure ~/.xsession to create a custom login for any user, not just Kodi.

sudo -H -u [username] bash -c "ln -s ~/.xinitrc ~/.xsession"

You must reconfigure Xserver for any user that is not a privileged user to be able to start a custom Xsession.

dpkg-reconfigure xserver-xorg-legacy 
dpkg-reconfigure xserver-xorg

When you reconfigure X11 with these commands, choose to allow non-root users (anybody) to start an Xsession. You should see your changes take effect after rebooting.