~x86 and GCC 4.x.x
Building Gentoo Linux From Scratch Style
Since the Gentoo Documentation team has deprecated Stage 1 and 2 there has been somewhat of an uproar in the Gentoo community. As I followed this I did some research on what is done in bootstrap.sh and discovered that the tool chain is not properly built. While it works fairly well it seems to me to that it could be done better, so the reason for this guide. We will build Gentoo from the ground up using the portage tools to build the system in the same manor as "Linux From Scratch", hereafter referred to as LFS. This will give us a properly built tool chain for a good foundation for the rest of our system.
WARNING: This is an advanced install method for advanced users. This method use the ~x86 branch, so be aware that you could run into some broken packages.
THIS IS NOT A GENTOO SUPPORTED INSTALL, SO DO NOT
BOTHER THE DEVELOPERS WITH ANY PROBLEMS ENCOUNTERED
WHILE FOLLOWING THIS GUIDE.
This Install is based upon a Stage 1 tarball. The main reason for using a Stage 1 tarball is that it provides a minimal installation environment for building our system, which should give us a cleaner environment in which to build the tool chain. During the installation bootstrap.sh will NOT be used, instead we will emerge the system following as closely as portage allows chapter 5 & 6 of the Linux From Scratch book to build the base system. There some dependency requirements in portage that will require some changes in the build process, but these are minor.
First thing we need to do is get either the Gentoo Minimal Installation CD or the Gentoo Universal Installation CD from http://gentoo.osuosl.org/releases/x86/2007.0/installcd, and then burn it to a CD. My recommendation is to use the Minimal CD as it is a smaller download. Use this CD to boot your computer.
1 Setup the network.
First thing to check is that your NIC is setup correctly.
First try ifconfig
Code: Select all
ifconfig
eth0 Link encap:Ethernet HWaddr 00:0D:56:32:6B:31
inet addr:192.168.1.6 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20d:56ff:fe32:6b31/64 Scope:Link
UP BROADCAST NOTRAILERS RUNNING MULTICAST MTU:1500 Metric:1
RX packets:534293 errors:0 dropped:0 overruns:0 frame:0
TX packets:907104 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:364028765 (347.1 Mb) TX bytes:116194376 (110.8 Mb)
Interrupt:11
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)Now ping www.google.com. If it works, then we are ready to proceed to the next step.
2 Prepare your hard disk.
Now to partition the hard disk. Use fdisk or cfdisk for this. I would recommend the following partition layout for a Linux only workstation:
Code: Select all
/dev/hda1 /boot
/dev/hda2 /
/dev/hda3 /home
/dev/hda4 swapNow format your filesystems:
Code: Select all
mkreiserfs /dev/hda1
mkreiserfs /dev/hda2
mkreiserfs /dev/hda3Mount the filesystems:
Code: Select all
mount /dev/hda2 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/hda1 /mnt/gentoo/bootWe do not need to mount the /home partition at this time.
3 Install Stage 1 and portage.
Now enter the Gentoo partition:
Code: Select all
cd /mnt/gentooCode: Select all
wget http://gentoo.osuosl.org/releases/x86/2007.0/stages/stage1-x86-2007.0.tar.bz2
Code: Select all
wget http://gentoo.osuosl.org/releases/x86/2007.0/stages/stage1-x86-2007.0.tar.bz2.DIGESTS
Code: Select all
md5sum -c stage1-x86-2007.0.tar.bz2.DIGESTSCode: Select all
tar xvjpf stage1-x86-2007.0.tar.bz2Download a portage snapshot:
Code: Select all
wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2
Code: Select all
tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usr/usr/portage/profiles/default-linix/x86/no-nptl. I am using the /usr/portage/profiles/default-linux/x86/2007.0 profile for my machine.
Code: Select all
rm -f /etc/make.profile
ln -s /usr/portage/profiles/default-linux/x86/2007.0 /etc/make.profile
Code: Select all
CHOST="i686-pc-linux-gnu"
CFLAGS="-O2 -march=pentium4 -fomit-frame-pointer -pipe"
CXXFLAGS=${CFLAGS}
ACCEPT_KEYWORDS="~x86"
MAKEOPTS="-j2"
PORTAGE_NICENESS=3
AUTOCLEAN="yes"
FEATURES="distlocks sandbox userpriv usersandbox"
USE="nptl nptlonly bootstrap -fortran -multislot"The first part of the build uses gcc-4.1.1 which is part of the Stage 1 tarball, so we need to use the more mild CFLAGS and CXXFLAGS to build with. After we finish the first part of the build we will change the CFLAGS and CXXFLAGS to what we will use to build the system with. Set the -march flag to match your arch. According to /usr/portage/profiles/use.desc entry on the bootstrap USE flag:
bootstrap - !!internal use only!! DO NOT SET THIS FLAG YOURSELF!, used during or
iginal system bootstrapping
Since step 8 bootstraps the the tool chain it makes sense to use it here. The -multislot USE flag eliminates the need to use gcc-config to change the default compiler. ( It worked on two test builds on my test machine. YMMV,) We will remove the bootstrap and -multislot flags before starting step 9.
With gcc 4.x.x we have to add the -fortran flag for the first two make.conf files or gcc will fail to build. This flag will be removed befor starting step 10.
4 Chrooting.
First copy the dns info.
Code: Select all
cp -L /etc/resolv.conf /mnt/gentoo/etc/resolv.confCode: Select all
mount -t proc none /mnt/gentoo/procCode: Select all
mount -o bind /dev /mnt/gentoo/devCode: Select all
cp /proc/mounts /mnt/gentoo/etc/mtabCode: Select all
chroot /mnt/gentoo /bin/bash
env-update
source /etc/profileNow set the correct time as this is important to our build. We can't set the time zone symlink at this time a zone info is not part of the Stage 1 tarball. We will set the symlink later. The format of the date command is MMDDHHMMYYYY, where MM is the month, DD is the day, HHMM is the time, and YYYY is the year. For January 05, 2007, 11:45 AM:
Code: Select all
date 010511452007Code: Select all
emerge --syncSetting user locales is now easier. my /etc/local.gen is listed below
Code: Select all
# This file names the list of locales to be built when glibc is installed.
# The format is <locale>/<charmap>, where <locale> is a locale from the
# /usr/share/i18n/locales directory, and <charmap> is name of one of the files
# in /usr/share/i18n/charmaps/. All blank lines and lines starting with # are
# ignored. Here is an example:
en_US.UTF-8 UTF-8
en_US ISO-8859-1
ja_JP.EUC-JP EUC-JP
ja_JP.UTF-8 UTF-8
ko_KR.EUC-KR EUC-KR
ko_KR.UTF-8 UTF-8
zh_TW.EUC-TW EUC-TW
zh_TW.UTF-8 UTF-8
zh_TW BIG5
zu_ZA.UTF-8 UTF-8
zu_ZA ISO-8859-1Steps 8 and 9 replace bootstrap.sh.
8 Start building The system.
8.1 LFS chap. 5, part 1
The build order according to LFS is: binutils, gcc, linux-headers, and glibc. So here is our first build packages:
Code: Select all
emerge --nodeps --oneshot binutils gcc-config libstdc++-v3 gcc linux-headers glibcCode: Select all
gcc-config -l
[1] i686-pc-linux-gnu-4.1.2 *
If your gcc-config -l show different from above then,
Code: Select all
gcc-config 6
env-update
source /etc/profileCode: Select all
emerge -P gcc8.1.1 Set the Time Zone Symlink.
First we need to get the /usr/share/zoninfo data so:
Code: Select all
emerge --oneshot timezone-dataCode: Select all
# ls /usr/share/zoneinfoCode: Select all
# rm /etc/localtime
# ln -s /usr/share/zoneinfo/CST6CDT /etc/localtime
# date
Fri Jan 6 09:38:02 CST 20068.2 LFS chap. 5 part 2
Now we are ready for the second part of our build were we will recompile the tool chain against itself and add other tools to the system.
Before we start the next phase of building we will change our /etc/make.conf file to reflect how we want our system:
Code: Select all
CHOST="i686-pc-linux-gnu"
CFLAGS="-O3 -march=pentium4 -fforce-addr -fomit-frame-pointer -ftracer -pipe"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
ACCEPT_KEYWORDS="~x86"
MAKEOPTS="-j2"
PORTAGE_NICENESS=3
AUTOCLEAN="yes"
FEATURES="distlocks sandbox userpriv usersandbox"
USE="nptl nptlonly -fortran -X -tk"The next step is to complete LFS Chapter 5 portion of our install. LFS builds the following packages: tcl, expect, dejagnu, gcc, binutils, gawk, bzip2, gzip, diffutils, findutils, make, grep, sed, gettext, gpm, ncurses, patch, tar, texinfo, bash, m4, bison, flex, util-linux, and perl.
Tcl, expect, and dejagnu are used by LFS to run the test suites, as we will not run the test suites they wll not be built. This part will take a while to complete, so it may make a good time to go to Starbucks for some expesso.
Code: Select all
emerge --nodeps --oneshot =sys-devel/autoconf-2.13 autoconf autoconf-wrapper automake gcc binutils gawk bzip2 gzip diffutils findutils make grep sed gettext gpm ncurses patch tar sys-apps/texinfo bash bash-completion m4 bison flex util-linux gdbm perlapp-xemacs/texinfo
sys-apps/texinfo
Autoconf-2.13 is a must have dependency of expect. Gpm is a must have dependency of ncurses.
Since we are not building Xorg at this time we need to specify sys-apps/texinfo for portage to know which texinfo to build.
9. Emerge the LFS chap. 6 packages.
Now acording to LFS Chapter 6 we would build linux-headers, man-pages, glibc, binutils, gcc, coreutils, zlib, mktemp, iana-etc, findutils, gawk ncurses, readline, m4, bison, less, groff, sed, flex, gettext, inetutils, iproute, perl, texinfo, autoconf, automake, bash, file, libtool, bzip2, diffutils, kbd, e2fsprogs, grep, grub, gzip, hotplug, man, make, module-init-tools, patch, procps, psmisc, shadow, sysvinit, tar, udev, and util-linux.
Start the emerge.
Code: Select all
emerge -e --oneshot linux-headers man-pages glibc binutils gcc coreutils zlib findutils gawk ncurses sys-libs/readline vim m4 bison less groff sed flex gettext perl sys-apps/texinfo autoconf automake bash file libtool bzip2 diffutils kbd reiserfsprogs grep gzip hotplug man make module-init-tools patch procps psmisc shadow sysklogd sysvinit tar udev util-linuxAt this point you can edit you make.conf file to build your system how you like.
Code: Select all
CHOST="i686-pc-linux-gnu"
CFLAGS="-O3 -march=pentium4 -fforce-addr -fomit-frame-pointer -ftracer -pipe"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
ACCEPT_KEYWORDS="~x86"
MAKEOPTS="-j2"
PORTAGE_NICENESS=3
AUTOCLEAN="yes"
FEATURES="distlocks sandbox userpriv usersandbox"
USE="nptl nptlonly< anyother USE flags that you want>"
#CCACHE_SIZE="512M"Now to complete the building of our system and prepare for for building the kernel run:
Code: Select all
emerge -e systemNow we need to build some other useful utilities before we build the kernel. Feel free to use another bootloader, system logger, or editor if you want. I am using lilo as my bootloader, syslogd for my system logger, and vim as my editor.
Code: Select all
emerge xinetd fcron sysfsutils dhcpcd gentoolkit acpid ntp sysklogd vim liloCode: Select all
rc-update add net.eth0 default
rc-update add fcron default
rc-update add xinetd default
rc-update add sshd default
rc-update add hotplug default
rc-update add acpid default
rc-update add ntp-client default
rc-update add sysklogd default11 Eliminate system clock skew
Code: Select all
ntpdate -b -u pool.ntp.org12 Build the kernel
Now we are ready to build the kernel. I use the vanilla-sources in this guide, however you can use any other kernel sources you like.
Code: Select all
emerge gentoo-sourcesCode: Select all
ls -l /usr/src
total 4
lrwxrwxrwx 1 root root 22 Jan 5 11:17 linux -> linux-2.6.19-gentoo-r2
drwxr-xr-x 20 root root 4096 Jan 5 17:49 linux-2.6.19-gentoo-r2Code: Select all
cd /usr/src/linux
make menuconfigCode: Select all
make && make modules_install && make install14 Now to make your system bootable.
Edit /etc/fstab to match your partition layout.
Code: Select all
/dev/hda1 /boot reiserfs noauto,noatime 1 2
/dev/hda2 / reiserfs noatime,notail 0 1
/dev/hda3 /home reiserfs noatime 0 1
/dev/hda4 none swap sw 0 0
/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
/dev/fd0 /mnt/floppy auto noauto 0 0
proc /proc proc defaults 0 0
shm /dev/shm tmpfs nodev,nosuid,noexec 0 0Edit /etc/lilo.conf
Code: Select all
boot=/dev/hda
prompt
timeout=50
default=gentoo
image=/boot/vmlinuz
label=gentoo
read-only
root=/dev/hda2Code: Select all
/sbin/liloCode: Select all
passwd rootCode: Select all
exit
cd
umount /mnt/gentoo/proc /mnt/gentoo/dev /mnt/gentoo/boot /mnt/gentoo
rebootThanks:
BobP for the Stage 3/1 Install that helped inspire this guide.
The folks over at Linux From Scratch for the book that provided the final
inspiration for this guide.
The Gentoo developers that made portage flexible enough to pull this off.
Copyright (c) 2005-2007 Steven Warren. Released under the Creative Commons Attribution-ShareAlike license version 2.5.





