m |
(wikify section headings, categorize) |
||
| (7 intermediate revisions not shown) | |||
| Line 1: | Line 1: | ||
'''Under construction''' | '''Under construction''' | ||
| - | + | The [[ARM/N900/Install/chroot|chroot script]] 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. | |
| - | The | + | |
| + | == Big picture == | ||
| - | |||
Ideally everything should go simply: | Ideally everything should go simply: | ||
# Start chroot | # Start chroot | ||
| Line 19: | Line 19: | ||
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. | 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 == | ||
| - | |||
Time to turn idea into practise. [[#Base_files|Base files]] section collects together the chroot start/stop/run_command scripts mentioned earlier. [[#Chroot_extras|Chroot extras]] continues with some nice to have extra stuff like graphics acceleration. | Time to turn idea into practise. [[#Base_files|Base files]] section collects together the chroot start/stop/run_command scripts mentioned earlier. [[#Chroot_extras|Chroot extras]] continues with some nice to have extra stuff like graphics acceleration. | ||
| - | == Base files == | + | After getting the files here chroot usage should go as: |
| - | === Chroot config === | + | # Edit chroot configuration |
| - | All the scripts here use a common configuration file. Copy the sample config file below to $HOME/.config/chroot.cfg and edit it according to your setup. | + | vi .config/chroot.cfg |
| + | |||
| + | # Start chroot | ||
| + | ch_mount.sh | ||
| + | |||
| + | # Run command inside chroot | ||
| + | ch_enter.sh | ||
| + | ch_enter.sh vim | ||
| + | |||
| + | # Close started applications | ||
| + | |||
| + | # Stop chroot | ||
| + | ch_umount.sh | ||
| + | |||
| + | === Base files === | ||
| + | |||
| + | ==== Chroot config ==== | ||
| + | |||
| + | All the scripts here use a common configuration file. Copy the sample config file below to '''$HOME/.config/chroot.cfg''' and edit it according to your setup. | ||
# Chroot configuration file | # Chroot configuration file | ||
| Line 31: | Line 49: | ||
# Path to chroot loopback image | # Path to chroot loopback image | ||
IMAGE=/path/to/image | IMAGE=/path/to/image | ||
| + | |||
| + | # Offset from the beginning of image. Needed for | ||
| + | # images that contain entire harddrive not single partition | ||
| + | # OFFSET=0 | ||
# Mount point | # Mount point | ||
| Line 38: | Line 60: | ||
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. | ||
#!/bin/sh | #!/bin/sh | ||
| Line 64: | Line 87: | ||
fi | fi | ||
| - | + | if [ "x$OFFSET" = "x" ]; then | |
| + | IM_OFFSET=0 | ||
| + | else | ||
| + | IM_OFFSET=$OFFSET | ||
| + | fi | ||
| + | |||
| + | |||
| + | losetup /dev/loop0 ${IMAGE} -o ${IM_OFFSET} | ||
| + | mount /dev/loop0 ${MOUNTDIR} | ||
# Make devices available inside chroot | # Make devices available inside chroot | ||
| Line 78: | Line 109: | ||
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. | ||
#!/bin/sh | #!/bin/sh | ||
| Line 111: | Line 143: | ||
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. | ||
#!/bin/sh | #!/bin/sh | ||
| Line 134: | Line 167: | ||
fi | fi | ||
| - | chroot $MOUNTDIR su - $CHUSER | + | CH_COMMAND="" |
| + | if [ "x$1" != "x" ]; then | ||
| + | CH_COMMAND="-c $1" | ||
| + | fi | ||
| + | |||
| + | chroot $MOUNTDIR su - $CHUSER $CH_COMMAND | ||
| - | === 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.''' | ||
#!/bin/sh | #!/bin/sh | ||
| Line 168: | Line 208: | ||
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: | ||
mount -o bind /var/lib/dbus /path/to/chroot/var/lib/dbus | 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. | + | 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 | #!/bin/sh | ||
| Line 192: | Line 233: | ||
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. | ||
#!/bin/sh | #!/bin/sh | ||
| Line 231: | Line 273: | ||
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. | ||
#!/bin/sh | #!/bin/sh | ||
| Line 276: | Line 319: | ||
cp ${bin} /usr/bin/ | cp ${bin} /usr/bin/ | ||
done | done | ||
| + | |||
| + | [[Category:N900]] | ||
Under construction
The chroot script 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.
Contents |
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.
Time to turn idea into practise. Base files section collects together the chroot start/stop/run_command scripts mentioned earlier. Chroot extras continues with some nice to have extra stuff like graphics acceleration.
After getting the files here chroot usage should go as:
# Edit chroot configuration vi .config/chroot.cfg # Start chroot ch_mount.sh # Run command inside chroot ch_enter.sh ch_enter.sh vim # Close started applications # Stop chroot ch_umount.sh
All the scripts here use a common configuration file. Copy the sample config file below to $HOME/.config/chroot.cfg and edit it according to your setup.
# Chroot configuration file # Path to chroot loopback image IMAGE=/path/to/image # Offset from the beginning of image. Needed for # images that contain entire harddrive not single partition # OFFSET=0 # 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.cfg
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
if [ "x$OFFSET" = "x" ]; then
IM_OFFSET=0
else
IM_OFFSET=$OFFSET
fi
losetup /dev/loop0 ${IMAGE} -o ${IM_OFFSET}
mount /dev/loop0 ${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.cfg
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.
#!/bin/sh
CONFIG_FILE=${HOME}/.config/chroot.cfg
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
CH_COMMAND=""
if [ "x$1" != "x" ]; then
CH_COMMAND="-c $1"
fi
chroot $MOUNTDIR su - $CHUSER $CH_COMMAND
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.cfg
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.cfg
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.cfg
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.cfg
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