Miscellaneous:32BitChroot

(Difference between revisions)
Jump to: navigation, search
(Init Script)
(Init Script)
Line 175: Line 175:
 
<pre>$ cat /etc/lunar32chroot.conf
 
<pre>$ cat /etc/lunar32chroot.conf
 
#!/bin/bash
 
#!/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="/usr/local/32bit"</pre>
 
CHROOTDIR="/usr/local/32bit"</pre>
Line 192: Line 188:
 
# description: Initializes 32 Bit chroot
 
# description: Initializes 32 Bit chroot
  
if [ -e "/etc/lunar32chroot.conf" ]; then
+
CONFIGFILE="/etc/lunar32chroot.conf"
 
+
    source /etc/lunar32chroot.conf
+
 
+
else
+
 
+
    # we need a config...
+
    echo "No config file found"
+
    echo -e $RESULT_FAIL
+
    exit 0
+
 
+
fi
+
  
 
start() {
 
start() {
  
 
         echo "Starting 32bit chroot..."
 
         echo "Starting 32bit chroot..."
 +
 +
if [ -e "$CONFIGFILE" ]; then
 +
    source /etc/lunar32chroot.conf
 +
else
 +
    # we need a config...
 +
    echo "No config file found!"
 +
    echo -e $RESULT_FAIL
 +
    exit 0
 +
fi
  
 
         echo -n "    Mounting chroot directories..."
 
         echo -n "    Mounting chroot directories..."
 
         mount -o bind /dev $CHROOTDIR/dev >/dev/null &&
 
         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 &&
 
         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 /sys $CHROOTDIR/sys >/dev/null &&
 
         mount -o bind /tmp $CHROOTDIR/tmp >/dev/null &&
 
         mount -o bind /tmp $CHROOTDIR/tmp >/dev/null &&
Line 230: Line 215:
 
         [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
 
         [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
 
         [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
 
         [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
 +
        # optional mounts //TODO: add check
 +
        $SHELL -c "[ -d /dev/pts ] && mount -o bind /dev/pts $CHROOTDIR/dev/pts >/dev/null" &&
 +
        $SHELL -c "[ -d /dev/shm ] && mount -o bind /dev/shm $CHROOTDIR/dev/shm >/dev/null" &&
 +
        $SHELL -c "[ -d /proc/bus/usb ] && mount -o bind /proc/bus/usb $CHROOTDIR/proc/bus/usb >/dev/null"
 +
  
 
         echo -n "    Copying essential files..."
 
         echo -n "    Copying essential files..."
Line 255: Line 245:
 
         umount -fl $CHROOTDIR/tmp >/dev/null &&
 
         umount -fl $CHROOTDIR/tmp >/dev/null &&
 
         umount -fl $CHROOTDIR/sys >/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 &&
 
         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
 
         umount -fl $CHROOTDIR/dev >/dev/null
 
         exitcode=$?
 
         exitcode=$?
 
         [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
 
         [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
 
         [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
 
         [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
 +
        # optional unmounts //TODO: add check
 +
        $SHELL -c "[ -d $CHROOTDIR/proc/bus/usb ] && umount -fl $CHROOTDIR/proc/bus/usb >/dev/null" &&
 +
        $SHELL -c "[ -d $CHROOTDIR/dev/shm ] && umount -fl $CHROOTDIR/dev/shm >/dev/null" &&
 +
        $SHELL -c "[ -d $CHROOTDIR/dev/pts ] && umount -fl $CHROOTDIR/dev/pts >/dev/null"
 +
 
}
 
}
  

Revision as of 01:11, 23 February 2012

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

Changelog:

  • (20.02.12) Added 32bit-kernel configuration and prompt customization tidbits (keios)
  • (22.02.11) Paths of qt4 changed, changed howto accordingly (for skype), fonts needs mkfontscale and mkfontdir (added), added section about ATI graphiccards (3d acceleration), some smaller adjustments.
  • (29.10.10) Added bdftopcf to list of fonts, without that, fonts won't compile (thx to cavalier for helping to find out)
  • (29.10.10) Added instructions regarding the kernel
  • (29.10.10) Added new (with current applications installed) image (lunarlinuxchroot.tar.bz2)
  • (29.10.10) Added some information at the Test-Stage
  • (29.10.10) Added little side note about lunar optimize in chrooted-environments
  • (29.10.10) Added little notice about the "unofficial image"
  • (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.

Todo:

  • Bash Script which performs the actions below automatically

Installation

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 which would like that 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.

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.

Images

These are unofficial images made by me (wdp).

These images are quite outdated, so you're far better off making your own 32bit image. If you don't, you could have difficulties during the lunar update process below.

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 -

Setup Environment

Important: The Image listed below: The image was created to be used as solaris zone, however its quite fine for chrooted environments, too. Please notice that this image is "unofficial" so you won't get official support for it.

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).

export OC="/usr/local/32bit"
mkdir -p $OC
cd $OC
wget http://www.jeanbruenn.info/downloads/lunarlinuxchroot.tar.bz2
tar -xjvf lunarlinuxchroot.tar.bz2
cp /etc/hosts $OC/etc/hosts
cp /etc/nsswitch.conf $OC/etc/nsswitch.conf
cp /etc/passwd $OC/etc/passwd
cp /etc/shadow $OC/etc/shadow
cp /etc/resolv.conf $OC/etc/resolv.conf
mount -o bind /dev $OC/dev
mount -o bind /dev/pts $OC/dev/pts
mount -o bind /proc $OC/proc
mount -o bind /sys $OC/sys
mount -o bind /tmp $OC/tmp


Don't copy your current kernel stuff over to the chroot except for your .config:

cp -rva /usr/src/linux/.config $OC/usr/src/

Tests

To enter this chrooted environment, simply type in linux32 chroot $OC

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

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 ;-)

Setting up the shell prompt

You might want to ensure you don't accidently mistake the chroot environment for your host or vice-versa. Even if you don't think this could ever happen to you, it almost inevitably will if you keep a lot of terminals open at the same time like me (keios).

So to change your default prompt automatically on entering the chroot, add something like this to your .bashrc:

if [ $(uname -m) = "i686" ]; then
   # insert whatever works for you between @ and :
   export PS1="\u@lunar32:\W> " 
else
    export PS1="\u@\h:\W> "
fi

Your default prompt might look different, in that case customize the snippet as you see fit. If you use a colored prompt, changing the color usually should be enough to remind you.

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.

Modules might need working 32bit kernel headers, so make sure your gcc versions in- and outside the chroot are the same (see Test 1 above). If you need a specific gcc version that's not in the moonbase, use the --want $VERSION option of lin. Then build the kernel - you need the exact same version as you have on your host so you won't run into any trouble when e.g. installing video drivers for 3d acceleration later on:

root@mari-chan:/$ lin -cr linux-stable

When it asks you if you want to configure the kernel, say yes. In the menuconfig, use the "Load alternative config" option to load the kernel .config file you've copied to /usr/src earlier. Just enter:

../.config

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.

Important Note about lunar optimize: If you select optimizations for your chrooted environment, never ever use "native" as cpu optimization, this will break things. Always go with something safe, like i686 for example.

Enhancing your Chroot Installation

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 :)

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. The important thing about this is that you have to use exactly the same driver version within your chroot as 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.

nVidia

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.

ATI (r600/kms enabled)

.

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.

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

CHROOTDIR="/usr/local/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

CONFIGFILE="/etc/lunar32chroot.conf"

start() {

        echo "Starting 32bit chroot..."

	if [ -e "$CONFIGFILE" ]; then
    		source /etc/lunar32chroot.conf
	else
	    # we need a config...
    	echo "No config file found!"
    	echo -e $RESULT_FAIL
    	exit 0
	fi

        echo -n "    Mounting chroot directories..."
        mount -o bind /dev $CHROOTDIR/dev >/dev/null &&
        mount -o bind /proc $CHROOTDIR/proc >/dev/null &&
        mount -o bind /sys $CHROOTDIR/sys >/dev/null &&
        mount -o bind /tmp $CHROOTDIR/tmp >/dev/null &&
        mount -o bind /home $CHROOTDIR/home >/dev/null &&
        mount -o bind /media/lain $CHROOTDIR/media/lain >/dev/null &&
        mount -o bind /media/maelstrom $CHROOTDIR/media/maelstrom >/dev/null &&
        mount -o bind /media/vortex $CHROOTDIR/media/vortex >/dev/null 
        exitcode=$?
        [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
        [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
        # optional mounts //TODO: add check
        $SHELL -c "[ -d /dev/pts ] && mount -o bind /dev/pts $CHROOTDIR/dev/pts >/dev/null" &&
        $SHELL -c "[ -d /dev/shm ] && mount -o bind /dev/shm $CHROOTDIR/dev/shm >/dev/null" &&
        $SHELL -c "[ -d /proc/bus/usb ] && mount -o bind /proc/bus/usb $CHROOTDIR/proc/bus/usb >/dev/null"


        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 
        exitcode=$?
        [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
        [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
}

stop() {

        echo "Stopping 32bit chroot..."

        echo -n "    Unmounting 32bit chroot directories..."
        umount -fl $CHROOTDIR/media/vortex >/dev/null &&
        umount -fl $CHROOTDIR/media/maelstrom >/dev/null &&
        umount -fl $CHROOTDIR/media/lain >/dev/null &&
        umount -fl $CHROOTDIR/home >/dev/null &&
        umount -fl $CHROOTDIR/tmp >/dev/null &&
        umount -fl $CHROOTDIR/sys >/dev/null &&
        umount -f $CHROOTDIR/proc >/dev/null &&
        umount -fl $CHROOTDIR/dev >/dev/null
        exitcode=$?
        [ ${exitcode} -eq 0 ] && echo -e $RESULT_OK
        [ ${exitcode} -ne 0 ] && echo -e $RESULT_FAIL
        # optional unmounts //TODO: add check
        $SHELL -c "[ -d $CHROOTDIR/proc/bus/usb ] && umount -fl $CHROOTDIR/proc/bus/usb >/dev/null" &&
        $SHELL -c "[ -d $CHROOTDIR/dev/shm ] && umount -fl $CHROOTDIR/dev/shm >/dev/null" &&
        $SHELL -c "[ -d $CHROOTDIR/dev/pts ] && umount -fl $CHROOTDIR/dev/pts >/dev/null" 

}

. /lib/lsb/init-functions

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

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.

Applications

Fonts

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

lin -cr mkfontdir mkfontscale bdftopcf 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.

Skype

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

cd /var/lib/lunar/moonbase
cp -rva qt4-apps/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 :)

Useful Documentation:

Personal tools
Namespaces
Variants
Actions
Wiki Navigation
Project Sites
Toolbox