Gentoo chroot under JohnCompanies' servers HOWTO

JohnCompanies is, in all fairness, one of today's most interesting collocation providers out there. I don't think I need to discuss their supremacy from a technical, or monetary point of view; you can just read the facts and draw your own conclusions. But one of the things I do find specially distinctive about their service is the way they handle their business in general. There are a number of small things that give you, as a costumer, a sense of satisfaction that no money can buy. Specially if you're a Unix hacker.

One of those things I talk about is the reason why I'm writing this HOWTO right now. Their Linux-based collocation services involve a Red Hat system in the lower layers of the server. Well, you might not be particularly thrilled about having Red Hat as the operating system of your servers. After all, there are quite a few GNU/Linux distributions available today. What if Red Hat is not your favorite one? Fear not. JC endorse the use of technologies such as chrooted environments if you need them. In fact, they have recommended this approach so far if you happen to like a Debian system for your server. I do like the Debian GNU/Linux operating system, but there's another OS I happen to like a lot, and that's Gentoo.

That's where this document comes into the picture. It is intended as a guide for anyone who wants to install a Gentoo system under a chroot environment. It has details which are very specific to JohnCompanies RedHat-based servers, but it could be useful under similar setups (i.e. if you want to install a certain GNU/Linux flavor on top of another GNU/Linux system).
Copyright Information

Copyright (c) 2003-2004, Kapco Media Creators.

This work is licensed under the Creative Commons ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/sa/1.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

If you have any questions, please contact <leonardop@gentoo.org>
Who this document is for

This HOWTO is for anyone who wants to learn a bit more about topics such as chroot environments and the Red Hat and Gentoo operating systems. In effect, it could work as a walkthrough guide documenting the process of setting up a Gentoo system under one of the Linux-based servers provided by JohnCompanies.

I assume that you know the basics of working with Unix-like systems, particularly GNU/Linux; if you know enough to use a shell like bash, copy files around, run a text editor session and things like that, you're good to go. I also assume that you have a reasonable grasp of the Gentoo operating system; it would be best if you're familiar with the Portage model and the Gentoo-way of doing things.
Disclaimer

No liability for the contents of this documents can be accepted. Use the concepts, examples and other content at your own risk. As this is a new edition of this document, there may be errors and inaccuracies, that may of course be damaging to your system. Proceed with caution, and although this is highly unlikely, the author(s) do not take any responsibility for that.

All copyrights are held by their respective owners, unless specifically noted otherwise. Use of a term in this document should not be regarded as affecting the validity of any trademark or service mark.

Naming of particular products or brands should not be seen as endorsements.

You are strongly recommended to take a backup of your system before major installation and backups at regular intervals.
Credits

This document wouldn't have been possible without the work of Joe Drew, author of Setting up a Debian chroot under Red Hat, and, naturally, a big thank you goes to everyone at JohnCompanies, which provided valuable resources used in the writing of this HOWTO.

Also, thanks to ari, who provided a few tips to improve this document.
Feedback

Feedback is most certainly welcome for this document. Please send your additions, comments and criticisms to the following email address : <leonardop@gentoo.org>.
Gentoo Installation

Let's start by installing a very basic Gentoo system. The following instructions assume you're starting from a scratch system (as provided by JohnCompanies).
Downloading the stage 1 tarball

The first step is downloading the Gentoo stage1 tarball. You should take a look at the list of Gentoo mirrors and choose one of them for this purpose. If you are not sure about which one to use, you can use something like the following perl script to ping them:

Example 1. The find-gentoo-mirror.pl script

#! /usr/bin/perl -w
use strict;

use vars qw(@mirrors $ping_command $best $min);
@mirrors = qw(www.ibiblio.org ftp.gtlib.cc.gatech.edu
csociety-ftp.ecn.purdue.edu mirror.iawnet.sandia.gov
ftp.ussg.iu.edu ftp.ucsb.edu gentoo.mirrors.pair.com
gentoo.seren.com gentoo.noved.org gentoo.chem.wisc.edu
adelie.polymtl.ca cs.ubishops.ca sunsite.ualberta.ca);

$ping_command = '/bin/ping';

$best = '';
$min = 9999;

print "Sending PING packets to mirrors\n";

foreach my $mirror (@mirrors) {
print " $mirror .. ";
my $output = `$ping_command -c 3 $mirror`;

my ($time) = ($output =~ /^rtt.*=\s*[\d\.]+\/([\d\.]+)\/.*$/m);

if ($time) {
print "$time\n";
if ($time < $min) {
$min = $time;
$best = $mirror;
}
}
else
{ print "?\n" }
}

print "\nApparently, $best is the best mirror for you\n";

This script outputs the ping times for a list of domains, and suggests the one with the lowest value:

[root@test root]# ./find-gentoo-mirror.pl
Sending PING packets to mirrors
www.ibiblio.org .. 69.838
ftp.gtlib.cc.gatech.edu .. 54.021
csociety-ftp.ecn.purdue.edu .. 66.698
mirror.iawnet.sandia.gov .. 52.943
ftp.ussg.iu.edu .. 73.395
ftp.ucsb.edu .. 12.828
gentoo.mirrors.pair.com .. 72.395
gentoo.seren.com .. 208.895
gentoo.noved.org .. 54.708
gentoo.chem.wisc.edu .. 75.406
adelie.polymtl.ca .. 82.697
cs.ubishops.ca .. 86.608
sunsite.ualberta.ca .. 88.970

Apparently, ftp.ucsb.edu is the best mirror for you

Once you know which mirror to use, browse around its directory structure and find the tarball for the stage 1. It usually lies under something like gentoo/releases/VERSION/x86/stages, where VERSION is the particular version of Gentoo you want to install. [1] Once you locate the appropriate file, you can download it using wget.

[root@test root]# wget ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/releases/1.4_rc4/x86/x86/stages/stage1-x86-1.4_rc4.tar.bz2
--02:34:22-- ftp://ftp.ucsb.edu/pub/mirrors/linux/gentoo/releases/1.4_rc4/x86/x86/stages/stage1-x86-1.4_rc4.tar.bz2
=> `stage1-x86-1.4_rc4.tar.bz2'
Resolving ftp.ucsb.edu... done.
Connecting to ftp.ucsb.edu[128.111.24.43]:21... connected.
Logging in as anonymous ... Logged in!
==> SYST ... done. ==> PWD ... done.
==> TYPE I ... done. ==> CWD /pub/mirrors/linux/gentoo/releases/1.4_rc4/x86/x86/stages ... done.
==> PORT ... done. ==> RETR stage1-x86-1.4_rc4.tar.bz2 ... done.
Length: 11,253,769 (unauthoritative)

100%[====================================>] 11,253,769 815.28K/s ETA 00:00

02:34:36 (815.28 KB/s) - `stage1-x86-1.4_rc4.tar.bz2' saved [11253769]

[root@test root]#

The chroot jail

Alright, we have the stage 1 tarball, so let us extract its contents. I'd recommend doing so under a directory such as /gentoo.

[root@test root]# mkdir /gentoo
[root@test root]# cd /gentoo
[root@test gentoo]# tar -xvjpf ~/stage1-x86-1.4_rc4.tar.bz2

(.. long list of files ..)
Now is a good time to create the chroot jail in which our Gentoo system will live. But before that, we better make sure that we will end up using our current process table and /etc/resolv.conf file.

[root@test gentoo]# mount -t proc proc /gentoo/proc
[root@test gentoo]# cp /etc/resolv.conf /gentoo/etc/
[root@test gentoo]# chroot /gentoo /bin/bash
bash-2.05b#

Great! We are now inside a chrooted environment, and, as far as we are concerned, it's like we got a fresh system we can toy with; this is where the fun begins. Before going any further, let us emend the environmont and spice up our shell session (nevermind the note from the env-update command.)

bash-2.05b# env-update
>>> Note: /etc/make.profile/make.defaults isn't available.
an 'emerge sync' will probably fix this.
>>> Regenerating /etc/ld.so.cache...
bash-2.05b# source /etc/profile
test / #

Getting the current Portage Tree

It is time now to obtain a crucial element of any Gentoo system: the Portage tree. It is basically a huge collection of ebuilds and other files used to build every package under a Gentoo system. This is as easy as typing:

test / # emerge sync

Downloading the entire Portage tree can take a few minutes. Once the command emerge completes, you will have a local copy of the current Portage tree under /usr/portage.
Customizing /etc/make.conf and bootstrapping

One of the critical steps we must take before calling this a Gentoo system, is bootstrapping. In Gentoo, this is done with the aid of the bootstrap.sh script. Beware that bootstrapping a Gentoo system implies things like building (and even rebuilding) packages like binutils, gcc, gettext and glibc. Do you have any idea how long can this last? You will know now.

As this will be the first time your Gentoo system emerges a package, compiling it from its sources, it is a good idea to edit the /etc/make.conf file now. The stage1 tarball comes with the nano editor, which might come handy in this situation (don't panic, you can install your favorite editor later on..)

test / # nano -w /etc/make.conf

Inside this file you can declare a number of custom parameters that will be taken into account whenever you emerge a package. Customization is one of the things Gentoo is best known for, so you may want to read carefully about the many settings you can tweak here. Some interesting variables you can define in this file are USE, CFLAGS, CXXFLAGS, MAKEOPTS and FEATURES. Special care should be taken when customizing the value of USE, depending on the "personality" you want to give to your system. For instance, if you're building this system to be mainly oriented to server applications, chances are you're never going to need a X-Window-System. In that case, you would be better off excluding USE flags such as X, gnome and kde explicitly.

Example 2. Some variable definitions taken from my /etc/make.conf

USE="-alsa -apm -arts berkdb -cjk crypt -cups -dvd emacs -esd
-flash gd -gnome -gtk -gtk2 guile -java -kde libwww -motif mysql
ncurses nls pam perl postgres python -qt -quicktime readline -samba
spell ssl tcpd -truetype -X -Xaw3d xml xml2 zlib"

CFLAGS="-march=pentium3 -O2 -pipe"

CXXFLAGS="${CFLAGS}"

# Remember, the suggested number for parallel makes (-j) is:
# number of CPUs + 1.
MAKEOPTS="-j3"

FEATURES="sandbox buildpkg distcc usersandbox notitles noclean noauto
cvs keeptemp keepwork"

Once you are through editing /etc/make.conf, it is time to start the bootstrapping process:

test / # cd /usr/portage/
test portage # ./scripts/bootstrap.sh

The bootstrap script will take some time to complete. Be patient my friend, the reward will be worth it.
Things may seem to go wrong

The bootstrap process may end with an ugly message stating something like CATEGORY info missing from info chunk, aborting.... Don't worry about it, this complain will cease to exist when we emerge the minimal system packages in the next step. Despite the rude note, you can be confident that the bootstrap process has completed successfully.
Stage 2

Stage 2 involves the installation of basic system packages, required in a regular Gentoo system. Again, you can expect a long and boring stream of output from the commands being used to compile and install every package. Emerging the relevant packages take some time. I suggest you go and take a nap, or take a (really long) walk, spend time with your friends and family. Just don't stay staring at the screen waiting for the stage 2 to complete; it could be a bad idea. :)

The command to install all necessary system packages is emerge system. Using the -p flag you can preview the list of packages that would be emerged.

test portage # emerge system -p

These are the packages that I would merge, in order:

Calculating system dependencies ...done!
[ebuild N ] sys-apps/modutils-2.4.25
[ebuild N ] dev-python/python-fchksum-1.6.1-r1
[ebuild N ] app-shells/bash-2.05b-r5
[ebuild N ] sys-libs/readline-4.3-r4
[ebuild N ] sys-devel/gnuconfig-20030708
[ebuild N ] sys-devel/libtool-1.4.3-r1
[ebuild N ] sys-devel/m4-1.4
[ebuild N ] sys-libs/db-1.85-r1
[ebuild N ] sys-libs/db-3.2.9-r2
[ebuild N ] dev-libs/expat-1.95.6-r1
[ebuild N ] dev-lang/python-2.2.3-r1
[ebuild N ] app-shells/sash-3.4-r5
[ebuild N ] sys-libs/gdbm-1.8.0-r5
[ebuild N ] sys-apps/groff-1.18.1-r3
[ebuild N ] sys-apps/cronbase-0.2.1-r2
[ebuild N ] sys-apps/man-1.5l-r6
[ebuild N ] sys-devel/libperl-5.8.0
[ebuild N ] dev-lang/perl-5.8.0-r12
[ebuild N ] app-editors/nano-1.2.1
[ebuild N ] net-misc/dhcpcd-1.3.22_p4
[ebuild N ] net-misc/iputils-020927
[ebuild N ] dev-libs/popt-1.7-r1
[ebuild N ] net-misc/rsync-2.5.6-r2
[ebuild N ] dev-libs/openssl-0.9.6j
[ebuild N ] net-misc/wget-1.8.2-r2
[ebuild N ] sys-apps/bzip2-1.0.2-r2
[ebuild N ] sys-apps/kbd-1.06-r1
[ebuild N ] sys-apps/cpio-2.5
[ebuild N ] sys-apps/debianutils-1.16.7-r2
[ebuild N ] sys-apps/help2man-1.29
[ebuild N ] sys-apps/diffutils-2.8.4-r3
[ebuild N ] sys-apps/e2fsprogs-1.33
[ebuild N ] sys-apps/ed-0.2-r3
[ebuild N ] sys-apps/fbset-2.1
[ebuild N ] sys-apps/file-4.02
[ebuild N ] sys-apps/fileutils-4.1.11-r1
[ebuild N ] sys-apps/findutils-4.1.7-r4
[ebuild N ] sys-devel/autoconf-2.57-r1
[ebuild N ] sys-devel/flex-2.5.4a-r5
[ebuild N ] sys-apps/miscfiles-1.3-r1
[ebuild N ] sys-libs/cracklib-2.7-r7
[ebuild N ] dev-libs/glib-1.2.10-r5
[ebuild N ] sys-libs/pwdb-0.61-r4
[ebuild N ] sys-devel/automake-1.7.5-r2
[ebuild N ] sys-libs/pam-0.75-r11
[ebuild N ] sys-apps/shadow-4.0.3-r6
[ebuild N ] sys-apps/slocate-2.7-r2
[ebuild N ] sys-apps/gawk-3.1.3
[ebuild N ] sys-apps/grep-2.5.1-r1
[ebuild N ] sys-apps/gzip-1.3.3-r2
[ebuild N ] sys-apps/hdparm-5.4
[ebuild N ] sys-apps/less-381
[ebuild N ] sys-apps/man-pages-1.56
[ebuild N ] sys-apps/net-tools-1.60-r7
[ebuild N ] sys-apps/procps-3.1.9
[ebuild N ] sys-apps/psmisc-21.2-r3
[ebuild N ] sys-apps/setserial-2.17-r2
[ebuild N ] sys-apps/sh-utils-2.0.15
[ebuild N ] sys-apps/pam-login-3.11
[ebuild N ] sys-apps/sharutils-4.2.1-r6
[ebuild N ] app-arch/ncompress-4.2.4
[ebuild N ] sys-apps/tar-1.13.25-r3
[ebuild N ] sys-apps/textutils-2.1
[ebuild N ] sys-apps/util-linux-2.11z-r4
[ebuild N ] sys-apps/which-2.14
[ebuild N ] sys-devel/bc-1.06-r5
[ebuild N ] sys-devel/bin86-0.16.0
[ebuild N ] sys-devel/bison-1.35
[ebuild N ] sys-devel/make-3.80
[ebuild N ] sys-apps/tcp-wrappers-7.6-r4
[ebuild N ] net-misc/openssh-3.6.1_p2
[ebuild N ] sys-apps/devfsd-1.3.25-r3

test portage # emerge system

Final steps

Congratulations! You got yourself a Gentoo system. There are still a few things that need to be taken care of, though.
Setting up the timezone

Look under the /usr/share/zoneinfo directory and find the appropiate timezone file for you. Then create a symbolic link to it from /etc/localtime. For instance:

test portage # ln -sf /usr/share/zoneinfo/US/Central /etc/localtime

Installing a few basic software packages

Now that your system is practically ready, you may be anxious to install your favorite chunks of software. So let's jump right into the installation of some basic services. Personally, I like qmail as my MTA, the apache web server, bind for my DNS needs and proftpd. While we're at it, let's throw in a cron system and a system logger:

test portage # emerge sysklogd
test portage # emerge dcron
test portage # emerge qmail
test portage # emerge apache
test portage # emerge bind
test portage # emerge proftpd

Of course, you might have different taste in software. Feel free to emerge any packages you want. However, you don't need to do this right now. I'm mentioning this just to show you the basic process involved in the installation of software in Gentoo. Quite easy, isn't it? Keep in mind that sometimes, when you emerge a package, some specific instructions are shown at the end of the installation process. Make sure you read them!
Should you want to use metalog...

A contributor reported that metalog actually requires a kernel logger in order to work properly, and since JohnCompanies doesn't provide you with one, it may not be among the loggers available for this configuration. However, it should be easy to modify metalog to optionally not attempt opening the kernel log.

In order to start daemons, you should use the scripts available under /etc/init.d. But we'll talk about daemons in the following section.
The chroot-start.sh script

You may want your service daemons to start whenever your machine boots. In addition, it is always nice to have a central script which starts every service your server should provide. That's why we will create now the /etc/init.d/chroot-start.sh script. Inside this file, we will add a line for every service you want to start within the chroot jail. Make sure you run the depscan.sh script before anything else.

test portage # nano -w /etc/init.d/chroot-start.sh

Example 3. Contents of an imaginary /etc/init.d/chroot-start.sh

#! /bin/sh

/etc/init.d/depscan.sh

# Replace this list of services with the ones you have on your server.
for service in \
sysklogd dcron postgresql mysql clamd spamd svscan xinetd sshd \
pure-ftpd authdaemond courier-imapd apache named
do
/etc/init.d/${service} start
done

In addition, we will also create another script called chroot-stop.sh to provide an easy way to clean up everything before/after a system reboot.

Example 4. Contents of an imaginary /etc/init.d/chroot-stop.sh

#! /bin/sh

/etc/init.d/depscan.sh

# Replace this list of services with the ones you have on your server.
for service in \
sysklogd dcron postgresql mysql clamd spamd svscan xinetd sshd \
pure-ftpd authdaemond courier-imapd apache named
do
/etc/init.d/${service} stop || /etc/init.d/${service} zap
done

for pid in `find /var/run -name "*.pid"`
do
echo "Deleting $pid"
rm $pid
done

test portage # chmod 700 /etc/init.d/chroot-start.sh
test portage # chmod 700 /etc/init.d/chroot-stop.sh

Don't run this script yet. Your system is not going to blow up if you do it, but we better fix a few things outside the chroot jail before proceeding.
Avoiding troubles with a few services

A nice addition for your chroot-start.sh script could be the creation of some symbolic links to /dev/null intended to keep Gentoo from trying to run fsck on filesystems or set the system hostname and clock.

Example 5. Fooling dependency checks

source /etc/init.d/functions.sh

# obviate the startup of these dependencies
for dep in checkfs checkroot clock hostname localmount modules
do
ln -sf /dev/null "$svcdir/started/$dep"
done

Finally, and just in case, we should ensure that a file called softlevel exists under /var/lib/init.d. Otherwise, the init.d scripts could complain about it.

test portage # touch /var/lib/init.d/softlevel

Cleaning the hard disk

The Gentoo installation process sure requires some hard disk space. Now that you have installed all those packages, your system is still storing their sources, and all the temporary files created while compiling them. Package sources usually reside under /usr/portage/distfiles, and /var/tmp/portage is the place where portage does all its dirty work. You may want to clean that mess, as you will get a significant amount of space back in the process.

test portage # rm -rf /usr/portage/distfiles/*
test portage # rm -rf /var/tmp/portage/*

Tweaking the Red Hat system

We have finished now the hardest part of the job. Now we should make a few changes to the base system, so let us exit from the chroot jail:

test portage # exit
exit
[root@test gentoo]#

Files shared by Red Hat and Gentoo

There are a few files that should be common to both systems; the Red Hat base system and the Gentoo chroot environment. We have already made a copy of /etc/resolv.conf from the original Red Hat filesystem to /gentoo. Now let us do the same for fstab, hosts, hostname (creating it if it doesn't exist yet), and, as a bonus, we'll create a hard link to the /jc_traffic_dump file, which contains important data about your server's traffic.

In the redhat base, you might also want to link /dev/log to /gentoo/dev/log, and copy /etc/ssh/ssh_host_* to /gentoo/etc/ssh/.

[root@test gentoo]# cp /etc/fstab /gentoo/etc/
cp: overwrite `/gentoo/etc/fstab'? y

[root@test gentoo]# cp /etc/hosts /gentoo/etc/
cp: overwrite `/gentoo/etc/hosts'? y

[root@test gentoo]# echo test > /etc/hostname
[root@test gentoo]# cp /etc/hostname /gentoo/etc

[root@test gentoo]# ln /jc_traffic_dump /gentoo/jc_traffic_dump

Services sanity-check

Your Red Hat system may be running services that you don't need anymore, since they will be provided now by the Gentoo chroot. A simple chkconfig --list can tell us about those unnecesary processes.

[root@test gentoo]# chkconfig --list
rwhod 0:off 1:off 2:off 3:off 4:off 5:off 6:off
atd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
keytable 0:off 1:on 2:on 3:off 4:off 5:off 6:off
syslog 0:off 1:off 2:on 3:on 4:on 5:on 6:off
iptables 0:off 1:off 2:on 3:on 4:on 5:on 6:off
gpm 0:off 1:off 2:on 3:off 4:off 5:off 6:off
httpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
lpd 0:off 1:off 2:on 3:off 4:off 5:off 6:off
kudzu 0:off 1:off 2:off 3:off 4:off 5:off 6:off
nscd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
sendmail 0:off 1:off 2:on 3:on 4:on 5:on 6:off
squid 0:off 1:off 2:off 3:off 4:off 5:off 6:off
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
snmpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
snmptrapd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
xfs 0:off 1:off 2:on 3:off 4:off 5:off 6:off
netfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
random 0:off 1:off 2:on 3:off 4:off 5:off 6:off
rawdevices 0:off 1:off 2:off 3:off 4:off 5:off 6:off
named 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ipchains 0:off 1:off 2:on 3:off 4:off 5:off 6:off
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
identd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
portmap 0:off 1:off 2:off 3:off 4:off 5:off 6:off
postgresql 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rstatd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rusersd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
rwalld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off
anacron 0:off 1:off 2:on 3:off 4:off 5:off 6:off
xinetd 0:off 1:off 2:off 3:on 4:on 5:on 6:off
ypbind 0:off 1:off 2:off 3:off 4:off 5:off 6:off
yppasswdd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ypserv 0:off 1:off 2:off 3:off 4:off 5:off 6:off
ypxfrd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
xinetd based services:
chargen-udp: off
rsync: off
rexec: off
rlogin: off
rsh: off
chargen: off
daytime-udp: off
daytime: off
echo-udp: off
echo: off
services: off
servers: off
time-udp: off
time: off
finger: off
imap: off
imaps: off
ipop2: off
ipop3: off
pop3s: off
ntalk: off
talk: off
telnet: off
wu-ftpd: off

As my Gentoo system already has a cron system, an MTA, and a web server, we will desactivate and stop them now, along with the xinetd super-server. Replace these services with the ones that apply to your own system.

[root@test gentoo]# chkconfig xinetd off
[root@test gentoo]# chkconfig crond off
[root@test gentoo]# chkconfig sendmail off
[root@test gentoo]# chkconfig httpd off

[root@test gentoo]# /etc/init.d/xinetd stop
Stopping xinetd: [ OK ]
[root@test gentoo]# /etc/init.d/crond stop
Stopping crond: [ OK ]
[root@test gentoo]# /etc/init.d/sendmail stop
Shutting down sendmail: [ OK ]
[root@test gentoo]# /etc/init.d/httpd stop
Stopping httpd: [ OK ]

Important

Make sure you do not stop services like ssh (if you are working under a ssh session, as is the case in this example) and network.

Youn can now add a line in your /etc/rc.local in order to run the chroot-start.sh script when the machine boots.

Example 6. A sample /etc/rc.local file

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
chroot /gentoo su -c /etc/init.d/chroot-start.sh -

After this, we're pretty much done. You may want to manually run the chroot-start.sh script now.

[root@test gentoo]# chroot /gentoo su -c /etc/init.d/chroot-start.sh -

A few things may go wrong here, like setting the system clock. It is alright. Just make sure all your services get started.
The end

So, that's about it. If you want to enter the Gentoo environment back again, you can do so with something like chroot /gentoo su -.

[root@test gentoo]# chroot /gentoo su -
localhost root # cat /etc/gentoo-release
Gentoo Base System version 1.4.3.8p1

For convenience, you may want to run another ssh daemon under Gentoo (binded to a different port or IP address than the currently active ssh daemon) so you can connect to both of your sshd processes. The rest is all up to you.

Have fun with your Red Hat/Gentoo hybrid, and Happy Hacking!
Further Information
Web Links

There is wealth of information one should go through when setting up things like chroot jails and installing new operating systems. The following web pages might be relevant to the topics being discussed:
Setting up a Debian chroot under Red Hat describes a similar procedure, only it involves Debian instead of Gentoo.

The Gentoo Linux installation handbook document is a must-read. There are segments of this HOWTO that are almost verbatim copies of some of the directions included there. Moreover, by reading that document you will most certainly learn a great deal about not only Gentoo Linux, but GNU/Linux systems in general.

In a similar fashion, you can't really say you are a Gentoo user before having read the Portage manual. It is a vital reference when maintaining Gentoo systems.