Meego Wiki
Views

ARM/N900/Install/chroot modular

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
m (Chroot config)
Line 1: Line 1:
'''Under construction'''
'''Under construction'''
-
The chroot script shown [[ARM/N900/Install/chroot|here]] performed everything in one script opening shell inside chroot. This made script very simple but it wasn't very flexible. Here is a new version that divides functionality a bit.
+
= About =
 +
The chroot script shown [[ARM/N900/Install/chroot|here]] performs everything in one script opening shell inside chroot. This makes the script very simple but it also results in shortcomings. Script doesn't for instance help in entering already existing chroot but forces user to do it manually. This divides chroot entering into seperate steps allowing more flexibility.
-
= Chroot basic stuff =
+
= Big picture =
-
== Chroot config ==
+
Ideally everything should go simply:
 +
# Start chroot
 +
chroot_start
 +
 +
# Start and stop applications inside chroot
 +
chroot_command app1
 +
chroot_command app2
 +
...
 +
 +
# Finally close chroot
 +
chroot_stop
 +
 
 +
From this three commands can be recognised, ''chroot_start'', ''chroot_stop'' and ''chroot_command''. Further there would need to be some sort of configuration file to tell chroot directory and other information.
 +
 
 +
 
 +
= Details =
 +
== Base files ==
 +
=== Chroot config ===
All the scripts here use a common configuration file. Copy the sample config file below to $HOME/.config/chroot and edit it according to your setup.
All the scripts here use a common configuration file. Copy the sample config file below to $HOME/.config/chroot and edit it according to your setup.
Line 18: Line 36:
  CHUSER=meego
  CHUSER=meego
-
== Chroot mount ==
+
=== Chroot mount ===
Copy the lines below to ch_mount.sh and give the file execute rights with chmod. The script should be run as a root.
Copy the lines below to ch_mount.sh and give the file execute rights with chmod. The script should be run as a root.
Line 58: Line 76:
  mount -o bind /var/tmp $MOUNTDIR/var/tmp
  mount -o bind /var/tmp $MOUNTDIR/var/tmp
-
== Chroot umount ==
+
=== Chroot umount ===
Copy the lines below to ch_umount.sh and give the file execute rights with chmod. The script should be run as a root.
Copy the lines below to ch_umount.sh and give the file execute rights with chmod. The script should be run as a root.
Line 91: Line 109:
  fi
  fi
-
== Chroot enter ==
+
=== Chroot enter ===
Copy the lines below to ch_enter.sh and give the file execute rights with chmod. The script should be run as a root.
Copy the lines below to ch_enter.sh and give the file execute rights with chmod. The script should be run as a root.
Line 116: Line 134:
  chroot $MOUNTDIR su - $CHUSER -c $1
  chroot $MOUNTDIR su - $CHUSER -c $1
-
== Chroot exit ==
+
=== Chroot exit ===
This section is here only for completeness as there is really no chroot exit: chroot is exited when the started program exits.
This section is here only for completeness as there is really no chroot exit: chroot is exited when the started program exits.
-
= Chroot extras =
+
== Chroot extras ==
Depending on situation more or less work must be done with the chroot. The base setup doesn't e.g access to user home directory.
Depending on situation more or less work must be done with the chroot. The base setup doesn't e.g access to user home directory.
-
== User home ==
+
=== User home ===
User home can be bind mounted inside chroot so that it will be visible there. Copy the lines below to ch_mount_home.sh and give the file execute rights. The script should be run as root. '''Notice! The script mount point is /home inside chroot meaning existing homes will be hidden.'''
User home can be bind mounted inside chroot so that it will be visible there. Copy the lines below to ch_mount_home.sh and give the file execute rights. The script should be run as root. '''Notice! The script mount point is /home inside chroot meaning existing homes will be hidden.'''
Line 148: Line 166:
  mount /dev/mmcblk0p1 $MOUNTDIR/home/user/MyDocs
  mount /dev/mmcblk0p1 $MOUNTDIR/home/user/MyDocs
-
== D-BUS ==
+
=== D-BUS ===
Chroot instructions traditionally instruct how to setup host dbus daemon to be visible inside chroot. This is the preferred way since it minimises the need to run multiple instances of daemons. This is how it would be done:
Chroot instructions traditionally instruct how to setup host dbus daemon to be visible inside chroot. This is the preferred way since it minimises the need to run multiple instances of daemons. This is how it would be done:
Line 172: Line 190:
  chroot $MOUNTDIR /etc/init.d/messagebus start
  chroot $MOUNTDIR /etc/init.d/messagebus start
-
== Graphics acceleration ==
+
=== Graphics acceleration ===
For graphics acceleration to work graphics libraries matching the running kernel has to made available. Copy the lines below to ch_setup_graphics.sh and give the file execute rights with chmod. Script must be run as root.
For graphics acceleration to work graphics libraries matching the running kernel has to made available. Copy the lines below to ch_setup_graphics.sh and give the file execute rights with chmod. Script must be run as root.
Line 211: Line 229:
  done
  done
-
== Pulseaudio ==
+
=== Pulseaudio ===
Pulseaudio has issues with library versions so it's best to use same versions as on the host. Copy the lines below to ch_setup_pulseaudio.sh and give the file execute rights with chmod.
Pulseaudio has issues with library versions so it's best to use same versions as on the host. Copy the lines below to ch_setup_pulseaudio.sh and give the file execute rights with chmod.

Revision as of 11:00, 26 May 2010

Under construction

Contents

About

The chroot script shown here performs everything in one script opening shell inside chroot. This makes the script very simple but it also results in shortcomings. Script doesn't for instance help in entering already existing chroot but forces user to do it manually. This divides chroot entering into seperate steps allowing more flexibility.

Big picture

Ideally everything should go simply:

# Start chroot
chroot_start

# Start and stop applications inside chroot
chroot_command app1
chroot_command app2
...

# Finally close chroot
chroot_stop

From this three commands can be recognised, chroot_start, chroot_stop and chroot_command. Further there would need to be some sort of configuration file to tell chroot directory and other information.


Details

Base files

Chroot config

All the scripts here use a common configuration file. Copy the sample config file below to $HOME/.config/chroot and edit it according to your setup.

# Chroot configuration file

# Path to chroot loopback image
IMAGE=/path/to/image

# Mount point
MOUNTDIR=/mnt/point

# User account inside chroot
CHUSER=meego

Chroot mount

Copy the lines below to ch_mount.sh and give the file execute rights with chmod. The script should be run as a root.

#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$IMAGE" = "x" ]; then
  echo "ERROR: Chroot loopback image is not defined!"
  exit
elif [ ! -f $IMAGE ]; then
  echo "ERROR: Chroot loopback image ($IMAGE) not found"
  exit
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

mount -o loop $IMAGE $MOUNTDIR

# Make devices available inside chroot
mount -o bind /proc $MOUNTDIR/proc
mount -o bind /sys $MOUNTDIR/sys
mount -o bind /dev $MOUNTDIR/dev

# This should make X work
mount -t devpts none $MOUNTDIR/dev/pts
mount -o bind /tmp $MOUNTDIR/tmp

# Share temp
mount -o bind /var/tmp $MOUNTDIR/var/tmp

Chroot umount

Copy the lines below to ch_umount.sh and give the file execute rights with chmod. The script should be run as a root.

#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

umount $MOUNTDIR/var/tmp
umount $MOUNTDIR/tmp
umount $MOUNTDIR/dev/pts
umount $MOUNTDIR/dev
umount $MOUNTDIR/sys
umount $MOUNTDIR/proc

LOOP_DEVICE=`grep $MOUNTDIR /proc/mounts | awk '{ print $1 }'`

umount $MOUNTDIR

if [ "x$LOOP_DEVICE" != "x"]; then
  losetup -d $LOOP_DEVICE
fi

Chroot enter

Copy the lines below to ch_enter.sh and give the file execute rights with chmod. The script should be run as a root.

#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

if [ "x$CHUSER" = "x" ]; then
  echo "ERROR: User account inside chroot is not defined!"
  exit
fi

chroot $MOUNTDIR su - $CHUSER -c $1

Chroot exit

This section is here only for completeness as there is really no chroot exit: chroot is exited when the started program exits.

Chroot extras

Depending on situation more or less work must be done with the chroot. The base setup doesn't e.g access to user home directory.

User home

User home can be bind mounted inside chroot so that it will be visible there. Copy the lines below to ch_mount_home.sh and give the file execute rights. The script should be run as root. Notice! The script mount point is /home inside chroot meaning existing homes will be hidden.

#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

# This is the general way
#mount -o bind /home/user $MOUNTDIR/home/user

# In Fremantle it could be done in this way
mount /dev/mmcblk0p2 $MOUNTDIR/home
mount /dev/mmcblk0p1 $MOUNTDIR/home/user/MyDocs

D-BUS

Chroot instructions traditionally instruct how to setup host dbus daemon to be visible inside chroot. This is the preferred way since it minimises the need to run multiple instances of daemons. This is how it would be done:

mount -o bind /var/lib/dbus /path/to/chroot/var/lib/dbus

In some cases using host dbus doesn't work so nicely. In Maemo Fremantle some services have been modified so that they don't work as expected when mounted inside chroot. Answer is to start an own dbus daemon inside chroot. Copy the lines below to ch_start_dbus.sh and the file execute rights with chmod. Script must be run as root.

#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

chroot $MOUNTDIR /etc/init.d/messagebus start

Graphics acceleration

For graphics acceleration to work graphics libraries matching the running kernel has to made available. Copy the lines below to ch_setup_graphics.sh and give the file execute rights with chmod. Script must be run as root.

#!/bin/sh

GRAPHICS_LIBS="
 /usr/lib/libIMGegl.so
 /usr/lib/libglslcompiler.so
 /usr/lib/libpvrPVR2D_DRI2WSEGL.so
 /usr/lib/libsrv_um.so
 /usr/lib/libOpenVGU.so
 /usr/lib/libpvrPVR2D_BLITWSEGL.so
 /usr/lib/libpvrPVR2D_FRONTWSEGL.so
 /usr/lib/libpvrPVR2D_FLIPWSEGL.so
 /usr/lib/libpvrPVR2D_X11WSEGL.so
 /usr/lib/libOpenVG.so
 /usr/lib/libEGL.so
 /usr/lib/libPVRScopeServices.so
 /usr/lib/libpvr2d.so
 /usr/lib/libGLESv2.so"

CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

for lib in ${GRAPHICS_LIBS}; do
  cp ${lib} ${MOUNTDIR}/usr/lib/
done

Pulseaudio

Pulseaudio has issues with library versions so it's best to use same versions as on the host. Copy the lines below to ch_setup_pulseaudio.sh and give the file execute rights with chmod.

#!/bin/sh
PULSE_LIBS="
 /usr/lib/libpulse-mainloop-glib.so.0
 /usr/lib/libpulse-mainloop-glib.so.0.0.4
 /usr/lib/libpulse-simple.so.0
 /usr/lib/libpulse-simple.so.0.0.2
 /usr/lib/libpulse.so.0
 /usr/lib/libpulse.so.0.8.0
 /usr/lib/libpulsecommon-0.9.15.so
 /usr/lib/libpulsecore-0.9.15.so"

CONFIG_FILE=${HOME}/.config/chroot

if [ -f $CONFIG_FILE ]; then
 . $CONFIG_FILE
fi

if [ "x$MOUNTDIR" = "x" ]; then
  echo "ERROR: Chroot mount directory is not defined!"
  exit
elif [ ! -d $MOUNTDIR ]; then
  echo "ERROR: Chroot mount directory ($MOUNTDIR) not found"
  exit
fi

for lib in ${PULSE_LIBS}; do
  cp ${lib} chroot/usr/lib/
done

# Lets also copy couple of pulseaudio executables
PULSE_BINS="
 /usr/bin/pacat
 /usr/bin/pacmd
 /usr/bin/pactl
 /usr/bin/padsp
 /usr/bin/paplay
 /usr/bin/parec
 /usr/bin/pasuspender"

for bin in ${PULSE_BINS}; do
  cp ${bin} /usr/bin/
done
Personal tools