Clean Core

From LinuxMCE
Revision as of 04:46, 24 August 2007 by Zaerc (Talk | contribs) (done updating for now)

Jump to: navigation, search

Introduction

This page is meant to document the efforts to turn the LMCE core into one or more "services" that are automaticly started at boot time. In other words we would like to be able to boot a LinuxMCE machine without using the Launch Manager application, and the dependency uppon a graphic environment, at least for starting a (dedicated) core machine.

Due to the lack of documentation we will have to figure a lot of things out on our own. Please don't be shy to add any related knowledge you have, we don't really know what we're doing, so why should you? At least by adding stuff here we'll be able to build uppon each others experience without having to reverse-engineer the wheel every time. And who knows, one day we might even achieve our common goal.

Runlevels

Runlevels are an easy way to change how the system boots. LinuxMCE uses runlevel 2 for normal operation (depending on the selections you made during installation) and runlevel 1 is used for rescue mode. The runlevels 0 and 6 are used for doing a shutdown or a reboot. Which leaves the runlevels 3, 4 and 5 free for us to experiment with.

Selecting a runlevel at boottime

This is a comfortable way to experiment by simply selecting an alternative target from the boot-menu. If it doesn't work out you can simply reboot. These instructions are for a dedicated LMCE hybrid, and will need to be expanded for the other installation types. This is still work in progress.

First we need to replace one of upstart's files, /etc/event.d/rc-default. (It's not a big addition, but I didn't like the way it was written originally, so I just rewrote most of it.)

cat >/etc/event.d/rc-default <<EOF
# rc - runlevel compatibility
#
# This task guesses what the "default runlevel" should be and starts the
# appropriate script.

start on stopped rcS

script
        runlevel --reboot || true


        if grep -q -w -- "-s\|single\|S" /proc/cmdline
        then
                RL="S"
        else
                RL="$(sed -n -e "s/.*runlevel=\([1-5]\).*/\1/p" /proc/cmdline || true)"
        fi

        if [ -z "$RL" -a -r /etc/inittab ]
        then
                RL="$(sed -n -e 's/^id:\([1-5]\):initdefault:.*/\1/p' /etc/inittab || true)"
        fi

        if [ -z "$RL" ]
        then
                RL="2"
        fi

        telinit $RL

end script
EOF

Now edit /boot/grub/menu.lst with your favorite editor as follows:

Comment out the hiddenmenu option as follows (this will show you the menu without having to press esc):

## hiddenmenu   
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

Copy the first boot target once for every runlevel you want to be able to start, and modify it to look something like this:

title           LMCE 1.1 (0704) LaunchManager
root            (hd#,#)
kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash runlevel=2
initrd          /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title           LMCE 1.1 (0704) KDE
root            (hd#,#)
kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash runlevel=3
initrd          /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title           Ubuntu, kernel 2.6.20-15-generic
root            (hd#,#)
kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx ro quiet splash 
initrd          /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

You can also remove the quiet splash part if you want to see what is going on during boot.

Setting up the runlevels

Traditionally the runlevels are controlled by manipulating a set of symlinks in the /etc/rcX.d/ directory, where X is the runlevel (the Kubuntu system uses upstart, which has other ways as well).

In order to make the dedicated LinuxMCE system boot KDE in runlevel 3, only a single symbolic link has to be changed

ln -sf ../init.d/kdm.saved /etc/rc3.d/S99kdm

Now you should be able to reboot and select one of the options we've just added.

In order to boot a core only in runlevel 4, we first need to add a script to the /etc/init.d/ directory:

cat >/etc/init.d/core
#!/bin/sh

case "$1" in
        start)
                /usr/pluto/bin/StartCoreServices.sh
                ;;
        stop)

                /usr/pluto/bin/StopCoreServices.sh
                ;;

        *)
                echo "Usage: /etc/init.d/core {start|stop}"
                exit 1
                ;;
esac

exit 0
EOF

Then remove the link to start kdm, and create a few other links

rm -fv /etc/rc4.d/S99kdm
ln -s ../init.d/powernowd.early /etc/rc4.d/S10powernowd.early
ln -s ../init.d/instcheck.sh /etc/rc4.d/S23instcheck.sh
ln -s ../init.d/LMCEUpdate /etc/rc4.d/S98LMCEUpdate
ln -s ../init.d/0start_avwizard /etc/rc4.d/S990start_avwizard
ln -s ../init.d/stop-readahead /etc/rc4.d/S99stop-readahead
ln -s ../init.d/core /etc/rc4.d/S99core

This will not yet completely start all the devices for me, but booting a diskless media director works. After starting a desktop manually, the launch manager will start the remaining devices and can fire up the local media director. Now we just need figure out how to start those devices from an extra script.

to be continued...

Changing the default runlevel

The default runlevel is 2, unless specified otherwise in the /etc/inittab file, here is an example on how to create such a file (it will override an existing one):

cat >/etc/inittab << EOF
# WARNING: Do NOT set the default runlevel to 0 (shutdown) or 6 (reboot).
id:2:initdefault: # LinuxMCE
#id:3:initdefault: # KDE
#id:4:initdefault: # Core
#id:5:initdefault: # Core + KDE
EOF

This specifies a default runlevel 2 (which it already was without this file anyway), you can use your favorite text editor to edit it to your desire when you permanently want to switch.

Personal experience

Moved to the discussion/talk page.