(→Chroot config) |
(→Chroot enter) |
||
| Line 94: | Line 94: | ||
== 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. | ||
| + | [[Media:ch_enter.sh]] | ||
#!/bin/sh | #!/bin/sh | ||
Under construction
The chroot script shown 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.
Contents |
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
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
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
Copy the lines below to ch_enter.sh and give the file execute rights with chmod. The script should be run as a root. Media:ch_enter.sh
#!/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
This section is here only for completeness as there is really no chroot exit: chroot is exited when the started program exits.
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 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
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
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 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