Running Debian in a chroot

From Internet Tablet Talk

Contents

Running Debian in a chroot

Rationale

Debian has a huge number of pre-compiled applications that run on the ITT. The problem is that they use a different kernel and different library versions, so you can't simply add the Debian repositories to your Application Manager and install the applications that interest you; you will almost surely destroy your operating system as the dependencies of almost every package will try to "upgrade" core components of your operating system.

Running Debian apps in a "chroot" allows the user to run applications from two different operating systems side-by-side. They can share the same desktop, and, for most purposes, they will seem to be running in the same OS. They have access to all of the same hardware and connections (Internet, Bluetooth, etc).

This method of running Debian does not require the same "level of commitment" as booting to Debian does; no custom initfs or bootmenu is required. It is a great way to test out different applications and see if they are worth any effort.

Howto

PLEASE NOTE: This Wiki article is outdated. While the basic principles remain sound, the scripts have been significantly improved. All of the scripts are available for download here, and a package ("Easy Debian") that installs the scripts for you (and lets you download a Debian image file with pre-installed apps) is here.

Prerequisites

  • Root access
  • A large (>1 GB free) ext2 or ext3 partition
  • EITHER:
    • A non-Hildon window manager; PenguinBait's KDE is your best bet, because it has many hacks to make non-tablet apps work with the features and limitations of the tablets, such as hardware keys, the lack of a right-click, and small screen size.
    • In case you prefer to stick to the vanilla Hildon window manager, you better apply three hacks which allow right mouse key functionality (on the N810), maximization of non-hildon windows and movable dialog windows - with those, Hildon works allright
    • If you have a N800, you need a virtual keyboard (like XVKBD). The n810 slide-on keyboard works perfectly with chrooted apps under the Hildon window manager, so no external keyboard is needed.

Installing Debian

  • Download the latest Debian package from Debian#Download.
  • As root, untar the package into (a) a folder on your large ext2/3 partition or (b) into a prepared partition as per Debian#Installation

Before running the chroot script

Before running the script below, make sure you back up your system files in the Debian directory.

The "cp" lines in the script below overwrite fairly important system files that may break your bootable Debian and will cause problems if you are using the beta3 bootable Debian. I would recommend doing the following (after mounting your partition to /opt), but before running the full chroot script

chroot /opt
cd /etc
cp resolv.conf resolv.conf.deboot
cp hosts hosts.conf.deboot
cp group group.deboot
cp passwd passwd.deboot
exit

When it is time to boot into Debian, you simply reverse the process, and copy the .deboot versions of the files back over the main versions.

For instance, the mpd music player daemon installed in the beta3 Debian has an mpd user that is lost when you copy your /etc/passwd file from OS2008, and apt-get install complains bitterly about this missing user. I found the best thing to do was put back my .deboot backup files and do an "apt-get remove --purge mpd" to maintain my sanity.

The chroot script

  • Create a chroot script, like the one below. This script assumes that Debian is in the root of its own partition, mmcblk0p4. If it is in a folder in an already-mounted partition, then the mounting section is not required. The script also assumes an N800, with two card slots, mmc1 and mmc2. The $* in the chroot allows you to run this script with an application name as a parameter, like 'debian epiphany' (to run the epiphany-webkit browser)
echo "Setting up the chroot..."
export CHROOT=/opt
###
#mount the Debian partition.
insmod /mnt/initfs/lib/modules/2.6.21-omap1/mbcache.ko
insmod /mnt/initfs/lib/modules/2.6.21-omap1/ext2.ko
mount /dev/mmcblk0p4 $CHROOT -o noatime
###
# Make the tablet's devices available to Debian.
mount -o bind /dev $CHROOT/dev
mount -o bind /proc $CHROOT/proc
###
# Gentoo wiki says this will make X work.
mount -t devpts none $CHROOT/dev/pts
mount -o bind /tmp $CHROOT/tmp
###
# Mount various external devices (SD cards, USB devices)
mount -o bind /media $CHROOT/media
mount -o bind /media/mmc1 $CHROOT/media/mmc1
mount -o bind /media/mmc2 $CHROOT/media/mmc2
mount -o bind /media/usb $CHROOT/media/usb
###
# Mount the user's home directory
mount -o bind /home/user $CHROOT/home/user
###
# Make the Internet work.
cp /etc/resolv.conf $CHROOT/etc/resolv.conf
cp /etc/hosts $CHROOT/etc/hosts
###
# Make permissions work.
cp /etc/group $CHROOT/etc/group
cp /etc/passwd $CHROOT/etc/passwd
###
# Custom prompt. Reduces confusion.
export PS1="[\u@Debian: \w]"
###
# Actually chroot. 
echo "Everything set up, running chroot..."
chroot $CHROOT $*
  • Make the script executable (chmod +x debian)
  • Run the script as root. If you give it a parameter, the given app should start. If no application is given, you should get the Debian prompt.
  • Put the script in /sbin since it needs to be run by root.
  • Don't put the script in /usr/bin - that causes problems

Running apps as a user

You can run Debian apps as a user (rather than as "root" which causes lots of problems for various apps), and even make menu items for Debian apps.

Choose one of the following three methods for running apps as a user. All methods use the "common" portion below.

1: sudo method

Thanks to Benson for this method. It is superior to the ssh method.

As root, use visudo to add the following line to your /etc/sudoers file. Benson says, "This is only to be done using visudo; manually editing the sudoers file could leave it in an invalid state, which could result in a reboot loop. visudo checks the syntax when you're done editing, and throws you back till you get it right."

user ALL = NOPASSWD: ALL

...and now the user "user", logged in on any machine, can execute any command without authentication.

(optional)

As root, make a one-line script, /usr/bin/debbie

  • This script assumes the above chroot script is named /root/debian
sudo /root/debian hilda $*

Make the script executable (chmod +x /usr/bin/debbie)

2: gainroot method

Thanks to debernardis for this method.

If you prefer to use gainroot for root access, you can make a one-line script, /usr/bin/debbie like the following:

#!/bin/sh

if [ `id -u` != 0 ] ; then
#if not already root, call itself as root
       sudo gainroot <<EOF
exec $0 $*
EOF
       exit
fi

exec /home/user/MyDocs/bin/debian hilda $*
  • This script assumes the above chroot script is named /root/debian
3: ssh method

You will need to have ssh installed, and you will need to know how to set up passwordless ssh using ssh-keygen. (outside the scope of this howto)

As root, make a one-line script, /usr/bin/debbie

  • This script assumes the above chroot script is named /root/debian
ssh root@localhost "/root/debian hilda $*"

Make the script executable (chmod +x /usr/bin/debbie)

common portion
  • Whether you use sudo, gainroot, or ssh, you need this part to run apps as user instead of root.

Assuming your chroot will be in /opt, make a script called /opt/usr/bin/hilda

export DISPLAY=:0
echo running $*
su user -c "$*"

Make the script executable (chmod +x /opt/usr/bin/hilda)

Now you can run, as user, the following command:

debbie hilda abiword /home/user/MyDocs/demo.doc

Making a menu icon for Debian apps

As root, copy an existing .desktop menu icon file.

cp /usr/share/applications/hildon/mplayer.desktop /usr/share/applications/hildon/abiword-deb.desktop

Edit the new .desktop file to look something like this (Changing the name, etc. of course):

[Desktop Entry]
Encoding=UTF-8
Name=Debian AbiWord
Exec=/usr/bin/debbie abiword
Icon=qgn_list_btno_gen_computer
X-Osso-Type=application/x-executable
X-HildonDesk-ShowInToolbar=true

All times are GMT -4. The time now is 01:40 PM.