注意:

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

32-bit Chroot

From Funtoo
Revision as of 06:03, December 18, 2018 by Tassietux (talk | contribs) (fix xhost note)
Jump to navigation Jump to search

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 ('multilib').

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/

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

The first option is to install a second separate instance of Funtoo Linux using x86-32bit arch builds.

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 linux32 (i.e. setarch) command provided by [Package:sys-apps/util-linux]. This guide will detail the setup and use of this second scenario.

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

Installation

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

root ##g##localuser@localhost##!g## $ su -
root ##i##Password:
root ##r##localhost##!r## # mkdir -p /path/to/chroot/directory
root ##r##localhost##!r## # 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 are 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 the 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 ##r##localhost##!r## /path/to/chroot/directory # 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.

root ##r##localhost##!r## /path/to/chroot/directory # 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 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.

root ##r##localhost##!r## /path/to/chroot/directory # mkdir -p var/git/meta-repo
root ##r##localhost##!r## /path/to/chroot/directory # 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 will set this up to occur automatically.

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

root ##r##localhost##!r## /path/to/chroot/directory # 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 ##r##localhost##!r## /path/to/chroot/directory # 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 FOR 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

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 /etc/init.d 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.

root ##r##localhost##!r## /path/to/chroot/directory # 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 ##r##localhost##!r## /path/to/chroot/directory # chmod +x /etc/init.d/chroot32

To set up the 32-bit chroot mounts ready for access you start the service.

root ##r##localhost##!r## /path/to/chroot/directory # rc-service chroot32 start
root ##bl##chroot32##!bl##        | * Mounting 32-bit chroot directories...                        [ ok ]
root ##bl##chroot32##!bl##        | * Copying 32bit chroot files...                                [ ok ]
   Tip

If you would like the necessary files copied and folders mounts at startup run the following

root ##r##localhost##!r## /path/to/chroot/directory # rc-update add chroot32 default
 * service chroot32 added to runlevel default

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

root ##r##localhost##!r## /path/to/chroot/directory # exit
root ##g##user@localhost##!g## $

Enter 32-bit Chroot

Enter the 32-bit chroot environment with the following commands

root ##g##user@localhost##!g## $ su -
root ##i##Password:
root ##r##localhost##!r## # linux32 chroot /path/to/chroot/directory /bin/bash -l
>>> Regenerating /etc/ld.so.cache...
(32-bit chroot) localhost / #
   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.

Confirm that you are now in a 32-bit environment

(32-bit chroot) localhost / # uname -m
i686
(32-bit chroot) localhost / # 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)

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

(32-bit chroot) localhost / # cp -r /etc/skel /home/localuser

Switch to 'localuser'

(32-bit chroot) localhost / # su localuser -l
(32-bit chroot) localuser@localhost ~ $

Updating Funtoo Meta-Repo

The 32-bit chroot environment accesses /var/git/meta-repo from the x86-64bit host.

Issuing ego sync is not necessary within the 32-bit chroot environment.

   Important

To keep Meta-Repo up-to-date first issue ego sync on the x86-64bit host before entering the 32-bit chroot environment.

Exiting

(32-bit chroot) localhost / # exit
root ##g##localuser@localhost##!g## ~ $

Emerging Packages

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

root ##g##user@localhost##!g## $ su -
root ##i##Password:
root ##r##localhost##!r## # linux32 chroot /path/to/chroot/directory /bin/bash -l
>>> Regenerating /etc/ld.so.cache...
(32-bit chroot) localhost / # emerge -av foobar

Wine (32-bit only)

   Important

Before entering the 32-bit environment run the following command

root ##g##localuser@localhost##!g## $ su -
root ##i##Password:
root ##r##localhost##!r## # xhost local:localhost

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

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

(32-bit chroot) localhost / # emerge -av wine-vanilla

Instead of running wine as the root user, run as localuser. Configure Wine with winecfg. Switch to 'localuser'

(32-bit chroot) localhost / # su localuser -l
(32-bit chroot) localuser@localhost ~ $ winecfg

Steam

Local Steam Repository

(details to come)

Install and Start

(details to come)