Eric Hartwell's InfoDabble

 
Welcome to Eric Hartwell's InfoDabble
About | Site Map
Home Tech Notes Apollo 17: Blue Marble Apollo 17 Flight Journal   Calendars About me  

HowTo: Create a Boot-From-CD Browser Kiosk with Firefox and SLAX Linux

By Eric Hartwell - February 26, 2006

 

   
 

I needed to turn an old PC into a cheap, dedicated, browser appliance. The cleanest choice is a Linux/Firefox boot-from-CD; the hardware demands are minimal, and it is impossible for users to make any permanent changes.

After a little research, I decided to go with SLAX 5.0.6. SLAX is a small and beautiful Linux operating system which fits on and runs directly from a CD-ROM disc. It's ideal for my purposes, because it's small, popular (i.e. current), easily customized, and auto-detects hardware and DHCP.

With the addition of Firefox 1.5, a Firefox kiosk mode extension module, and a little fiddling with xinitrc, I was able to create a small, clean kiosk boot CD that works on practically any PC without affecting the hard disk.

Quick Start

In many cases the default kiosk configuration works fine, and all you have to do is change the start URL. Here's a procedure for Windows:

  1. Download the sample kiosk: Myslax-popcorn-5.0.6.iso  (ZIP, 111MB). Unzip, burn to CD, and test on your hardware.
  2. Copy the /rootcopy directory tree from the CD to your hard disk
  3. Edit the text file rootcopy\etc\X11\xinit\xinitrc. Change the URL in the last line from http://www.ehartwell.com to whatever you need.
    You may need to customize the network settings too.
    [Note: xinitrc uses unix newline codes; you may need a conversion utility].
  4. Download, install, and run MySLAX creator:
    • Select source: use the sample kiosk CD or ISO file
    • Modify boot options: Set MyRootcopy folder to the rootcopy folder on your hard disk.
    • Create ISO, then burn to CD
  5. Done!

Custom Setup

SLAX is easy to customize. Use the full toolkit if you have special requirements, or if you're running on a network without a DHCP server.

Parts

  1. An old PC that can boot from CD
  2. SLAX 5.0.6.
  3. SLAX No CD Ejection module
  4. SLAX Mozilla Firefox 1.5 module
  5. R-kiosk 0.2 Firefox extension that defaults to full screen, disables all menus, toolbars, key commands and right button menus.
  6. A custom xinitrc script (details below)

Tools

  • MySLAX creator [Windows XP/2000/NT] - optional, but very handy
  • A virtual PC (Microsoft or VMware) is useful for development and testing.
    You can boot from the ISO image instead of burning a new CD every time.

Procedure

SLAX Popcorn Edition v 5.0.6

screenshot of SLAX Popcorn Edition 5.0.6SLAX PE is a pocket operating system which fits even 128MB USB Flash Drives. It contains only XFce desktop, Mozilla Firefox, beep-XMMS, Gaim, AbiWord. http://slax.linux-live.org/download.php

Image: SLAX PE desktop


MySLAX Creator Add modules page: Click for larger image.
 


MySLAX Creator Modify boot options page: Click for larger image.
 


Full kiosk screen: No menus, toolbars, or desktop, just HTML.
 

  1. You can configure SLAX from scratch, but I started with SLAX Popcorn Edition. This is a 100M image which includes XFce desktop, X Window System and Firefox.
     
  2. By default, SLAX ejects the boot CD when it shuts down. For a kiosk, this is not "a good thing"! Fortunately, there's a downloadable module to prevent this:
    No CD Ejection module disables forced cd ejection when shutting down the system
    Download the module and keep it handy for the next step
     
  3. SLAX is easy to modify by adding modules, but if you need to change only few files, it provides a straight file copy option. The SLAX CD contains a directory /rootcopy/ whose contents are copied to the root filesystem each time you boot SLAX, preserving all directories.

    I decided to use a custom xinitrc script (details below) to install the Firefox kiosk extension, then start up directly into Firefox without enabling the interactive desktop.
    • Create a rootcopy directory
    • Copy r-kiosk-0.2-fx.xpi to rootcopy/etc
    • Copy the custom xinitrc to rootcopy/etc/X11/xinit
       
  4. MySLAX creator allows you to create your own customised Slax live CD/ISO in Windows XP/2000/NT. Run MySLAX Creator to create a custom installation.
    • Start with Slax-popcorn.iso
    • Add the No_CD_Ejection module
    • Mozilla Firefox 1.5 module
    • Select the gui start boot option so SLAX starts up in GUI mode, without a login prompt
    • Select any other SLAX boot options that are appropriate.
      Caution: SLAX usually needs "hotplug" enabled to detect the network
    • Point the "MyRootcopy folder" to the rootcopy directory from step 3
       
  5. Create your custom ISO and/or CD image (as a bonus, MySLAX has integrated CD burning support).

    Here's my sample kiosk: Myslax-popcorn-5.0.6.iso  (ZIP, 111MB)
     
  6. That's it!

 

Using rootcopy to configure the X Window System

SLAX is easy to modify by adding modules, but if you need to change only few files, you can use straight file copy. The SLAX CD contains a directory /rootcopy/ whose contents are copied to the root filesystem each time you boot SLAX, preserving all directories. So, to use a custom xinitrc script, create a /rootcopy/etc/X11/xinit/ directory on the CD and store your xinitrc in it.

When the startx command initiates an X session, it reads a file called .xinitrc in your home directory to decide which window manager to use or other X clients to start. It also reads the sample or template file called xinitrc installed in the /etc/X11/xinit directory. With SLAX, the simplest approach it to put a custom xinitrc in the /rootcopy/etc/X11/xinit/ directory.

If your network doesn't use DHCP, you may need to customize the network settings first (see below).

In my case, I want to run Firefox instead of the desktop manager:

  • Start up SLAX and get a copy of /etc/X11/xinit/xinitrc
  • Delete or comment out the code that starts the xfce4-session desktop manager
  • Delete or comment out the code that starts the xftaskbar4, xfdesktop, xfcalendar, and xfce4-panel
  • I left in the code to check the Autostart directories and to start xfce-mcs-manager and the xfwm4 daemon
  • Finally, at the end of the startup script run Firefox instead of the desktop:
    /usr/bin/firefox http://www.starturl.com
  • If the user exits Firefox, the xinitrc script will end, and the system will shut down. If you don't want this to happen, you can put the kiosk application inside a loop:
    while true; do
      /usr/bin/firefox
      sleep 1
    done

Caution: The xinit shell script will not work if it has DOS/Windows CR/LF line terminators. Use an editor that supports Unix-style line endings, or a conversion utility to strip them before building the SLAX CD.

Changes to xinitrc (highlighted)
Original xinitrc (slax-popcorn-5.0.6) Modified xinitrc
#!/bin/sh

# fix broken $UID on some system...
if test "x$UID" = "x"; then
UID=`id -u`
fi

# create temp file for X resources
if [ -x /usr/bin/tempfile ]; then
XRESOURCES="$(/usr/bin/tempfile -p xrdb-)"
elif [ -x /usr/bin/mcookie ]; then
XRESOURCES="/tmp/xrdb-$(/usr/bin/mcookie)"
else
XRESOURCES="/tmp/xrdb-$UID.$$"
fi

# Has to go prior to merging Xft.xrdb, as its the "Defaults" file
test -r $HOME/.Xdefaults && cat $HOME/.Xdefaults >> $XRESOURCES

# Check if the user wants to override the above defaults (set by
# mcs ui plugin)
if test "x$XDG_CONFIG_HOME" = "x" ; then
BASEDIR=$HOME/.config/xfce4
else
BASEDIR=$XDG_CONFIG_HOME/xfce4
fi

if test -r $BASEDIR/Xft.xrdb; then
cat $BASEDIR/Xft.xrdb >> $XRESOURCES
elif test -r $XFCE4HOME/Xft.xrdb; then
mkdir -p $BASEDIR
cp $XFCE4HOME/Xft.xrdb $BASEDIR/
cat $BASEDIR/Xft.xrdb >> $XRESOURCES
else
# Those are fallback settings, use the ui plugin to change it
# or add your overrides to ~/.Xresources
# Xft DPI: 96
# Xft.hintstyle: hintnone/hintslight/hintmedium/hintfull
# Xft hinting: 1/0
cat >> $XRESOURCES << EOF
Xft.dpi: 96
Xft.hinting: 1
Xft.hintstyle: hintmedium
EOF
fi

# ~/.Xresources contains overrides to the above
test -r $HOME/.Xresources && cat $HOME/.Xresources >> $XRESOURCES

# load all X resources
xrdb -nocpp -merge $XRESOURCES
rm -f $XRESOURCES

# load local modmap
test -r $HOME/.Xmodmap && xmodmap $HOME/.Xmodmap

# Launch xscreensaver (if available), but only as non-root user
test $UID -gt 0 -a -z "$VNCSESSION" && xscreensaver -no-splash &

# Use ssh-agent if installed and not already running. Run it separately
# so it populates the environment here, so we can clean it up later.
sshagent=`which ssh-agent`
kill_sshagent=0
if test -z "$SSH_AGENT_PID" -a "$sshagent" -a "x$sshagent" != "xno"; then
eval `$sshagent -s`
kill_sshagent=1
fi

# Use dbus-launch if installed.
if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
dbuslaunch=`which dbus-launch`
if test x"$dbuslaunch" != x"" -a x"$dbuslaunch" != x"no"; then
eval `$dbuslaunch --sh-syntax --exit-with-session`
fi
fi
#!/bin/sh

# fix broken $UID on some system...
if test "x$UID" = "x"; then
UID=`id -u`
fi

# create temp file for X resources
if [ -x /usr/bin/tempfile ]; then
XRESOURCES="$(/usr/bin/tempfile -p xrdb-)"
elif [ -x /usr/bin/mcookie ]; then
XRESOURCES="/tmp/xrdb-$(/usr/bin/mcookie)"
else
XRESOURCES="/tmp/xrdb-$UID.$$"
fi

# Has to go prior to merging Xft.xrdb, as its the "Defaults" file
test -r $HOME/.Xdefaults && cat $HOME/.Xdefaults >> $XRESOURCES

# Check if the user wants to override the above defaults (set by
# mcs ui plugin)
if test "x$XDG_CONFIG_HOME" = "x" ; then
BASEDIR=$HOME/.config/xfce4
else
BASEDIR=$XDG_CONFIG_HOME/xfce4
fi

if test -r $BASEDIR/Xft.xrdb; then
cat $BASEDIR/Xft.xrdb >> $XRESOURCES
elif test -r $XFCE4HOME/Xft.xrdb; then
mkdir -p $BASEDIR
cp $XFCE4HOME/Xft.xrdb $BASEDIR/
cat $BASEDIR/Xft.xrdb >> $XRESOURCES
else
# Those are fallback settings, use the ui plugin to change it
# or add your overrides to ~/.Xresources
# Xft DPI: 96
# Xft.hintstyle: hintnone/hintslight/hintmedium/hintfull
# Xft hinting: 1/0
cat >> $XRESOURCES << EOF
Xft.dpi: 96
Xft.hinting: 1
Xft.hintstyle: hintmedium
EOF
fi

# ~/.Xresources contains overrides to the above
test -r $HOME/.Xresources && cat $HOME/.Xresources >> $XRESOURCES

# load all X resources
xrdb -nocpp -merge $XRESOURCES
rm -f $XRESOURCES

# load local modmap
test -r $HOME/.Xmodmap && xmodmap $HOME/.Xmodmap

# Launch xscreensaver (if available), but only as non-root user
test $UID -gt 0 -a -z "$VNCSESSION" && xscreensaver -no-splash &

# Use ssh-agent if installed and not already running. Run it separately
# so it populates the environment here, so we can clean it up later.
sshagent=`which ssh-agent`
kill_sshagent=0
if test -z "$SSH_AGENT_PID" -a "$sshagent" -a "x$sshagent" != "xno"; then
eval `$sshagent -s`
kill_sshagent=1
fi

# Use dbus-launch if installed.
if test x"$DBUS_SESSION_BUS_ADDRESS" = x""; then
dbuslaunch=`which dbus-launch`
if test x"$dbuslaunch" != x"" -a x"$dbuslaunch" != x"no"; then
eval `$dbuslaunch --sh-syntax --exit-with-session`
fi
fi
# Run xfce4-session if installed
xfcesm=`which xfce4-session`
case "x$xfcesm" in
x|xno*)
;;
*)
$xfcesm

if test $kill_sshagent -eq 1; then
eval `$sshagent -k`
fi
exit 0
;;
esac
################## KIOSK: Skip xfce4-session startup
################## KIOSK: Skip xfce4-session startup
##################
# IMPORTANT NOTE #
##################
# Everything below here only gets executed if you are not using xfce4-session
# (Xfce's session manager). If you are using the session manager, everything
# below is handled by it, and the code below is not executed at all. If you're
# not sure if you're using the session manager, type 'ps -e|grep xfce4-session'
# in a terminal while Xfce is running.
##################

# this is only necessary when running w/o xfce4-session
xsetroot -solid black -cursor_name watch

# or use old-fashioned startup script otherwise

xfce-mcs-manager
xfwm4 --daemon

# Start-up stuff from ~/Desktop/Autostart directory, if it exists
# (as it seems to be the new standard)
if test -d "$HOME/Desktop/Autostart"; then
for i in `ls -1 -L ${HOME}/Desktop/Autostart/ 2>/dev/null`; do
if test -x $HOME/Desktop/Autostart/$i; then
$HOME/Desktop/Autostart/$i &
fi
done
fi


##################
# Everything below here ONLY gets executed if you are NOT using xfce4-session
# (Xfce's session manager). If you are using the session manager, everything
# below is handled by it, and the code below is not executed at all. If you're
# not sure if you're using the session manager, type 'ps -e|grep xfce4-session'
# in a terminal while Xfce is running.
##################

# this is only necessary when running w/o xfce4-session
xsetroot -solid black -cursor_name watch

# or use old-fashioned startup script otherwise

xfce-mcs-manager
xfwm4 --daemon

# Start-up stuff from ~/Desktop/Autostart directory, if it exists
# (as it seems to be the new standard)
if test -d "$HOME/Desktop/Autostart"; then
for i in `ls -1 -L ${HOME}/Desktop/Autostart/ 2>/dev/null`; do
if test -x $HOME/Desktop/Autostart/$i; then
$HOME/Desktop/Autostart/$i &
fi
done
fi
xftaskbar4&
xfdesktop&
xfcalendar &

panel=`which xfce4-panel`
case "x$panel" in
x|xno*)
;;
*)
$panel
ret=$?
while test $ret -ne 0; do
xmessage -center -file - -timeout 20 -title Error <<EOF
A crash occured in the panel
Please report this to the xfce4-dev@xfce.org list
or on http://bugs.xfce.org
Meanwhile the panel will be restarted
EOF
cat >&2 <<EOF
A crash occured in the panel
Please report this to the xfce4-dev@xfce.org list
or on http://bugs.xfce.org
Meanwhile the panel will be restarted
EOF
$panel
ret=$?
done
;;
esac
################## KIOSK: Skip desktop startup
################## KIOSK: Skip desktop startup
if test $kill_sshagent -eq 1; then
eval `$sshagent -k`
fi

xsetroot -bg white -fg red -solid black -cursor_name watch
if test $kill_sshagent -eq 1; then
eval `$sshagent -k`
fi

xsetroot -bg white -fg red -solid black -cursor_name watch
  ################## KIOSK: Run FireFox, shut down when done
# Install the kiosk extension, then load the starting web page
/usr/bin/firefox -install-global-extension /etc/r-kiosk-0.2-fx.xpi
/usr/bin/firefox http://www.ehartwell.com

Network Configuration Example

SLAX is extremely smart about network configuration: "SLAX uses DHCP to autoconfigure your network card's IP address, route tables and nameservers. If you are on the network with DHCP server then you shouldn't have any problem. Just boot SLAX and everything will work."

In my case, some of the workstations used DHCP and some had fixed IP. This is easy to script in xinitrc:

if ping -c 1 -w 2 www.ehartwell.com | grep "ttl=" >nul
then
   echo Network detected.
else
   ifconfig eth0 111.1.1.1 netmask 255.255.255.0
   route add default gateway 222.2.2.2
   echo "nameserver 222.2.2.10" >> /etc/resolv.conf
   echo "nameserver 222.2.2.11" >> /etc/resolv.conf
fi

The first line uses PING to see if the workstation is able to reach the server. A successful PING doesn't always return errorlevel 0, so instead the output is piped through GREP to look for the "ttl" line in a successful response. GREP does return errorlevel 0 if the text is found.

The remaining lines are fairly straightforward. The workstation is assigned the fixed IP 111.1.1.1, using the gateway 222.2.2.2 and the nameservers 222.2.2.10 and  222.2.2.11. An excellent online reference is "Guide to IP Layer Network Administration with Linux" by Martin A. Brown.

Revision History

  • February 26, 2006 - added fixed IP setup
  • February 21, 2006 - added quick start
  • February 19, 2006 - initial version

Illustration: A sixteenth-century design for a revolving reading desk: Agostino Ramelli, Le diverse et artificiose machine; composte in lingua Italiana et Francese (Paris, 1588), p. 317. BL, 48.f.15. Courtesy The Electronic British Library Journal

Creative Commons License

Unless otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License

 

Site Map | About Me