Note

The Funtoo Linux project has transitioned to "Hobby Mode" and this wiki is now read-only.

Difference between revisions of "32-bit Chroot"

From Funtoo
Jump to navigation Jump to search
m (formatting)
(Marked this version for translation)
 
(27 intermediate revisions by 3 users not shown)
Line 1: Line 1:
The [https://en.wikipedia.org/wiki/X86 x86 Instruction Set Architecture] includes 64-bit registers which have been implemented in processors from AMD, Intel and others starting in 2003 (AMD Opteron). Since then most new and existing applications have been written to make use of x86-64bit architecture. Fewer applications require 32-bit support. In the past x86-64bit arch on Funtoo Linux has provided support for 64 and 32-bit applications and libraries simultaneously ('multilib').
<translate>
<!--T:1-->
The 1.3-release of Funtoo Linux deprecates support for 32-bit applications and libraries on x86-64bit arch via 'multilib' -- for more information see [https://forums.funtoo.org/topic/1866-important-13-release-to-beta-and-removal-of-multilib/ this forums post]. This page provides background for this decision as well as steps that can be used to provide 32-bit support without multilib, namely a 32-bit chroot.


'''The 1.3-release of Funtoo Linux depreciates support for 32-bit applications and libraries on x86-64bit arch:''' https://forums.funtoo.org/topic/1866-important-13-release-to-beta-and-removal-of-multilib/
== Background == <!--T:2-->


Users needing to run 32-bit programs on x86-64bit hardware have two options:
<!--T:3-->
The [https://en.wikipedia.org/wiki/X86 x86 Instruction Set Architecture] includes 64-bit registers which have been implemented in processors from AMD, Intel and others starting in 2003 (AMD Opteron).


The first option is to install a second separate instance of Funtoo Linux using x86-32bit arch builds.
<!--T:4-->
Since then most new and existing applications have been written to make use of x86-64bit architecture. Fewer applications require 32-bit support. In the past, x86-64bit arch on Funtoo Linux has provided support for 64 and 32-bit applications and libraries simultaneously -- called  'multilib' -- which is a capability that is part of the GNU C library and dynamic library loader.  


An alternative to this is to install an x86-32bit arch instance of Funtoo Linux on an x86-64bit host. Users then chroot into the 32-bit chroot environment using the {{c|linux32}} (i.e. {{c|setarch}}) command provided by [Package:sys-apps/util-linux]. This guide will detail the setup and use of this second scenario.
<!--T:5-->
However, multilib support makes ebuild maintenance more complex, and we have had 64-bit instructions for 15+ years, and fewer and fewer things truly need 32-bit support. Therefore it makes sense to start to transition to a pure 64-bit non-multilib environment to reduce the complexity of ebuilds, and look at other approaches to solve the 32-bit compatibility problem.


= Acknowledgement =
== Options == <!--T:6-->
The information published here is based on steps detailed on the Gentoo Linux Wiki: https://wiki.gentoo.org/wiki/Project:AMD64/32-bit_Chroot_Guide ([https://creativecommons.org/licenses/by-sa/3.0/ CC BY-SA 3.0]).
 
<!--T:7-->
Users needing to run 32-bit programs on x86-64bit hardware have several options:
 
<!--T:8-->
# install a second separate instance of Funtoo Linux using x86-32bit arch builds.
# install an x86-32bit arch instance of Funtoo Linux on an x86-64bit host. Users then chroot into the 32-bit chroot environment using the {{c|linux32}} (i.e. {{c|setarch}}) command provided by {{package|sys-apps/util-linux}}. This guide will detail the setup and use of this second scenario.
# use [[LXD]] to set up a 32-bit container.
 
<!--T:9-->
See [[Chroot and Containers]] for a full list of options documented on the wiki.


= Installation =
== Installation == <!--T:10-->
This guide describes a 32-bit chroot installed into a new directory on existing storage.
This guide describes a 32-bit chroot installed into a new directory on existing storage.
{{console|body=
{{console|body=
##g##localuser@localhost##!g## $ ##i##su -
$ ##i##su -
##i##Password:
Password:
##r##localhost##!r## # ##i##mkdir -p /path/to/chroot/directory
# ##i##mkdir -p /path/to/chroot/directory
##r##localhost##!r## # ##i##cd /path/to/chroot/directory
# ##i##cd /path/to/chroot/directory
}}
}}


<!--T:11-->
Similar to a Funtoo [[Install/Download_and_Extract_Stage3|installation]] an appropriate Stage3 tarball must be downloaded and extracted. This will provide the directories, files and links necessary for the 32-bit chroot.
Similar to a Funtoo [[Install/Download_and_Extract_Stage3|installation]] an appropriate Stage3 tarball must be downloaded and extracted. This will provide the directories, files and links necessary for the 32-bit chroot.


'''Please refer to the [[Subarches]] page for an appropriate 32-bit Stage3.'''
<!--T:12-->
 
'''Please refer to the [[Subarches]] page for an appropriate 32-bit Stage3.''' The following x86-32bit builds would be appropriate on an x86-64bit host
The following are appropriate on an x86-64bit host


<!--T:13-->
{{TableStart}}
{{TableStart}}
{{2ColHead|Subarch|CPU Family}}
{{2ColHead|Subarch|CPU Family}}
Line 35: Line 51:
{{TableEnd}}
{{TableEnd}}


You should choose a 32-bit subarch with features and CPU_FLAGS that are compatible with the subarch and CPU of the x86-64bit host. '''If in doubt, choose 'Generic 32'.'''
<!--T:14-->
You should choose a 32-bit subarch with features and CPU_FLAGS that are compatible with the subarch and CPU of your x86-64bit host. '''If in doubt, choose 'Generic 32'.'''


<!--T:15-->
Copy the download link address for the '''1.3-release-std''' build and paste it into your terminal to download using {{c|wget}}.
Copy the download link address for the '''1.3-release-std''' build and paste it into your terminal to download using {{c|wget}}.
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##wget https://build.funtoo.org/1.3-release-std/x86-32bit/generic_32/2018-12-13/stage3-generic_32-1.3-release-std-2018-12-13.tar.xz
# ##i##wget https://build.funtoo.org/1.3-release-std/x86-32bit/generic_32/2018-12-13/stage3-generic_32-1.3-release-std-2018-12-13.tar.xz
}}
}}


Extract the Stage3 tarball, preserving permissions.
<!--T:16-->
From within your 32-bit chroot directory, run the following command to extract the Stage3 tarball, preserving permissions:
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##tar -xpf stage3-generic_32-1.3-release-std-2018-12-13.tar.xz
# ##i##tar -xpf stage3-generic_32-1.3-release-std-2018-12-13.tar.xz
}}
}}


Instead of having duplicate portage trees, this 32-bit chroot will use the meta-repo of the host. To further eliminate duplicate downloads the 32-bit chroot will be set up to use the Portage local sourcefile directory on the host (see 'DISTDIR' in {{c|emerge --info}}). Package source files already fetched by the host will be available inside of the chroot environment. To achieve this you must first create the necessary directories inside of the 32-bit chroot folder. Later the host folders will bind-mount onto these empty directories.
<!--T:17-->
Instead of having duplicate portage trees, this 32-bit chroot will instead use the meta-repo of the 64-bit host. To further eliminate duplicate downloads you can also use the local Portage sourcefile directory on the host inside of the chroot (see 'DISTDIR' in {{c|emerge --info}}). Package source files already fetched by the host will then be available for use by Portage inside of the chroot.
 
<!--T:18-->
To achieve this you must first create the necessary directories inside of the 32-bit chroot folder. Later the host folders will bind-mount onto these empty directories.
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##mkdir -p var/git/meta-repo
# ##i##mkdir -p var/git/meta-repo
##r##localhost##!r## /path/to/chroot/directory # ##i##mkdir -p var/cache/portage/distfiles
# ##i##mkdir -p var/cache/portage/distfiles
}}
}}


{{package|sys-apps/portage}} and other packages must only see the environment variables of the 32-bit chroot and '''not those of the 64-bit host'''. The Gentoo guide requires users to execute {{c|env-update}} each time you enter the 32-bit chroot environment. The following will set this up to occur automatically.
<!--T:19-->
{{package|sys-apps/portage}} and other packages must only see the environment variables of the 32-bit chroot and not those of the 64-bit host. The Gentoo guide requires users to execute {{c|env-update}} each time you enter the 32-bit chroot environment. The following configuration will set this to occur automatically.


<!--T:20-->
Create and edit the file {{f|.bash_profile}} inside of the directory {{f|/part/to/chroot/directory/root/}} to include the following
Create and edit the file {{f|.bash_profile}} inside of the directory {{f|/part/to/chroot/directory/root/}} to include the following
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##nano root/.bash_profile
# ##i##nano root/.bash_profile
}}
}}
{{file|name=.bash_profile|desc=/root/.bash_profile inside of /path/to/chroot/directory/|body=
{{file|name=.bash_profile|desc=/root/.bash_profile inside of /path/to/chroot/directory/|body=
Line 64: Line 89:
}}
}}


<!--T:21-->
As the last step you should configure {{package|app-shells/bash}} to display a modified command prompt while inside of the chroot environment. This will help you to identify when you are issuing commands inside of the 32-bit chroot as opposed to the x86-64bit host.
As the last step you should configure {{package|app-shells/bash}} to display a modified command prompt while inside of the chroot environment. This will help you to identify when you are issuing commands inside of the 32-bit chroot as opposed to the x86-64bit host.


Add the following line at the end of the file {{f|/profile}} inside of the directory {{f|/part/to/chroot/directory/etc/}}
<!--T:22-->
Add the following line at the end of the file {{f|profile}} inside of the directory {{f|/part/to/chroot/directory/etc/}}
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##nano etc/profile
# ##i##nano etc/profile
}}
}}
{{file|name=profile|desc=/etc/profile inside of /path/to/chroot/directory/|body=
{{file|name=profile|desc=/etc/profile inside of /path/to/chroot/directory/|body=


         # understand sequences such as \h, don't put anything special in it.
         <!--T:23-->
# understand sequences such as \h, don't put anything special in it.
         PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
         PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi
fi


# ADD THE FOLLOWING LINE FOR YOUR 32-BIT CHROOT ENVIRONMENT
<!--T:24-->
# ADD THE FOLLOWING LINE TO IDENTIFY YOUR 32-BIT CHROOT ENVIRONMENT
PS1="(32-bit chroot) ${PS1}"
PS1="(32-bit chroot) ${PS1}"


<!--T:25-->
for sh in /etc/profile.d/*.sh ; do
for sh in /etc/profile.d/*.sh ; do
         [ -r "$sh" ] && . "$sh"
         [ -r "$sh" ] && . "$sh"
Line 84: Line 114:
unset sh
unset sh


<!--T:26-->
}}
}}


= OpenRC Configuration =
== OpenRC Configuration == <!--T:27-->
Following the Gentoo guide you will create an OpenRC service to automatically handle mounts and file copies from your host to the 32-bit chroot. This file in {{f|/etc/init.d}} will include additional mounts for Meta-Repo and the Portage DISTDIR.
You can create an {{Package|sys-apps/openrc}} service named '''chroot32''' to automatically copy files and mount directories prior to accessing the 32-bit chroot environment. This service will include additional mounts for meta-repo and the Portage DISTDIR.


<!--T:28-->
{{note|The following file mounts Funtoo portage tree /var/git/meta-repo as read-only. The Portage DISTDIR (/var/cache/portage/distfiles) is mounted read-write.}}
{{note|The following file mounts Funtoo portage tree /var/git/meta-repo as read-only. The Portage DISTDIR (/var/cache/portage/distfiles) is mounted read-write.}}


<!--T:29-->
Create and edit the file {{f|/etc/init.d/chroot32}}, setting chroot_dir to equal {{f|/path/to/chroot/directory}}.
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##nano /etc/init.d/chroot32
# ##i##nano /etc/init.d/chroot32
}}
}}
{{file|name=chroot32|desc=/etc/init.d/chroot32 on x86-64bit host|body=
{{file|name=chroot32|desc=/etc/init.d/chroot32 on x86-64bit host|body=
#!/sbin/openrc-run
#!/sbin/openrc-run


chroot_dir=/home/cameron/Data/chroot32
<!--T:30-->
chroot_dir=/path/to/chroot/directory


<!--T:31-->
depend() {
depend() {
   need localmount bootmisc
   need localmount bootmisc
}
}


<!--T:32-->
start() {
start() {
     ebegin "Mounting 32-bit chroot directories"
     ebegin "Mounting 32-bit chroot directories"
Line 120: Line 157:
}
}


<!--T:33-->
stop() {
stop() {
     ebegin "Unmounting 32-bit chroot directories"
     ebegin "Unmounting 32-bit chroot directories"
Line 132: Line 170:
}
}


<!--T:34-->
}}
}}


<!--T:35-->
Set this file to be executable.
Set this file to be executable.
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##chmod +x /etc/init.d/chroot32
# ##i##chmod +x /etc/init.d/chroot32
}}
}}


To set up the 32-bit chroot mounts ready for access you start the service.
<!--T:36-->
Start the {{c|chroot32}} service to prepare the 32-bit environment.
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##rc-service chroot32 start##!i##
# ##i##rc-service chroot32 start##!i##
##bl##chroot32##!bl##        {{!}} ##g##*##!g## Mounting 32-bit chroot directories...                        [ ##g##ok##!g## ]
{{!}} ##g##*##!g## Mounting 32-bit chroot directories...                        [ ##g##ok##!g## ]
##bl##chroot32##!bl##        {{!}} ##g##*##!g## Copying 32bit chroot files...                                [ ##g##ok##!g## ]
{{!}} ##g##*##!g## Copying 32bit chroot files...                                [ ##g##ok##!g## ]
}}
}}


{{tip|If you would like the necessary files copied and folders mounts at '''startup''' run the following
<!--T:37-->
{{tip|If you would like this service to run during host startup issue the following command
{{console|body=
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##rc-update add chroot32 default##!i##
# ##i##rc-update add chroot32 default
  ##g##*##!g## service chroot32 added to runlevel default
  ##g##*##!g## service chroot32 added to runlevel default
}}
}}
}}
}}


<!--T:38-->
The 32-bit chroot environment is now ready for access.
The 32-bit chroot environment is now ready for access.
{{console|body=
##r##localhost##!r## /path/to/chroot/directory # ##i##exit
##g##user@localhost##!g## $
}}


= Enter 32-bit Chroot =
== Enter 32-bit Chroot == <!--T:39-->
Enter the 32-bit chroot environment with the following commands
Enter the 32-bit chroot environment with the following commands
{{console|body=
{{console|body=
##g##user@localhost##!g## $ ##i##su -
$ ##i##su -
##i##Password:
Password: ##i##*******
##r##localhost##!r## # ##i##linux32 chroot /path/to/chroot/directory /bin/bash -l##!i##
# ##i##linux32 chroot /path/to/chroot/directory /bin/bash -l##!i##
>>> Regenerating /etc/ld.so.cache...
>>> Regenerating /etc/ld.so.cache...
(32-bit chroot) ##r##localhost##!r## / #
%chroot32%
}}
}}


{{important|The switch '''-l''' tells bash to source /etc/profile within the chroot environment and not from the host. Without this switch you must manually issue the command {{c|source /etc/profile}}.}}
<!--T:40-->
{{important|The switch '''-l''' tells bash to source /etc/profile within the chroot environment and not from the host. Without this switch you must manually issue the command {{c|source /etc/profile}} each time you enter the 32-bit environment.}}


<!--T:41-->
Confirm that you are now in a 32-bit environment
Confirm that you are now in a 32-bit environment
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##uname -m##!i##
%chroot32% ##i##uname -m##!i##
i686
i686
(32-bit chroot) ##r##localhost##!r## / # ##i##epro show##!i##
%chroot32% ##i##epro show##!i##


=== ##g##Enabled Profiles:##!g## ===
=== ##g##Enabled Profiles:##!g## === <!--T:42-->


         arch: ##bl##x86-32bit##!bl##
         <!--T:43-->
arch: ##bl##x86-32bit##!bl##
       build: ##bl##current##!bl##
       build: ##bl##current##!bl##
     subarch: ##bl##generic_32##!bl##
     subarch: ##bl##generic_32##!bl##
Line 186: Line 228:




=== ##g##Python kit:##!g## ===
=== ##g##Python kit:##!g## === <!--T:44-->


       branch: ##bl##3.7-release##!bl##
       <!--T:45-->
branch: ##bl##3.7-release##!bl##


=== ##g##All inherited flavor from core flavor:##!g## ===
=== ##g##All inherited flavor from core flavor:##!g## === <!--T:46-->


                         ##bl##minimal##!bl## (from core flavor)
                         <!--T:47-->
##bl##minimal##!bl## (from core flavor)


<!--T:48-->
}}
}}


= First Steps =
== Chroot First Steps == <!--T:49-->
If necessary now is a good point to set up [[Funtoo_Linux_Localization|Localization]]. Similarly, changes to {{f|/etc/portage/make.conf}} within the 32-bit environment can be made.
If necessary now is a good point to set up [[Funtoo_Linux_Localization|Localization]]. Similarly, changes to {{f|/etc/portage/make.conf}} within the 32-bit environment can be made.


Currently you are the '''root''' user inside of the 32-bit environment. To change to the host user account '''localuser''' you must first create a home directory for localuser inside the 32-bit environment. ({{f|/home/localuser}} on the host is not mounted inside of this chroot environment.)
<!--T:50-->
Currently you are the '''root''' user inside of the 32-bit environment. To change to the host user account '''localuser''' you must first create a home directory for localuser inside the 32-bit environment. ({{f|/home/localuser}} '''on the host''' is not mounted inside of this chroot environment.)
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##cp -r /etc/skel /home/localuser##!i##
%chroot32% ##i##cp -r /etc/skel /home/localuser##!i##
%chroot32% ##i##chown -R localuser:localuser /home/localuser##!i##
}}
}}


<!--T:51-->
Switch to 'localuser'  
Switch to 'localuser'  
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##su localuser -l
%chroot32% ##i##su localuser -l
(32-bit chroot) ##g##localuser@localhost##!g## ~ $
$
}}
}}


== Updating Funtoo Meta-Repo ==
== Updating Funtoo Meta-Repo == <!--T:52-->
 
The 32-bit chroot environment accesses {{f|/var/git/meta-repo}} from the x86-64bit host.


Issuing {{c|ego sync}} is not necessary within the 32-bit chroot environment.
<!--T:53-->
{{warning|The 32-bit chroot environment uses the Meta-Repo ({{f|/var/git/meta-repo}}) of the 64bit host. Issuing {{c|ego sync}} is not necessary within the 32-bit chroot environment.}}


{{important|To keep Meta-Repo up-to-date first issue {{c|ego sync}} on the x86-64bit host '''before''' entering the 32-bit chroot environment.}}
<!--T:54-->
You must update Meta-Repo on the x86-64bit host ''before'' entering the 32-bit environment.


== Exiting ==
== Exiting the 32-bit Chroot == <!--T:55-->
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##exit
%chroot32% ##i##exit
##g##localuser@localhost##!g## ~ $
#
}}
}}


= Emerging Packages =
== Emerging Packages == <!--T:56-->
Enter the 32-bit chroot environment and install packages normally.
Enter the 32-bit chroot environment and install packages normally.
{{console|body=
{{console|body=
##g##user@localhost##!g## $ ##i##su -
$ ##i##su -
##i##Password:
Password: ##i##*******
##r##localhost##!r## # ##i##linux32 chroot /path/to/chroot/directory /bin/bash -l##!i##
# chroot /path/to/chroot/directory /bin/bash -l
>>> Regenerating /etc/ld.so.cache...
>>> Regenerating /etc/ld.so.cache...
(32-bit chroot) ##r##localhost##!r## / # ##i##emerge -av foobar
%chroot32% ##i##emerge -av foobar
}}
}}


== Wine (32-bit only) ==
<!--T:57-->
{{tip|Depending on your use case it may be beneficial to change flavor and add mix-ins within the 32-bit environment.}}
 
== Wine (32-bit only) == <!--T:58-->
{{important|'''Before''' entering the 32-bit environment run the following command
{{important|'''Before''' entering the 32-bit environment run the following command
{{console|body=
{{console|body=
##g##localuser@localhost##!g## $ ##i##su -
$ ##i##su -
##i##Password:
Password: ##i##*******
##r##localhost##!r## # ##i##xhost local:localhost
# ##i##xhost local:localhost}}
 
<!--T:59-->
'''This will allow X11 applications inside of the 32-bit environment to display on the host X session.'''
}}
}}


<!--T:60-->
Install Wine inside of the 32-bit environment (example, {{Package|app-emulation/wine-vanilla}})
Install Wine inside of the 32-bit environment (example, {{Package|app-emulation/wine-vanilla}})
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##emerge -av wine-vanilla
%chroot32% ##i##emerge -av wine-vanilla
}}
}}


Instead of running wine as the '''root''' user, run as '''localuser'''. Configure Wine with {{c|winecfg}}.
<!--T:61-->
Switch to 'localuser'
Instead of running wine as the '''root''' user, run as '''localuser'''. Switch to 'localuser' and configure Wine with {{c|winecfg}}. An X window should display.
{{console|body=
{{console|body=
(32-bit chroot) ##r##localhost##!r## / # ##i##su localuser -l
%chroot32% ##i##su localuser -l
(32-bit chroot) ##g##localuser@localhost##!g## ~ $ ##i##winecfg
%chroot32% ##i##winecfg
}}
}}


== Steam ==
== Acknowledgement == <!--T:62-->
=== Local Steam Repository ===
 
(details to come)
<!--T:63-->
=== Install and Start ===
The information published here is based on steps detailed on the Gentoo Linux Wiki: https://wiki.gentoo.org/wiki/Project:AMD64/32-bit_Chroot_Guide ([https://creativecommons.org/licenses/by-sa/3.0/ CC BY-SA 3.0]).
(details to come)
</translate>
[[Category:Official Documentation]]

Latest revision as of 07:52, April 13, 2020

The 1.3-release of Funtoo Linux deprecates support for 32-bit applications and libraries on x86-64bit arch via 'multilib' -- for more information see this forums post. This page provides background for this decision as well as steps that can be used to provide 32-bit support without multilib, namely a 32-bit chroot.

Background

The x86 Instruction Set Architecture includes 64-bit registers which have been implemented in processors from AMD, Intel and others starting in 2003 (AMD Opteron).

Since then most new and existing applications have been written to make use of x86-64bit architecture. Fewer applications require 32-bit support. In the past, x86-64bit arch on Funtoo Linux has provided support for 64 and 32-bit applications and libraries simultaneously -- called 'multilib' -- which is a capability that is part of the GNU C library and dynamic library loader.

However, multilib support makes ebuild maintenance more complex, and we have had 64-bit instructions for 15+ years, and fewer and fewer things truly need 32-bit support. Therefore it makes sense to start to transition to a pure 64-bit non-multilib environment to reduce the complexity of ebuilds, and look at other approaches to solve the 32-bit compatibility problem.

Options

Users needing to run 32-bit programs on x86-64bit hardware have several options:

  1. install a second separate instance of Funtoo Linux using x86-32bit arch builds.
  2. install an x86-32bit arch instance of Funtoo Linux on an x86-64bit host. Users then chroot into the 32-bit chroot environment using the linux32 (i.e. setarch) command provided by No results. This guide will detail the setup and use of this second scenario.
  3. use LXD to set up a 32-bit container.

See Chroot and Containers for a full list of options documented on the wiki.

Installation

This guide describes a 32-bit chroot installed into a new directory on existing storage.

user $ su -
Password:
root # mkdir -p /path/to/chroot/directory
root # cd /path/to/chroot/directory

Similar to a Funtoo installation an appropriate Stage3 tarball must be downloaded and extracted. This will provide the directories, files and links necessary for the 32-bit chroot.

Please refer to the Subarches page for an appropriate 32-bit Stage3. The following x86-32bit builds would be appropriate on an x86-64bit host

SubarchCPU Family
Generic 3232-bit Processors (PC-Compatible, Generic)
I68632-bit Processors (PC-Compatible, Generic)
Atom 3232-bit Intel Processors
Pentium432-bit Intel Processors

You should choose a 32-bit subarch with features and CPU_FLAGS that are compatible with the subarch and CPU of your x86-64bit host. If in doubt, choose 'Generic 32'.

Copy the download link address for the 1.3-release-std build and paste it into your terminal to download using wget.

root # wget https://build.funtoo.org/1.3-release-std/x86-32bit/generic_32/2018-12-13/stage3-generic_32-1.3-release-std-2018-12-13.tar.xz

From within your 32-bit chroot directory, run the following command to extract the Stage3 tarball, preserving permissions:

root # tar -xpf stage3-generic_32-1.3-release-std-2018-12-13.tar.xz

Instead of having duplicate portage trees, this 32-bit chroot will instead use the meta-repo of the 64-bit host. To further eliminate duplicate downloads you can also use the local Portage sourcefile directory on the host inside of the chroot (see 'DISTDIR' in emerge --info). Package source files already fetched by the host will then be available for use by Portage inside of the chroot.

To achieve this you must first create the necessary directories inside of the 32-bit chroot folder. Later the host folders will bind-mount onto these empty directories.

root # mkdir -p var/git/meta-repo
root # mkdir -p var/cache/portage/distfiles

sys-apps/portage and other packages must only see the environment variables of the 32-bit chroot and not those of the 64-bit host. The Gentoo guide requires users to execute env-update each time you enter the 32-bit chroot environment. The following configuration will set this to occur automatically.

Create and edit the file .bash_profile inside of the directory /part/to/chroot/directory/root/ to include the following

root # nano root/.bash_profile
   .bash_profile - /root/.bash_profile inside of /path/to/chroot/directory/
#run env-update on 32-bit chroot login
env-update

As the last step you should configure app-shells/bash to display a modified command prompt while inside of the chroot environment. This will help you to identify when you are issuing commands inside of the 32-bit chroot as opposed to the x86-64bit host.

Add the following line at the end of the file profile inside of the directory /part/to/chroot/directory/etc/

root # nano etc/profile
   profile - /etc/profile inside of /path/to/chroot/directory/
# understand sequences such as \h, don't put anything special in it.
        PS1="${USER:-$(whoami 2>/dev/null)}@$(uname -n 2>/dev/null) \$ "
fi

# ADD THE FOLLOWING LINE TO IDENTIFY YOUR 32-BIT CHROOT ENVIRONMENT
PS1="(32-bit chroot) ${PS1}"

for sh in /etc/profile.d/*.sh ; do
        [ -r "$sh" ] && . "$sh"
done
unset sh

OpenRC Configuration

You can create an sys-apps/openrc service named chroot32 to automatically copy files and mount directories prior to accessing the 32-bit chroot environment. This service will include additional mounts for meta-repo and the Portage DISTDIR.

   Note

The following file mounts Funtoo portage tree /var/git/meta-repo as read-only. The Portage DISTDIR (/var/cache/portage/distfiles) is mounted read-write.

Create and edit the file /etc/init.d/chroot32, setting chroot_dir to equal /path/to/chroot/directory.

root # nano /etc/init.d/chroot32
   chroot32 - /etc/init.d/chroot32 on x86-64bit host
#!/sbin/openrc-run

chroot_dir=/path/to/chroot/directory

depend() {
   need localmount bootmisc
}

start() {
    ebegin "Mounting 32-bit chroot directories"
    mount --rbind /dev "${chroot_dir}/dev" >/dev/null
    mount --rbind /sys "${chroot_dir}/sys" >/dev/null
    mount -t proc none "${chroot_dir}/proc" >/dev/null
    mount -o bind /tmp "${chroot_dir}/tmp" >/dev/null
    mount -o bind,ro /var/git/meta-repo "${chroot_dir}/var/git/meta-repo/" >/dev/null
    mount -o bind /var/cache/portage/distfiles "${chroot_dir}/var/cache/portage/distfiles/" >/dev/null
    mount -t tmpfs -o nosuid,nodev,noexec,mode=755 none "${chroot_dir}/run" > /dev/null
    eend $? "An error occured while attempting to mount 32bit chroot directories"
    ebegin "Copying 32bit chroot files"
    cp -pf /etc/resolv.conf /etc/passwd /etc/shadow /etc/group \
           /etc/gshadow /etc/hosts "${chroot_dir}/etc" >/dev/null
    cp -Ppf /etc/localtime "${chroot_dir}/etc" >/dev/null
    eend $? "An error occured while attempting to copy 32 bits chroot files."
}

stop() {
    ebegin "Unmounting 32-bit chroot directories"
    umount -fR "${chroot_dir}/dev" >/dev/null
    umount -fR "${chroot_dir}/sys" >/dev/null
    umount -f "${chroot_dir}/proc" >/dev/null
    umount -f "${chroot_dir}/tmp" >/dev/null
    umount -f "${chroot_dir}/var/git/meta-repo/" >/dev/null
    umount -f "${chroot_dir}/var/cache/portage/distfiles/" >/dev/null
    umount -f "${chroot_dir}/run"
    eend $? "An error occured while attempting to unmount 32bit chroot directories"
}

Set this file to be executable.

root # chmod +x /etc/init.d/chroot32

Start the chroot32 service to prepare the 32-bit environment.

root # rc-service chroot32 start
 | * Mounting 32-bit chroot directories...                        [ ok ]
 | * Copying 32bit chroot files...                                [ ok ]
   Tip

If you would like this service to run during host startup issue the following command

root # rc-update add chroot32 default
 * service chroot32 added to runlevel default

The 32-bit chroot environment is now ready for access.

Enter 32-bit Chroot

Enter the 32-bit chroot environment with the following commands

user $ su -
Password: *******
root # linux32 chroot /path/to/chroot/directory /bin/bash -l
>>> Regenerating /etc/ld.so.cache...
chroot32 #
   Important

The switch -l tells bash to source /etc/profile within the chroot environment and not from the host. Without this switch you must manually issue the command source /etc/profile each time you enter the 32-bit environment.

Confirm that you are now in a 32-bit environment

chroot32 # uname -m
i686
chroot32 # epro show

=== Enabled Profiles: ===

        arch: x86-32bit
       build: current
     subarch: generic_32
      flavor: core
     mix-ins: (not set)


=== Python kit: ===

      branch: 3.7-release

=== All inherited flavor from core flavor: ===

                         minimal (from core flavor)

Chroot First Steps

If necessary now is a good point to set up Localization. Similarly, changes to /etc/portage/make.conf within the 32-bit environment can be made.

Currently you are the root user inside of the 32-bit environment. To change to the host user account localuser you must first create a home directory for localuser inside the 32-bit environment. (/home/localuser on the host is not mounted inside of this chroot environment.)

chroot32 # cp -r /etc/skel /home/localuser
chroot32 # chown -R localuser:localuser /home/localuser

Switch to 'localuser'

chroot32 # su localuser -l
user $

Updating Funtoo Meta-Repo

   Warning

The 32-bit chroot environment uses the Meta-Repo (/var/git/meta-repo) of the 64bit host. Issuing ego sync is not necessary within the 32-bit chroot environment.

You must update Meta-Repo on the x86-64bit host before entering the 32-bit environment.

Exiting the 32-bit Chroot

chroot32 # exit
root #

Emerging Packages

Enter the 32-bit chroot environment and install packages normally.

user $ su -
Password: *******
root # chroot /path/to/chroot/directory /bin/bash -l
>>> Regenerating /etc/ld.so.cache...
chroot32 # emerge -av foobar
   Tip

Depending on your use case it may be beneficial to change flavor and add mix-ins within the 32-bit environment.

Wine (32-bit only)

   Important

Before entering the 32-bit environment run the following command

user $ su -
Password: *******
root # xhost local:localhost

This will allow X11 applications inside of the 32-bit environment to display on the host X session.

Install Wine inside of the 32-bit environment (example, No results)

chroot32 # emerge -av wine-vanilla

Instead of running wine as the root user, run as localuser. Switch to 'localuser' and configure Wine with winecfg. An X window should display.

chroot32 # su localuser -l
chroot32 # winecfg

Acknowledgement

The information published here is based on steps detailed on the Gentoo Linux Wiki: https://wiki.gentoo.org/wiki/Project:AMD64/32-bit_Chroot_Guide (CC BY-SA 3.0).