Miscellaneous:32BitChroot

(Difference between revisions)
Jump to: navigation, search
Wdp (Talk | contribs)
(New page: '''This Article is not finished! Talk to "wdp" on irc if you have any questions until its done.''' ---- This is an Article about running a 32bit Chroot of Lunar Linux within 64bit Lunar L...)
Newer edit →

Revision as of 10:22, 28 August 2010

This Article is not finished! Talk to "wdp" on irc if you have any questions until its done.


This is an Article about running a 32bit Chroot of Lunar Linux within 64bit Lunar Linux. It's getting updated sometimes and should work on different Distributions, too.

Contents

Lunar Linux 32 Bit Chroot within native 64 Bit Environment

Last Update of this Document: 11.08.2009 Changelog:

  • (11.08.09) Added some Information (Thanks to beko)
  • (10.07.09) 3D Acceleration howto was wrong, corrected thx to Raedwulf for pointing out :)
  • (10.07.09) I rewrote some parts to a hopefully nicer english.

Originally this Document was written to provide/explain an easy way to setup a 32 Bit Chroot using Lunar Linux. Of course you could use every other Distribution instead of Lunar Linux to do this. In this Document i will show how to use Lunar Linux for a 32 Bit Chroot.

Contents

  • <a href="#install">Installation</a>
    • <a href="#why">Why</a>
    • <a href="#req">Requirements</a>
    • <a href="#switchroot">Switch to root (For the Dummies)</a>
    • <a href="#setupenvironment">Setup Environment</a>
    • <a href="#test1">Test #1</a>
    • <a href="#test2">Test #2</a>
    • <a href="#updatechroot">Updating the Chroot-System</a>
  • <a href="#enhance">Enhancing your Chroot Installation</a>
    • <a href="#x11">X11</a>
    • <a href="#3daccel">3D Acceleration</a>
    • <a href="#homedir">Home Directory</a>
    • <a href="#initscript">Init Script</a>
    • <a href="#enterchrootscript">Entering Chroot - Script</a>
  • <a href="#applications">Applications</a>
    • <a href="#fonts">Fonts</a>
    • <a href="#skype">Skype</a>
  • <a href="#usefuldoc">Useful Documentation</a>

<a name="install"></a>

Installation

<a name="why"></a>

Why

Because. As Lunar Linux is 32bit or 64bit and not multilib, you have to use a chroot for 32bit. I really dislike this but nobody wanted to put time into multilib yet just because of a few guys and as every day some more apps work using 64bit, multilib will probably not be that useful at all. Anyway, for those of you who want to use 32bit apps within the 64bit environment, this little howto should help a lot.

<a name="req"></a>

Requirements

Having an image of a running system could help a lot and reduce the needed time amount. If you like you can use an Image i created originally for use as OpenSolaris Zone. You could also create your own 32bit image (just install 32bit linux using a vm or something and tar cjvf the whole system, without proc, sys, dev..). Anyway, i will explain here how to do it using my image.

<a name="switchroot"></a>

Switch to root (For the Dummies)

Of course you need to be root to run most of the following commands. If you don't know how to switch to the super user (root) in a Linux System you don't want to deal with this Howto. First learn some Basics. However. You can switch to the super user using the command:

wdp@yulivee ~ $ su

<a name="setupenvironment"></a>

Setup Environment

I installed my Chroot within /usr/local/32bit you might want to change that, just replace the "export" line to do so and don't forget to replace the path in the config files i'm later showing. The following lines will create the directory for your chroot, download my image and unpack it within that directory, copy over some files from the host to the chroot (like users, passwords, etc) and finally mount some directories from the host within the chroot (like dev, proc, sys, tmp).

wdp@yulivee ~ $ export OC="/usr/local/32bit"
wdp@yulivee ~ $ mkdir -p $OC
wdp@yulivee ~ $ cd $OC
wdp@yulivee ~ $ wget http://www.jeanbruenn.info/downloads/osol_lunar_zone.tar.gz
wdp@yulivee ~ $ tar -xzvf osol_lunar_zone.tar.gz
wdp@yulivee ~ $ cp /etc/hosts $OC/etc/hosts
wdp@yulivee ~ $ cp /etc/nsswitch.conf $OC/etc/nsswitch.conf
wdp@yulivee ~ $ cp /etc/passwd $OC/etc/passwd
wdp@yulivee ~ $ cp /etc/shadow $OC/etc/shadow
wdp@yulivee ~ $ cp /etc/resolv.conf $OC/etc/resolv.conf
wdp@yulivee ~ $ mount -o bind /dev $OC/dev
wdp@yulivee ~ $ mount -o bind /dev/pts $OC/dev/pts
wdp@yulivee ~ $ mount -o bind /proc $OC/proc
wdp@yulivee ~ $ mount -o bind /sys $OC/sys
wdp@yulivee ~ $ mount -o bind /tmp $OC/tmp

<a name="test1"></a>

Test #1

Within the chroot:

wdp@yulivee ~ $ gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../configure –host=i686-pc-linux-gnu –enable-languages=c++,fortran –prefix=/usr –infodir=/usr/share/info –mandir=/usr/share/man –enable-__cxa_atexit –enable-threads –disable-nls –enable-target-optspace –with-gnu-ld –with-system-zlib –enable-shared
Thread model: posix
gcc version 4.2.4

Within the host:

wdp@yulivee ~ $ gcc -v
Using built-in specs.
Target: x86_64-pc-linux-gnu
Configured with: ../configure –host=x86_64-pc-linux-gnu –enable-languages=c++,fortran –prefix=/usr –infodir=/usr/share/info –mandir=/usr/share/man –enable-__cxa_atexit –enable-threads –disable-nls –enable-target-optspace –with-gnu-ld –with-system-zlib –enable-shared –disable-multilib
Thread model: posix
gcc version 4.2.4

<a name="test2"></a>

Test #2

Within the chroot:

wdp@yulivee ~ $ uname -m
i686

Within the host:

wdp@yulivee ~ $ uname -m
x86_64

as you can see - the chroot picks a not-64bit-gcc and uname -m returns not 64bit within the chroot - It's working ;-)

<a name="updatechroot"></a>

Updating the Chroot-System

My Image might be quite old and it's usually good to have the chroot environment as up to date as the host is. Run the following commands to get new packages/modules:

wdp@yulivee ~ $ lin moonbase; lin theedge

Now you can run "lunar" and set some settings. The most important Settings might be the Optimizations. You can either go through: Option -> Optimize Architecture or you run "lunar optimize" at the console. After you've done configuring your lunar installation run:

wdp@yulivee ~ $ lunar renew

to update your whole installation. Get a cup of tea or coffee, this might take a while depending on your box and resources. At this state you should have a running 32 Bit Chroot. However we will still need to enhance this a bit. You want for sure X11 within the Chroot.

<a name="enhance"></a>

Enhancing your Chroot Installation

<a name="x11"></a>

X11

We mounted /tmp from the host to /tmp inside the chroot already. This way we can use the X11 Socket to connect applications within the chroot to our running x11-server within the host. You could also, if this isn’t possible, use TCP Connections. But they come usually with overhead and thus performance of x11 stuff will be bad. Anyway. You don’t need a whole X11-Server within the chroot, just a few x11 libs. Let’s go:

wdp@linux32 ~ $ lin -cr libX11 fixesproto libXxf86vm libXt libXmu libXi mesa-lib xclock

This will install some X11 staff and libraries which are needed. You need now to allow X11-Unix-Socket Connections. Within the Chroot Environment edit your /etc/hostname and set "linux32" or something similar, remember this hostname. On the host type in: xhost +local:linux32 (Replace linux32 with the hostname you've set) or you could use "xhost +" which is insecure. Now you can test your X11 using xclock within your Chroot:

wdp@linux32 ~ $ export DISPLAY=”:0.0″
wdp@linux32 ~ $ xclock

You see the Clock? Fine it worked :)

<a name="3daccel"></a>

3D Acceleration

If you want to run 32 Bit Games or Emulators like wine which don't work in native 64 Bit you might want to have 3D Acceleration. As i got an nvidia graphic card i will show how to setup 3D Acceleration with nvidia cards, for other cards it should be similar, you just need to replace nvidia by another driver. The important thing about this is that you have to use exactly the same driver version within your chroot than the driver version in your host, otherwise it will simply not work. Thats why you should try to keep both installations as up to date as possible.

It is really important that you got your kernel files and kernel header from the host, also within the chroot. you can do that by copy (cp) from the host to the chrooted environment or you simply copy over the current kernel configuration to the chroot and compile the kernel within the chroot again. (i will explain this step better when i got more time) - Keep also in mind, by default the kernel is on hold within the lunar installation. you might want to "unhold" it using lvu.

On the Host check which NVIDIA drivers you got installed and what version it is:

wdp@yulivee ~ $ lvu installed NVIDIA
NVIDIA is not installed
wdp@yulivee ~ $ lvu installed NVIDIA-beta
185.18.14
wdp@yulivee ~ $

As you can see, i have NVIDIA-beta installed on the host. Within the Chroot i check now whats the current version of NVIDIA-beta within the moonbase using:

root@yulivee /usr/src # lvu version NVIDIA-beta
185.18.14

As you can see, it's the same version, so everything is fine, issue:

lget NVIDIA-beta

and copy the .run from /var/spool/lunar to /usr/src. Make it executable using chmod a+x file.run and run it finally using ./file.run. Of course you have to replace "file" with the real filename.

It will tell you that you run an X-Server and you have to stop this one first. Thats np, close X11, chroot into your chroot on the console and install NVIDIA. Exit the Chroot, start X11 again and everything is fine and should be done. You have to try around a bit with the NVIDIA Installer.

<a name="homedir"></a>

Home directory

This is the easiest Task. We just need to mount the home directory with bind:

mount -o bind /home $OC/home

Within the Chroot you can “su - username” and you’re in your home directory, without any problems or any flaws.

<a name="initscript"></a>

Init Script

These are only examples.. you’ll probably find nicer variants. Anyway, for both scripts you will need a configfile containing at least the variable CHROOTDIR - which should point to your Chroot Directory. Example:

Config This config will be used by the initscripts below and our “chroot-enter script”.

$ cat /etc/lunar32chroot.conf
#!/bin/bash

# ^.^
OK="\033[00;29;1m[ \033[00;32;1mDONE\033[00;29;1m ]\033[0m"
FAIL="\033[00;29;1m[ \033[00;32;1mFAIL\033[00;29;1m ]\033[0m"

CHROOTDIR="/home/wdp/32bit"

SysVinit: This Init Script will mount with --bind some needed directories for the chroot and copy some files which you will most likely want to keep up to date, to have permissions and networking working correctly.

$ cat /etc/init.d/lunar32chroot

#!/bin/bash
#
# lunar32chroot Initializes the 32 Bit lunar chroot
#
# chkconfig: 2345 80 10
# description: Initializes 32 Bit chroot

if [ -e "/etc/lunar32chroot.conf" ]; then

    source /etc/lunar32chroot.conf

else

    # we need a config...
    echo "No config file found"
    echo -e $FAIL
    exit 0

fi

case $1 in
    start)

        echo "Starting 32bit chroot..."

        echo -n "Mounting chroot directories..."
        mount -o bind /dev $CHROOTDIR/dev >/dev/null
        if [ -d /dev/pts ]; then
            mount -o bind /dev/pts $CHROOTDIR/dev/pts >/dev/null
        fi
        if [ -d /dev/shm ]; then
            mount -o bind /dev/shm $CHROOTDIR/dev/shm >/dev/null
        fi
        mount -o bind /proc $CHROOTDIR/proc >/dev/null
        if [ -d /proc/bus/usb ]; then
            mount -o bind /proc/bus/usb $CHROOTDIR/proc/bus/usb >/dev/null
        fi
        mount -o bind /sys $CHROOTDIR/sys >/dev/null
        mount -o bind /tmp $CHROOTDIR/tmp >/dev/null
        mount -o bind /home $CHROOTDIR/home >/dev/null
        # todo: add a check whether everything was mounted
        echo -e $OK

        echo -n "Copying essential files..."
        cp -afr /etc/resolv.conf $CHROOTDIR/etc >/dev/null
        cp -afr /etc/passwd $CHROOTDIR/etc >/dev/null
        cp -afr /etc/shadow $CHROOTDIR/etc >/dev/null
        cp -afr /etc/group $CHROOTDIR/etc >/dev/null
        cp -afr /etc/hosts $CHROOTDIR/etc > /dev/null
        cp -afr /etc/localtime $CHROOTDIR/etc >/dev/null
        cp -afr /etc/nsswitch.conf $CHROOTDIR/etc >/dev/null
        # todo: add a check whether everything was copied
        echo -e $OK
        ;;

    stop)

        echo "Stopping 32bit chroot"

        echo -n "Unmounting 32bit chroot directories..."
        umount -fl $CHROOTDIR/home >/dev/null
        umount -fl $CHROOTDIR/tmp >/dev/null
        umount -fl $CHROOTDIR/sys >/dev/null
        if [ -d $CHROOTDIR/proc/bus/usb ]; then
            umount -fl $CHROOTDIR/proc/bus/usb >/dev/null
        fi
        umount -f $CHROOTDIR/proc >/dev/null
        if [ -d $CHROOTDIR/dev/shm ]; then
            umount -fl $CHROOTDIR/dev/shm >/dev/null
        fi
        if [ -d $CHROOTDIR/dev/pts ]; then
            umount -fl $CHROOTDIR/dev/pts >/dev/null
        fi
        umount -fl $CHROOTDIR/dev >/dev/null
        # todo: add a check whether umount was ok
        echo -e $OK
        ;;

    esac

exit 0

Now run “chkconfig –add lunar32chroot” to create the essential init scripts/symlinks for the different runlevels and you’re done.

<a name="enterchrootscript"></a>

Entering Chroot - Script

With this Script you just need to type “lunar32″ to enter the chroot environment. Keep in mind the "linux32" command should be available on all boxes, you dont need to install additional software. However its part of "util-linux".

$ cat /usr/bin/lunar32

#!/bin/bash
# little script to reduce some things to just one command
# especially for lazy people like me.

source /etc/lunar32chroot.conf

echo "Entering chroot..."
linux32 chroot "$CHROOTDIR" /bin/bash

Hint from Beko Beko has shown me a dirty way (as he said) of doing the same using sudo, thus you can enter the environment without beeing root:

linux32 sudo chroot "$CHROOTDIR" /bin/bash -c "su $WHOAMI"

Negative Sideeffects: you're landing in / at the start and sudo has to run with NOPASS. Thats why this solution is dirty and might be a security risk. However.. :-) By the way Of course you want to replace $WHOAMI with your username - or a variable containing the current username.

<a name="applications"></a>

Applications

<a name="fonts"></a>

Fonts

For most applications you will need some X11 Fonts installed within the Chroot. Its enough if you install these:

lin -cr font-adobe-100dpi font-adobe-75dpi font-adobe-utopia-75dpi font-adobe-utopia-100dpi font-adobe-utopia-type1 font-bitstream-100dpi font-bitstream-75dpi font-bh-lucidatypewriter-100dpi font-bh-lucidatypewriter-75dpi

some of them might not be needed, but well doesnt hurt to install them.

<a name="skype"></a>

Skype

If you want to use Skype you will have to install some more libraries and tools:

cd /var/lib/lunar/moonbase
cp -rva kde4/base/qt4 zlocal/
cd zlocal/qt4
vim DEPENDS

Remove this line:

depends  %X

Finally install needed stuff:

lin -cr dbus alsa-utils videoproto libXv scrnsaverproto libXScrnSaver qt4

It might be needed to install dbus-qt3 (not sure) if so, you have to copy the module to zlocal and edit the DEPENDS file (of qt3 and of dbus-qt3) to remove the X Dependecy.

Skype should now work. You might want to look at the "fonts" Section because skype will display broken fonts :)

<a name="usefuldoc"></a>

Useful Documentation:

Personal tools
Namespaces
Variants
Actions
Wiki Navigation
Project Sites
Toolbox