Installing apps in a 32-bit chroot in AMD64 Debian system

Posted by Utumno on Tue 21 Feb 2006 at 09:54

So you switched to the AMD64 architecture, installed the 'pure64'; flavour of Debian on it? Well, get prepared for some problems: no flashplugin for Firefox, no win32 codecs for MPlayer, no OpenOffice.

I couldn't care less for the flashplugin, OpenOffice I've got on my laptop and I hardly use it, but a complete, custom-compiled MPlayer is a must. Here's a way to install it along with the win32 and RealPlayer codecs, LIVE.com streaming support, and more.

One way - they say - is to install the ia32-libs, but I wanted to be all clean about it and use the arguably harder 'chroot' method. This way, one can achieve a modular, easily upgradeble system. Both 64- and 32- bit apps are separated from each other, and all users can - compeletely transparently - call the 32-bit apps from within their 64-bit text consoles and DEs.

1. Install the chroot

Minimal Debian system, although I ended up with about 400 MB of stuff in it.

1.1) Create a new empty directory:

$ mkdir /var/sid-386-chroot
1.2) Make sure you've got the 'debootstrap' package installed and install Debian Sid, i386 version, base system to the newly created directory:
$ debootstrap --arch i386 sid /var/sid-386-chroot http://ftp.debian.org/debian/
That will pull quite a few packages. Once it is done, you should see a normal Debian root directory tree inside.

1.3) Add the library path of your chroot to your /etc/ld.so.conf: ( I mean your original /etc/ld.so.conf, not the one from the chroot )

/usr/X11R6/lib
# chroot i386 system libs
/var/sid-386-chroot/lib
/var/sid-386-chroot/usr/lib
/var/sid-386-chroot/usr/X11R6/lib
/var/sid-386-chroot/usr/local/lib

1.4) You also need a link to your 32bit linker in the /lib path:

$ cd /lib
$ ln -s /var/sid-386-chroot/lib/ld-linux.so.2 ld-linux.so.2
1.5) Now run ldconfig to update your linker's cache:
$ ldconfig
1.6) To run an application inside the chroot you will need some parts of your 64bit system tree inside the chroot. This can be achieved with a bind mount. In this example we will bind /tmp to the chroot for the X11 sockets which are in /tmp, and bind /home to access the home directories from within the chroot. You may also want to mount the /proc and /sys filesystems within the chroot. Edit your fstab and add the required paths:
# ia32 chroot
/home           /var/sid-386-chroot/home none   bind            0       0
/tmp            /var/sid-386-chroot/tmp  none   bind            0       0
/proc           /var/sid-386-chroot/proc proc   defaults        0       0
/dev            /var/sid-386-chroot/dev  none   bind            0       0
1.7) Then mount them:
$ mount /var/sid-386-chroot/home
$ mount /var/sid-386-chroot/tmp
$ mount /var/sid-386-chroot/proc
$ mount /var/sid-386-chroot/dev
WARNING: The above means that should you ever decide to remove the chroot:
$ rm -rf /var/sid-386-chroot/
then ALL the bind-mounted partitions, including your $HOME, are also going to be deleted!
So make sure to unmount them first.
1.8) You will also need to set up the relevant users in the chroot. Copy your /etc/passwd, /etc/shadow , /etc/hosts and /etc/group files to the chroot.
1.9) At this point you should be able to run applications within the chroot. Change to your chroot (you must be root to do this):
$ chroot /var/sid-386-chroot
1.10) Try to run something:
$ cat /etc/apt/sources.list
The above command should give you the contents of 32-bit sources.list (doh!). Now it's good time to edit it if you are planning on installing some more stuff there (Skype?)

1.11) To get out of the chroot back to your 64-bit main system, simply type
$ exit

2. Compile and install 32-bit MPlayer into the chroot

2.1) 'chroot' to your chroot:
chroot /var/sid-386-chroot
From this point on, we're going to do all the downloading and compiling inside the chroot.
2.2) Install quite a few packages we're gonna need:
$ apt-get install libogg0 libogg-dev libvorbis0a libvorbis-dev vorbis-tools libpng12-0 libpng12-dev liblogfile-rotate-perl libconfhelper-perl debhelper fakeroot gcc g++ libgtk1.2 libgtk1.2-dev svgalibg1 svgalibg1-dev libsdl1.2-dev libaa1 libaa1-dev libxv1 libxv-dev
2.3) Also, while at it, install some other packages that I always find useful:
$ apt-get install cvs vim bzip2
2.4) Perl is going to spit errors about locale being unset. Shut it up by adding export LC_ALL=C line to /root/.bashrc and source the file:
$ . ~/.bashrc
2.5) Download MPlayer's sources:
$ cd /home/leszek/
$ mkdir mplayer; cd mplayer
$ cvs -d:pserver:anonymous@mplayerhq.hu:/cvsroot/mplayer login
Password: [hit enter]
$ cvs -z3 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/mplayer co -P main
2.6) download FFMPEG's sources:
$ cvs -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg login
Password: [hit enter]
$ cvs -z3 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg
A directory named 'ffmpeg' with subdirectories named 'libavcodec' and 'libavutil' inside will be created. Copy (symbolic linking does NOT suffice) these 2 subdirectories into the MPlayer source tree.
2.7) Create a directory where we're gonna keep our binary codecs:
$ mkdir /usr/local/lib/codecs
2.8) Get Win32 codecs 'essential-YYYYMMDD.tar.bz2' - grab the latest version "essential codecs package" from Mplayer HQ Download
2.9) Unpack and move the codecs to the right directory:
$ mv essential-YYYYMMDD.tar.bz2 /usr/local/lib
$ cd /usr/local/lib
$ tar xjvf essential-YYYYMMDD.tar.bz2
$ mv essential-YYYYMMDD/* codecs
$ rm -rf essential-YYYYMMDD*
2.10) Same story with the LIVE streaming codecs: get them from here
2.11) Unpack and install:
$ cd /usr/local/lib
$ tar -xvzf live.2005.06.16.tar.gz
$ cd live/
$ ./genMakefiles linux
$ make
2.12) QuickTime codecs: download QuickTime DLL pack from http://www.mplayerhq.hu/MPlayer/releases/codecs/
Unpack and copy them to /usr/local/lib/codecs.
2.13) Download Real codecs from http://www.mplayerhq.hu/MPlayer/releases/codecs/ and extract them to the /usr/local/lib/codecs directory.
2.14) Get MPlayer's UserConf from here, become your user, copy it to your home directory and unpack:
$ tar -xvvf mplayer-user-conf.tar

This will create the ~/.mplayer directory including a skin (neutron), arial size 18 font, and config files.

In line 27 of the ~/.mplayer/gui.conf file, change: font_name = "/home/lyz/.mplayer/font/font.desc" to reflect your username.

2.15) Move MPlayer's sources to /usr/src:
$ mv /home/leszek/mplayer/ /usr/src/
$ cd /usr/src/mplayer/main/
2.16) Compile:
$ DEB_BUILD_OPTIONS="-disable-runtime-cpudetection -enable-gui -enable-menu -disable-rtc -enable-live -with-livelibdir=/usr/local/lib/live" fakeroot debian/rules binary
2.17) After some 8 minutes ( on my Sempron 3000+ with 512 DDR400 and a SATA HD ) a package mplayer_1.0cvs_i386.deb will appear in /usr/src/mplayer. Install it:
$ dpkg -i mplayer_1.0cvs_i386.deb

Voilla! You can now run your mplayer from within your 32-bit chroot. Dont forget to set Video and Audio outputs ( Xv and ALSA in my case ).

3. Make it work transparently from within your 64-bit system

3.1) Get out of the chroot and install the dchroot package:
$ apt-get install dchroot
3.2) Edit /etc/dchroot.conf:
# sid386 chroot
sid386    /var/sid-386-chroot
3.3) Now you should be able to run commands inside the chroot as normal user:
$ dchroot -c sid386 -d gmplayer
3.4) Add a wrapper script to ease things and be able to call 'mplayer' and 'gmplayer' transparently from the command line: in /usr/local/bin create the following script, name it 'do_chroot' and chmod it to 755:
#!/bin/sh
ARGS=""
for i in "$@" ; do
        ARGS="$ARGS '$i'"
done

exec dchroot -c sid386 -d -q "`basename $0`" "$ARGS"
3.5) Last step : symbolic links to our script:
$ cd /usr/local/bin
$  ln -s do_dchroot mplayer
$  ln -s do_dchroot gmplayer
$  ln -s do_dchroot mencoder
3.6) Now, being in the 64-bit system, you can run your 32-bit mplayer like this:
$ /usr/local/bin/mplayer
or better yet, simply
$ mplayer
( /usr/local/bin is searched before /usr/local! ) It all works because the symbolic link /usr/local/bin/mplayer points to /usr/local/bin/do_chroot, which checks its name ( in this case 'mplayer' ), appends all the arguments you might have supplied, and uses dchroot to launch the corresponding mplayer binary from the 32-bit chroot.

Of course, should you ever install any other 32-binary in the chroot , you also have to add new link to make it work from the 64-bit part.

3.7) Finally, the true reason for all this:
$ mencoder -oac lavc -ovc lavc -of mpeg -mpegopts format=dvd -vf scale=720:480, harddup -srate 48000 -af lavcresample=48000 -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:\
vbitrate=5000:keyint=18:acodec=ac3:abitrate=192:aspect=16/9 -ofps 30000/1001 -o movie.mpg movie.avi
And 'movie.avi' gets recoded for NTSC DVD, which you can enjoy watching on your DVD player :)
( mplayer-1.0-pre6 from Ubuntu Breezy does not have the 'mpegopts' flag yet, and 1.0-pre7 from Dapper is uninstallable on Debian Sid because of dependence on X.Org 7.0 )

4. Most of the info has been shamelessly copied from the following sources

a) MPlayer compilation and setup:


b) chroot setup:


This article can be found online at the Debian Administration website at the following bookmarkable URL (along with associated comments):

This article is copyright 2006 Utumno - please ask for permission to republish or translate.