Are you interested in poking at archlinux without disturbing your pristine Gentoo installation? Want to submit something to the AUR for your friend when you are not an archlinux fan? This guide describes how to set up an archlinux chroot on your Gentoo system. As always, if there are any issues with this guide, please email me (see the page's footer for the email)
Archlinux's package manager is known as pacman. Pacman is in portage, and xyne's useful reflector script is in portage also.
To get pacman and reflector, you first need to unmask and then simply emerge them:
# echo sys-apps/pacman >> /etc/portage/package.keywords
# echo www-misc/reflector >> /etc/portage/package.keywords
# emerge -va sys-apps/pacman www-misc/reflector
Pacman stores its configuration information in /etc/pacman.conf (pacman.conf(5)). I believe that the default configuration file should be working in most respects. It is here where you can override pacman's automatic architecture detection. This might be useful if you are on a multilib-capable architecture (such as amd64 where you can have x86 chroots).
Before pacman can install packages, you'll have to set up the repositories section of /etc/pacman.conf. You need to grab a list of mirrors as described in Reflector.
# reflector -l 8 --sort rate --save /etc/pacman.d/mirrorlist
You may examine the output saved in /etc/pacman.d/mirrorlist. Since this list of mirrors is not static, you may want to set reflector as a weekly cronjob. To read more information about mirror lists on archlinux, see Mirrors.
The last configuration step is to enable the core repository. Edit /etc/pacman.conf so that it has a [core] section which looks like the following:
[core]
#SigLevel = Required
#Server = ftp://ftp.example.com/foobar/$repo/os/$arch/
# The file referenced here should contain a list of 'Server = ' lines.
Include = /etc/pacman.d/mirrorlist
To enable other repositories, such as testing or extra, just duplicate the core repository example (above) and put the name of the desired repository inside of the square brackets instead of core.
If you have USE=curl and pacman-4.0.0 or later, this
section doesn't apply to you and you may skip to configuring
RootDir. Otherwise, you must set XferCommand.
For pacman-3.* or pacman-4.* with USE=-curl, internal fetching support is
disabled. pacman-3.* required libfetch, which is quite difficult to
package. In either case, using an external fetch tool works
adequately. (As a comparison, portage exclusively does its fetching
using external fetch tools). Thus, you will need to uncomment one of
the two XferCommand lines in /etc/pacman.conf. I recommend using the wget
line:
XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
If you do not have wget installed and do not want it, you could try the following configuration:
XferCommand = /bin/busybox wget -c -O %o %u
Be careful! You are not yet done. Do not start playing with pacman unless if you know what you are doing, because you may partially overwrite your Gentoo installation with archlinux packages.
You can tell pacman which directory to use as its default root path by specifying the RootDir option in /etc/pacman.conf. To specify /var/lib/arch as the chroot's path, use:
RootDir = /var/lib/arch
This directive in the configuration file is equivelant to pacman(8)'s -r option. I recommend to set this option so that use of pacman doesn't inadvertently overwrite parts of your Gentoo installation.
On Gentoo systems, when one wants to install packages into a place other than /, one sets the ROOT environment variable (see make.conf(5)). For pacman(8), one uses the -r flag or RootDir. But first, the chroot directory must be prepared. The following describes how to set up a chroot in /var/lib/arch (and is based on arch's Install from Existing Linux wiki page).
First, create the chroot directory itself and then the required /var/lib/pacman subdirectory. Then ask pacman to, using that root directory, download repository metadata:
# mkdir -p /var/lib/arch/var/lib/pacman
# pacman -r /var/lib/arch -Sy
If you have recently upgraded pacman and get some interesting errors, check out the upgrade notes.
Then, you may install arch's base package set (analogous to Gentoo's @system set).
# pacman -r /var/lib/arch -S base
Before entering a chroot, one must set up the pseudo filesystems that most tools depend on first. These include /dev, /sys, and /proc. The following setup will be lost be lost after rebooting unless if you add the commands to a startup script (such as in /etc/conf.d/local).
# mkdir -p /var/lib/arch/{dev,proc,sys}
# mount -o bind /dev /var/lib/arch/dev
# mount -o bind /proc /var/lib/arch/proc
# mount -o bind /sys /var/lib/arch/sys
There's a good chance you'll also want a copy of your DNS resolver's settings.
# cp {,/var/lib/arch}/etc/resolve.conf
The chroot should now be usable! If there are any problems in the information above, please contact me using the email address in the footer. You may now enjoy your chroot with the following command:
# chroot /var/lib/arch
Forgetting to pass the proper -r option to pacman may cause pacman to attack your beautiful Gentoo install! Whenever issuing a pacman command, check the following:
# cat /etc/issue
Arch Linux \r (\n) (\l)
Of course, if the emerge command is unavailable,
then you're likely in an arch chroot. Then it is safe to use
pacman without its -r switch:
# emerge
bash: emerge: command not found
Like any package manager, pacman does get updated and improved by its developers. Pacman's own local package database needs to be updated occasionally as its format is improved. When this happens, you might get the following output:
# pacman -r /var/lib/arch -Sy
:: Synchronizing package databases...
error: local database version is too old
error: failed to init transaction (database is incorrect version)
try running pacman-db-upgrade
Now, running pacman-db-upgrade without any arguments isn't enough. You need to tell it to the path of pacman's package database within your chroot. If your chroot is /var/lib/arch, this is accomplished with:
# pacman-db-upgrade /var/lib/arch/var/lib/pacman
==> Pre-3.5 database format detected - upgrading...
==> Done.
Now you may continue adjusting your chroot.