Difference between revisions of "Clean Core"

From LinuxMCE
Jump to: navigation, search
(halfway through an update)
(done updating for now)
Line 1: Line 1:
 
== Introduction ==
 
== 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 get rid of the Launch Manager application, and it's dependency uppon a graphic environment, at least for starting a (dedicated) core machine.
+
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.
 
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.
Line 8: Line 8:
 
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.
 
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.
  
=== Setting the default runlevel ===
+
=== Selecting a runlevel at boottime ===
  
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):
+
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.
  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: # Unused
+
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.
+
 
+
=== Selecting a runlevel at boottime ===
+
  
Since changing a text file to switch back and forth every time isn't very comfortable, here is a way to do it from the boot-menu.
 
 
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.)
 
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
 
  cat >/etc/event.d/rc-default <<EOF
Line 58: Line 47:
 
  EOF
 
  EOF
  
Now edit [i]/boot/grub/menu.lst[/i] with your favorite editor as follows:
+
Now edit ''/boot/grub/menu.lst'' with your favorite editor as follows:
  
Comment out the ''hiddenmenu'' option (this will show you the menu without having to press esc)
+
Comment out the ''hiddenmenu'' option as follows (this will show you the menu without having to press esc):
 
  ## hiddenmenu   
 
  ## hiddenmenu   
 
  # Hides the menu by default (press ESC to see the menu)
 
  # Hides the menu by default (press ESC to see the menu)
Line 66: Line 55:
  
 
Copy the first boot target once for every runlevel you want to be able to start, and modify it to look something like this:
 
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) Launch Manager
+
  title          LMCE 1.1 (0704) LaunchManager
 
  root            (hd''#'',''#'')
 
  root            (hd''#'',''#'')
 
  kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'' ro quiet splash '''runlevel=2'''
 
  kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'' ro quiet splash '''runlevel=2'''
Line 80: Line 69:
 
  savedefault
 
  savedefault
 
   
 
   
title          Ubuntu, kernel 2.6.20-15-generic
+
title          Ubuntu, kernel 2.6.20-15-generic
 
  root            (hd''#'',''#'')
 
  root            (hd''#'',''#'')
 
  kernel          /boot/vmlinuz-2.6.20-15-generic root=UUID=''xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'' ro quiet splash  
 
  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
+
initrd          /boot/initrd.img-2.6.20-15-generic
quiet
+
quiet
savedefault
+
savedefault
  
 +
You can also remove the ''quiet splash'' part if you want to see what is going on during boot.
  
to be continued soon...
+
=== Setting up the runlevels ===
  
 +
Traditionally the runlevels are controlled by manipulating a set of symlinks in the ''/etc/rc'''X'''.d/'' directory, where '''X''' is the runlevel (the Kubuntu system uses upstart, which has other ways as well).
  
== Known Information ==
+
In order to make the dedicated LinuxMCE system boot KDE in runlevel 3, only a single symbolic link has to be changed
* In [http://forum.linuxmce.com/index.php?topic=1766.0 Starting CORE software automatically. Beta1.1] bobpaul wrote on June 24, 2007 [http://forum.linuxmce.com/index.php?topic=1766.msg8377#msg8377]:
+
  ln -sf ../init.d/kdm.saved /etc/rc3.d/S99kdm
you'll find all of the LinuxMCE scripts in /usr/pluto/bin.
+
Two very interesting scripts are Start_X.sh (which I assume you already found?) and StartCoreServices.sh
+
+
My guess would be you could disable the Start_X script.
+
  This can be done from the web interface and goto Advanced: Software: Boot Sequence.  
+
Untick the box for Start_X.  
+
Then, manually launch /usr/pluto/bin/StartCoreServices.sh from some init script.
+
I think that should do what you originally asked for, but I haven't tried it myself.
+
  
* A request for more information on the forum was posted by KingCrab: [http://forum.linuxmce.com/index.php?topic=1894.msg8605#msg8605 How does a core system start?].  If you don't want to sign up for the wiki or feel uncomfortable editing this page you could leave a message there.
+
Now you should be able to reboot and select one of the options we've just added.
  
* More to come...
+
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
  
== Version Specific Notes ==
+
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.
This seems like a good place to add information specificly related to a certain version of LMCE.
+
  
=== LMCE 1.1 RC1 ===
+
to be continued...
The current test version.
+
  
== Personal Notes ==
+
=== Changing the default runlevel ===
So... what did you try, and how did it work out?
+
 
+
----
+
 
+
I've tried the way bobpaul described in his post, but unfortunately working with the Start_X box didn't change anything for me. Then I tried it the "old linux way" ;-) I removed the S99kdm script from /etc/rc2.d, giving me a text login at bootup. Next step was to modify the /etc/rc.local by adding /usr/pluto/bin/StartCoreServices.sh. After next bootup the login web page was up again. This is the point I stopped testing and tried to get more information on startup before moving on...
+
(done with beta2 and rc1)
+
 
+
-- [[User:KingCrab|KingCrab]]
+
 
+
----
+
 
+
I looked on a dedicated core, but the Start_X box was already unticked in the web interface for the core. So I looked at "/etc/rc2.d/S99kdm" which turned out to be a symlink to a non-existant file.  In the end I just rebooted to "rescue" mode and launched "/usr/pluto/bin/StartCoreServices.sh" by hand.  After taking controll with "screen -r" I discover that the DCERouter is unable to connect to the MySQL server.
+
 
+
I reboot the machine to single usermode again to have a clean starting point, this time I decide to change to runlevel 3 with the command "telinit 3".  LinuxMCE is only fully started in runlevel 2 so there are no screen sessions to attach to except for the "VoiceMailMonitor" one (obviously started by /etc/rc3.d/S99voiceMailMonitor).  After launching "/usr/pluto/bin/StartCoreServices.sh" by hand again I see 2 additional screen sessions for "discovery" and "DCERouter", none of the sessions seem to show errors.  The script itself however ended with the message "ERROR: Couldn't attach to DCOP server".
+
 
+
The web-admin appears to fully work, and so does booting a diskless Media Director.  Storage might not fully work yet though, as there are still 2 pluto related scripts (symlinked) in "/etc/rc2.d" that I haven't started yet, "StorageDevices_SambaRadar.sh" and "StorageDevices_StatusRadar.sh" but I'm not entirely sure if they normally even get started since they don't have the usual S## prefix.
+
 
+
I tested this using a dedicated core installation of LMCE-1.1B2 running under VMWare as described in: [[Testing with VMWare]], which I still had lying around.
+
 
+
-- [[User:Zaerc|Zaerc]] 15:53, 2 August 2007 (MST)
+
 
+
----
+
 
+
Not entirely unrelated, but I stumbled onto this neat trick. If you have installed your LinuxMCE hybrid as a "A dedicated LMCE System" so that it starts automaticly after boot you can switch to starting LinuxMCE from the desktop icon (and back) with these instructions.  For this the otherwise unused runlevel 3 is used.  Basicly this hack just activates the backup-config of KDE in another runlevel, and then sets that runlevel as the default, this way it's easy to switch back and forth.
+
 
+
'''These instructions require root privileges!'''
+
# Change the ''/etc/rc3.d/S99kdm'' symlink to point at ''../init.d/kdm.saved''.
+
# Create an ''/etc/inittab'' configuration file to start runlevel 3 by default (there should be none to start with, but you may want to check to be certain, if it already exists you can skip this step and edit it as described below).
+
# Reboot the machine.
+
 
+
ln -sfv ../init.d/kdm.saved /etc/rc3.d/S99kdm
+
  
 +
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
 
  cat >/etc/inittab << EOF
 
  # WARNING: Do NOT set the default runlevel to 0 (shutdown) or 6 (reboot).
 
  # WARNING: Do NOT set the default runlevel to 0 (shutdown) or 6 (reboot).
  #id:2:initdefault: # LinuxMCE
+
  id:2:initdefault: # LinuxMCE
  id:3:initdefault: # KDE
+
  #id:3:initdefault: # KDE
  #id:4:initdefault: # Unused
+
  #id:4:initdefault: # Core
  #id:5:initdefault: # Unused
+
  #id:5:initdefault: # Core + KDE
 
  EOF
 
  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.
  
reboot
+
== Personal experience ==
 
+
Moved to the discussion/talk page.
You should be greeted by the KDE login screen, after logging in with the user you created during the '''Kubuntu''' installation, you should be able to start LinuxMCE with the icon as one normally would after a "Primary used as PC" type of installation.
+
 
+
If you want to change the default runlevel again, simply use your favorite text editor (as root) to uncomment one of the other lines in the ''/etc/inittab'' created earlier. '''''WARNING:''''' Do '''NOT''' set the default runlevel to 0 (shutdown) or 6 (reboot), if you do your system will either immediately shutdown or reboot!  This can be fixed, but just don't do it ok?
+
 
+
I did this on my LinuxMCE-1.1RC1 hybrid installation, which was installed as a dedicated LMCE machine.
+
 
+
-- [[User:Zaerc|Zaerc]] 18:29, 4 August 2007 (MST)
+
 
+
----
+
 
+
And why stop there? (apart from that it's getting light outside again).  I decided to try KingCrabs approach with an other runlevel.
+
 
+
# replace ''Startup_Core-Hybrid'' with ''StartCoreServices'' and save the result in a new file.
+
# remove the link that starts "kdm" in runlevel 4
+
# make a symlink in runlevel 4 to start our modified script
+
 
+
sed -e 's/Startup_Core-Hybrid/StartCoreServices/' /etc/init.d/kdm >/etc/init.d/lmce-core
+
rm -v /etc/rc4.d/S99kdm
+
ln -sfv ../init.d/lmce-core /etc/rc4.d/S99lmce-core
+
 
+
Now you can use the ''/etc/inittab'' trick described above and reboot.  To change the default runlevel back to as it was you set it to runlevel 2, deleting the ''/etc/inittab'' file completely should have the same effect (deleting could break non-Kubuntu systems though if they rely on this file).
+
 
+
Not all services might be properly started yet, this is experimental! These start scripts might also still need to be started for full operation:
+
 
+
diff rc2.d/ rc4.d/
+
Only in rc2.d/: S10powernowd.early
+
Only in rc2.d/: S23instcheck.sh
+
Only in rc2.d/: S98LMCEUpdate
+
Only in rc2.d/: S990start_avwizard
+
''Only in rc2.d/: S99kdm''
+
''Only in rc4.d/: S99lmce-core''
+
Only in rc2.d/: S99stop-readahead
+
Only in rc2.d/: StorageDevices_SambaRadar.sh
+
Only in rc2.d/: StorageDevices_StatusRadar.sh
+
 
+
After booting a diskless media director I see a bunch of ''CIFS VFS'' errors on the console, but I have seen plenty of those before I even got started.  The web-admin seems to work, the diskless MD plays media, however X10 lighting and the mobile orbitter on my phone, as well as restarting the core from the UI or web-admin don't seem to work, so were not quite done yet. 
+
 
+
In the end I changed the default runlevel back to 2 and everything works as it did before and I can control the lights with the mobile again...
+
 
+
-- [[User:Zaerc|Zaerc]] 22:17, 4 August 2007 (MST)
+
 
+
----
+

Revision as of 04:46, 24 August 2007

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.