Clean Core

From LinuxMCE
Revision as of 21:04, 28 August 2007 by Zaerc (Talk | contribs) (forgot a few things)

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.

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.

In the end, when everything is confirmed working, I would like to propose the following scheme:

  1. rescue (as it is now)
  2. KDE (as it was installed by Kubuntu, like mainly-PC is now)
  3. Core (as in textmode, not fully working yet)
  4. Core + KDE (at the moment the LaunchManager still needs to be started for full operation)
  5. Core + LaunchManager (as the current dedicated core or hybrid is now)

For now, just adapt the examples to your wishes.

Starting another runlevel

If you just want to start a different runlevel once without modifying your startup scripts to much (as described below) You can simply boot into rescue mode by pressing [Esc] if grub tells you to and selecting it from the boot menu. That should boot up to a text console in single user mode, from there you can easily switch to another runlevel, for example runlevel 3:

telinit 3

The "runlevel" command will show you the previous and current runlevel.

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 probably 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 boot 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. Another section of interest could be:

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default         0

Setting up the runlevels

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

Changing the symlinks

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 you'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 probably just need figure out how to start those devices from an extra script.

to be continued...

additional upstart files to modify

/etc/event.d/media-center-startup

start on runlevel 2
start on runlevel 4

stop on shutdown
stop on runlevel 3
stop on runlevel 5

script
/usr/pluto/bin/startup-script.sh
end script

/etc/event.d/pluto-dhcpd-plugin

start on runlevel 2
start on runlevel 4

stop on shutdown
stop on runlevel 3
stop on runlevel 5

script
screen -d -m -S DhcpdPlugin /usr/pluto/bin/Dhcpd-Plugin.sh
end script

In this example they are changed to start in runlevel 4 as well.

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.