~x86 With NPTL and GCC 3.4.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 ENCOUTERED
WHILE FOLLOWING THIS GUIDE.
This Install is based upon a Stage 1 tarball, though a Stage 2 or Stage 3 tarball can be used. 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/2005.1/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/2005.1-r1/stages/x86/stage1-x86-2005.1-r1.tar.bz2Code: Select all
wget http://gentoo.osuosl.org/releases/x86/2005.1-r1/stages/x86/stage1-x86-2005.1-r1.tar.bz2.md5Code: Select all
md5sum -c stage1-x86-2005.1-r1.tar.bz2.md5Code: Select all
tar xvjpf stage1-x86-2005.1-r1.tar.bz2Download a portage snapshot:
Code: Select all
wget http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2Code: Select all
tar xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /mnt/gentoo/usrCode: 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"The first part of the build uses gcc-3.3.5 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.
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 November 30, 2005, 11:45 AM:
Code: Select all
date 113011452005Code: Select all
emerge --syncPlace the following in you /etc/portage/packages.use
Code: Select all
sys-libs/glibc userlocales
sys-devel/libperl ithreads
dev-lang/perl ithreadsCode: Select all
en_US/ISO-8859-1
en_US.UTF-8/UTF-88 Start building The system.
8.1 LFS chap. 5, part 1
The build order according to LFS is: binutils, gcc, linux-headers, and the glibc. So here is our firs build packages:
Code: Select all
emerge --nodeps binutils gcc-config libstdc++-v3 gccCode: Select all
gcc-config -l
[1] i386-pc-linux-gnu-3.3.5-20050130 *
[2] i386-pc-linux-gnu-3.3.5-20050130-hardened
[3] i386-pc-linux-gnu-3.3.5-20050130-hardenednopie
[4] i386-pc-linux-gnu-3.3.5-20050130-hardenednopiessp
[5] i386-pc-linux-gnu-3.3.5-20050130-hardenednossp
[6] i686-pc-linux-gnu-3.4.4
[7] i686-pc-linux-gnu-3.4.4-hardened
[8] i686-pc-linux-gnu-3.4.4-hardenednopie
[9] i686-pc-linux-gnu-3.4.4-hardenednopiessp
[10] i686-pc-linux-gnu-3.4.4-hardenednossp
gcc-config 6
env-update
source /etc/profileCode: Select all
emerge --nodeps linux-headers glibcNow 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 -D_FILE_OFFSET_BITS=64"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
ACCEPT_KEYWORDS="~x86"
MAKEOPTS="-j2"
PORTAGE_NICENESS=3
AUTOCLEAN="yes"
FEATURES="distlocks sandbox userpriv usersandbox"
USE="nptl -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.
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 tcl =sys-devel/autoconf-2.13 autoconf autoconf-wrapper automake expect dejagnu 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, vim, 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, sysklogd, sysvinit, tar, udev, and util-linux.
Before we emerge the next list of packages we need to remove gcc-3.3.6.
Code: Select all
emerge -P gccCode: Select all
emerge -e 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 lilo gzip hotplug coldplug 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 -D_FILE_OFFSET_BITS=64"
CXXFLAGS="${CFLAGS} -fvisibility-inlines-hidden"
ACCEPT_KEYWORDS="~x86"
MAKEOPTS="-j2"
PORTAGE_NICENESS=3
AUTOCLEAN="yes"
FEATURES="distlocks sandbox userpriv usersandbox"
USE="nptl < 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 systemWe already have the system logger built in the previous steps, so to enable it run:
Code: Select all
rc-update add sysklogd defaultCode: Select all
emerge xinetd fcron sysfsutils dhcpcd coldplug gentoolkit acpid ntpCode: 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 coldplug default
rc-update add acpid default
rc-update add ntp-client default11 Set the Time Zone Symlink.
This example displays the available time zone selections for the Western Hemisphere:
Code: Select all
# ls /usr/share/zoneinfo/AmericaCode: Select all
# rm /etc/localtime
# ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime
Sun Mar 27 19:32:50 CST 200511.1 Get it Right for Daylight Savings Time.
The previous example showed how to select a city when setting the timezone symlink. It is my opinion that you should always choose a city that is in your time zone, and use the city to set the time zone symlink. You should NEVER choose a time zone as your symlink for the setting the time zone. Here's why:
I live in Chicagoland (BobP lives in Chicagoland, but I live in the Dallas-Fort Worth area. However Chicago is the closest city in MY timezone that is listed). By setting the timezone symlink to the nearest major city, Chicago, I don't have to worry about implementing Daylight Savings Time. Linux is smart enough to spring forward and fall back so that no changes to the system time are necessary on my part. This past weekend, when Chicago changed from Central Standard Time to Central Daylight Time, I watched with glee as the clocks on all of my linux PCs ticked from 01:59:59 CST to 03:00:00 CDT. (Just in case you were wondering, THAT is confirmation that I am a basement-dwelling linux g33k!) If I had made the mistake of setting the timezone symlink to CST, then linux would have kept my PC's clock on CST, even though the city that I live in had switched to CDT. In this case, I would either have to manually change my clock over from CST to CDT, or learn to live with a PC who's clock is off by an hour.
12 Eliminate system clock skew
Code: Select all
ntpdate -b -u pool.ntp.org13 Build the kernel
Now we are ready to build the kernel. I use the vanilla-sources in this guide, however you can use anyother kernel sources you like.
Code: Select all
emerge vanilla-sourcesCode: Select all
ls -l /usr/src
total 1
lrwxrwxrwx 1 root root 16 Dec 2 05:19 linux -> linux-2.6.15-rc3
drwxr-xr-x 19 root root 712 Dec 2 05:19 linux-2.6.15-rc3Code: 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/kernel-2.6.12.5
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 Steven Warren. Released under the Creative Commons Attribution-ShareAlike license version 2.0.







