~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. 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 bootstrap -multislot"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. 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 original 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.
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 010608452006Code: Select all
emerge --syncPlace the following in you /etc/portage/package.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 glibc. So here is our first build packages:
Code: Select all
emerge --nodeps binutils gcc-config libstdc++-v3 gcc linux-headers glibcCode: 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.5 *
[7] i686-pc-linux-gnu-3.4.5-hardened
[8] i686-pc-linux-gnu-3.4.5-hardenednopie
[9] i686-pc-linux-gnu-3.4.5-hardenednopiessp
[10] i686-pc-linux-gnu-3.4.5-hardenednossp
Code: Select all
gcc-config 6
env-update
source /etc/profileCode: Select all
emerge -P gccFirst we need to get the /usr/share/zoninfo data so:
Code: Select all
emerge 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 -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.
Start the emerge.
Code: 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 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 vanilla-sourcesCode: Select all
ls -l /usr/src
total 1
lrwxrwxrwx 1 root root 16 Dec 2 05:19 linux -> linux-2.6.15
drwxr-xr-x 19 root root 712 Dec 2 05:19 linux-2.6.15Code: Select all
cd /usr/src/linux
make menuconfigCode: Select all
make && make modules_install && make install13 Now to make your system bootable.
Edit /etc/fstab to match your partition layout.
Code: Select all
/dev/hda1 /boot reiserfs noauto,noatime,notail 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.15
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-2006 Steven Warren. Released under the Creative Commons Attribution-ShareAlike license version 2.5.



