From Gentoo Wiki
Jump to: navigation, search

XBMC Autostart

Standard method, via init script

First create the xbmc user

root # useradd -m -G audio,cdrom,video,cdrw,usb,users xbmc

Then define the xbmc init.d file with the following contents


# Released under the 2-clause BSD license.

description="Start and stop XBMC"

	need net

        ebegin "Starting XBMC"
        start-stop-daemon --start -u ${XBMC_USER:-xbmc} --background --pidfile /var/run/xbmc.pid --make-pidfile --exec /usr/bin/xinit -- /usr/bin/xbmc-standalone ${XMBC_OPTS} -- :0
        eend $?

        ebegin "Stopping XBMC"
        start-stop-daemon --stop --pidfile /var/run/xbmc.pid
        eend $?

Set the appropriate permissions

root # chmod +x /etc/init.d/xbmc

And tell openrc to start it on boot

root # rc-update add xbmc default

Alternative method, via inittab

This is based on the way the mythtv ebuilds enable the autostart of the mythtv frontend.

First create the xbmc user

root # useradd -m -G audio,cdrom,video,cdrw,usb,users xbmc

Define an xinitrc file in xbmc's home


# .xinitrc
[ -x /usr/bin/nvidia-settings ] && /usr/bin/nvidia-settings -l
/usr/bin/xset s noblank
/usr/bin/xset s off
/usr/bin/xset -dpms
/usr/bin/evilwm &
exec /usr/bin/xbmc

Then create the login scripts


# .bash_profile
case "`tty`" in
        *tty9) startx; logout ;;

Finally add an inittab entry which does the autologin


c9:2345:respawn:/sbin/mingetty --autologin xbmc tty9


Allow the xbmc user to issue an shutdown via polkit, resulting in a shutdown option in the XBMC menu:


polkit.addRule(function(action, subject) {
        if (( (action.id.indexOf("org.freedesktop.udisks.") == 0) || (action.id.indexOf("org.freedesktop.upower.")== 0) || (action.id.indexOf("org.freedesktop.consolekit.")== 0) ) &&
        subject.user=="xbmc") {
        return polkit.Result.YES;

Note: ensure you have the udev USE flag set for shutdown to work

Hardened profile notes

XBMC runs in hardened profiles. One caveat is that to get networking fully working, CONFIG_GRKERNSEC_PROC_USER kernel option has to be unset. If you want to restrict /proc access, set CONFIG_GRKERNSEC_PROC_USERGROUP and GRKERNSEC_PROC_GID to a special group that will have access to /proc filesystem. You can then add add xbmc user to this group.

External resources