Gentoo Logo

How to set up a 32bit chroot


1.  Introduction

Introduction to 64bit system

The Gentoo Linux 32bit chroot guide will help you setting up a true 32bit chroot for your Gentoo/AMD64 system.

As you know 64bit systems don't run 32bit applications natively yet (at least not with portage) so you need to use emulation libraries to make them working or create a true 32bit system inside a chroot to install and run native 32bit applications. For the most common uses you do not need do build a 32bit chroot system. However, if you want to run applications that don't have a binary available to run with 32bit libraries, you should use a 32bit chroot. This guide will teach you how to set up a 32bit chroot and how to install and run applications inside the chroot.

2.  Installation

Installation of your 32bit chroot

To install a 32bit chroot you need to follow many footsteps that you use to install Gentoo Linux on a x86 computer. For now you need the latest stage3 available on our mirrors.

Code Listing 2.1: downloading stage3 from a gentoo mirror

$ cd /home/user/downloads
$ wget -c

Note: Note that we download a stage for x86, not for AMD64.

After downloading the stage3 you need to create a new directory to build your new chroot.

Code Listing 2.2: creating directory for 32bit chroot

$ su root insert your root password
# cd /mnt
# mkdir gentoo32

Then move the stage you have already downloaded, unpack it and set it up it like this example.

Code Listing 2.3: installing from stage3

# cd /mnt/gentoo32
# tar -xvjpf /home/user/downloads/stage3-i686-2006.1.tar.bz2
# cp -L /etc/resolv.conf /mnt/gentoo32/etc/
# cp -L /etc/passwd /mnt/gentoo32/etc/

Now you have the chroot ready for setup. Read the next chapter to learn how to set it up.

3.  Setup

Doing a setup for your new 32bit chroot

If everything went well until here now you will be able to set up your new 32bit chroot and finish the installation of this chroot.

The next step is to setup your new /mnt/gentoo32/etc/make.conf.

Code Listing 3.1: Configuring your new make.conf

CFLAGS="-O2 -march=athlon-xp -msse2 -pipe -fomit-frame-pointer"

Now mount the various bogus file systems:

Code Listing 3.2: Mount virtual file systems

# mount -o bind /dev /mnt/gentoo32/dev
# mount -o bind /dev/pts /mnt/gentoo32/dev/pts
# mount -o bind /dev/shm /mnt/gentoo32/dev/shm
# mount -o bind /proc /mnt/gentoo32/proc
# mount -o bind /proc/bus/usb /mnt/gentoo32/proc/bus/usb
# mount -o bind /sys /mnt/gentoo32/sys

Now you have a true 32bit chroot installed in your 64bits system which is almost ready for use. Next, you need to create a link from your portage available in your 64bit system to your chroot. This way, you only need to update it in one installation instead of duplicating a lot of data.

Code Listing 3.3: Link portage to /usr/portage inside the 32bit chroot

# mkdir -p /mnt/gentoo32/usr/portage/
# mount -o bind /usr/portage /mnt/gentoo32/usr/portage/

Note: Everytime you update your portage by doing a emerge sync, you update your 32bit chroot's portage as well.

If you want to run 32bit applications which use X, you also need to mount /tmp.

Code Listing 3.4: Mount /tmp for applications with a GUI

# mount -o bind /tmp /mnt/gentoo32/tmp

Now we're ready to switch inside the chroot.

Code Listing 3.5: Changing inside the chroot

(Only perform this step if you don't have util-linux already installed)
# emerge util-linux
# linux32 chroot /mnt/gentoo32 /bin/bash
(Make sure we have a i686 setup)
# uname -m

Warning: The linux32 util is needed to change the CHOST value. If you forget it, you're likely to be unable to compile anything inside the chroot environment.

Now you have a new 32bit chroot system ready to be updated. Follow the next steps to update it.

Code Listing 3.6: Updating your new 32bit chroot

# source /etc/profile
# env-update
# emerge --sync
# emerge -auDN world

After this you basically have finished the setup of your 32bit chroot. To make things more suitable, we are going to set up a new file in your 64bit system to enable the 32bit chroot when booting.

Code Listing 3.7: creating a new file in /etc/init.d

# nano -w /etc/init.d/gentoo32

depend() {
   need localmount
   need bootmisc

start() {
    ebegin "Mounting 32bit chroot dirs"
    mount -o bind /dev /mnt/gentoo32/dev >/dev/null
    mount -o bind /dev/pts /mnt/gentoo32/dev/pts >/dev/null &
    mount -o bind /dev/shm /mnt/gentoo32/dev/shm >/dev/null &
    mount -o bind /proc /mnt/gentoo32/proc >/dev/null
    mount -o bind /proc/bus/usb /mnt/gentoo32/proc/bus/usb >/dev/null &
    mount -o bind /sys /mnt/gentoo32/sys >/dev/null &
    mount -o bind /tmp /mnt/gentoo32/tmp >/dev/null &
    mount -o bind /usr/portage /mnt/gentoo32/usr/portage/ >/dev/null &
    eend $? "An error occured while attempting to mount 32bit chroot directories"
    ebegin "Copying 32bit chroot files"
    cp -pf /etc/resolv.conf /mnt/gentoo32/etc >/dev/null &
    cp -pf /etc/passwd /mnt/gentoo32/etc >/dev/null &
    cp -pf /etc/shadow /mnt/gentoo32/etc >/dev/null &
    cp -pf /etc/group /mnt/gentoo32/etc >/dev/null &
    cp -pf /etc/gshadow /mnt/gentoo32/etc >/dev/null &
    cp -pf /etc/hosts /mnt/gentoo32/etc > /dev/null &
    cp -Ppf /etc/localtime /mnt/gentoo32/etc >/dev/null &
    eend $? "An error occured while attempting to copy 32 bits chroot files."

stop() {
    ebegin "Unmounting 32bit chroot dirs"
    umount -f /mnt/gentoo32/dev/pts >/dev/null
    umount -f /mnt/gentoo32/dev/shm >/dev/null
    umount -f /mnt/gentoo32/dev >/dev/null &
    umount -f /mnt/gentoo32/proc/bus/usb >/dev/null
    umount -f /mnt/gentoo32/proc >/dev/null &
    umount -f /mnt/gentoo32/sys >/dev/null &
    umount -f /mnt/gentoo32/tmp >/dev/null &
    umount -f /mnt/gentoo32/usr/portage/ >/dev/null &
    eend $? "An error occured while attempting to unmount 32bit chroot directories"

Now you only need to run rc-update add gentoo32 default to run it at boot time.

Whenever you want to switch to your chroot environment, you only need to run the following command: linux32 chroot /mnt/gentoo32 /bin/bash.

Now you have your 32bit chroot ready to install new applications.

4.  Applications

Installing new applications in your chroot

Now that you have a fully functional 32bit chroot you can install every application in 32bit mode. Let's see how you can install new packages on your 32bit chroot.

Code Listing 4.1: Install foo inside the chroot

# linux32 chroot /mnt/gentoo32 /bin/bash
# source /etc/profile
# env-update
# emerge foo

Note: Always remember to do source /etc/profile and env-update after switching inside the chroot.

You now have installed a new package in your 32bit chroot. If you want to run your new package you need to run it inside of your chroot. If you want to run X applications the best solution to run it is doing the xhost trick. Everytime you need to run a X application run the this command in your 64bit environment:

Code Listing 4.2: Xhost trick

# xhost local:localhost

After this get inside your chroot again and you should be able to run every X application you build inside your 32bit chroot.

5.  Conclusion

Conclusion of this guide

With this chroot you can install many packages available only for x86 arch. Some packages like OpenOffice can be installed by using the binary available for Gentoo/AMD64. Some of the codecs available for MPlayer need this 32bit chroot so you can install win32codecs with this chroot.


Page updated November 16, 2012

Summary: This HOWTO shows you how to create a 32bit chroot.

Luis Medinas

Donate to support our development efforts.

Copyright 2001-2014 Gentoo Foundation, Inc. Questions, Comments? Contact us.