Do you Gentoo?
June 15th, 2004 • Linux
Finally, I got my perfect Gentoo installation. In the last couple of weeks I’ve been installing, formatting, reinstalling Gentoo like crazy, I was so eager to learn the ins’ and out’s of the portage, ebuilds, the utilities, and I must say… I’m very impressed!
Well, why wouldn’t I?! Gentoo is a very stable system, it’s easy to use, straight to the point (well maybe not the installation process, but still), and for the first time, I get a distribution that doesn’t try to shove all it’s applications down my throat, when I want something I can ask for it, I don’t need a system trying to tell me what to do.
I know I had to get through a tiresome installation, I had to redo a lot of work, I had to wait for about 12 hours for XFree, Qt and KDE to complete, but it was totally worth it, trust me, the performance I gained was too good to be true. I’ve tried Fedora Core 2, tried Mandrake 10, SuSE 9, they were all good, but they were nothing compared to a fully tweaked Gentoo system in terms of performance.
What I really like about Gentoo, is that you can actually choose what you like, you don’t have to stick to somebody else’s compilation and choice of packages, directory structure, kernel modules, tons of drivers and hardware auto-detection. With Gentoo, you can ask for whatever kernel you need, you get to choose what’s compiled and what’s not, you tell it whether to use MMX, 3DNow, SSE/SSE2, and all those buzz-word-sounding acronyms, you end up with a system that can only run on your computer, your hardware, your choices, not somebody else’s, you don’t need hardware detection anymore, you compiled all you need and that’s it, let the kernel do it’s stuff.
Most of the installation is very well documented in gentoo’s handbook, but that isn’t enough to get a full-fledged Linux up and running, so I’ll try to be a bit more useful and talk a little about my installation experience, though it wasn’t very pleasant, I finally liked what I saw. This isn’t meant to replace Gentoo’s handbook, I’m not going to repeat what Gentoo guys already documented, in fact, some steps are even omitted.
Well, here goes:
Booting
First of all you need to boot to Linux, any Linux that is, you only need a connection to the internet to download the stage tarball and do the rest. Knoppix is a very good choice, though it might slow down the compilation process, since it already loads a lot into memory. The only difference is that mounting /proc in Knoppix isn’t done like in the handbook.
Knoppix: mount -o bind /proc /mnt/gentoo/proc Gentoo LiveCD: mount -t proc none /mnt/gentoo/proc
Setup your network if it’s not already up, setup partitions, download a stage tarball and untar it (for more information about stages, please refer to Gentoo’s handbook). I chose a stage1 tarball, since I’d like to optimize my compiler settings to squeeze the most performance, I also think that anyone who’s up for Gentoo shouldn’t choose anything else. Granted, I can get a Gentoo server up and running in less than an hour using a stage3 tarball, but I would be missing all the fun :)
Now we get to the whole point of choosing Gentoo… customization. in /etc/make.conf, you can edit compiler options, those are added to compiler arguments when compiling various packages. Unfortunately, vi isn’t the default editor in Gentoo’s LiveCD, you’ll have to stick with nano, but who cares, you’ll get vi later on.
nano -w /etc/make.conf
… and add -march settings to CFLAGS, note that -march implies -mcpu, so you shouldn’t have both, just delete -mcpu and replace it with -march=<your-architecture>, that can be i386, athlon-xp, sparc, etc. Refer to GNU C Compiler manual for more information.
A note worth remembering, that -mcpu does optimize the binaries to run on a certain CPU, although it they still run on i386, while -march does more optimization, but the resulting binaries can only run on the chosen architecture.
I chose not to use -O3 or -Os since some packages might break with these, but I added other optimization settings, like -pipe which doesn’t affect the resulting binaries, although it speeds compilation significantly. So here’s how my CFLAGS look like:
CFLAGS="-O2 -march=athlon-xp -m3dnow -mmmx -msse -mfpmath=sse -pipe -fomit-frame-pointer"
There’s also CHOST, which in my case was i686-pc-linux-gnu. Stage3 users should not edit this.
Now for USE settings. For those who are wondering what’s USE, it’s what makes Gentoo fun! Here’s how it works: suppose you want to install Apache without SSL support, you tell Gentoo (actually it’s emerge, but we’ll get to that later) not to USE ssl, or on other words USE=”-ssl”. Also, suppose you don’t want KDE to be compiled at all, you want a system fully optimized to run Gnome, you tell Gentoo not to USE KDE and Qt, that is USE=”-kde -qt”. Sometimes, there are packages that have extra options but they’re not compiled by default, you can add that to USE, for instance, Samba can be compiled with ClamAV to scan files on the fly, but that’s not enabled by default, so I added oav to USE. That’s basically what’s USE is all about, so what you’d want to do is to set all USE flags that you might use then forget about it. What’s good about this USE, is that it can be changed via command line, if there are certain features you’d like to exclude from USE when emerging a certain package, for instance, the following code compiles <package-name> without Java support, it doesn’t matter if Java is installed or not, what matters is that this package can do Java:
USE="-java" emerge <package-name>
For the interested, here are my USE values in /etc/make.conf:
USE="nptl 3dfx 3dnow sse acpi alsa aim apache2 apm bidi cdr ssl divx4linux DVD gd gpm gtkhtml icq IMAP jabber java maildir mailwrapper mailbox mmx mozilla pic postgres samba sqlite SVG tcpd unicode USB vhost xvid yahoo oav"
Cute, isn’t it? Except, one wouldn’t figure out all available USE settings without reading use.desc, located in /usr/portage/profiles/, which becomes available after syncing the portage, that’s the next step…
Chroot and Bootstrap
After customizing /etc/make.conf, it’s time for us to chroot to /mnt/gentoo (assuming that’s were it’s mounted), run “emerge sync” and we’re all set for the bootstrapping. Now here’s what you might want to know, bootstrapping is the process of compiling certain programs like gcc, glibc, coreutils, and others in order to use them for later compilation, this is how you get an optimized compiler.
Now here’s a couple of traps the many new Gentoo addic.., err users fall into. When you want to bootstrap, don’t run bootstrap-2.6.sh, even if you want to compile a 2.6 kernel, it has nothing to do with it. The only difference is that it emerges a package called linux-headers during the bootstrap, but bootstrap.sh fixes a nasty bug that bootstrap-2.6.sh isn’t very aware of. So why would anybody want linux-headers? Well, I needed them to add NPTL (Native POSIX Thread Library for Linux) support to my glibc, which isn’t done by default, I had to emerge a 2.6 linux-headers before bootstrapping, then run bootstrap.sh.
How to compile glibc with NPTL
First of all, add nptl to your USE flags (i.e. USE=”nptl mmx all-the-rest”), this would tell emerge to add NPTL support when compiling glibc during bootstrap. Then, create a local portage overlay in say /usr/local/portage and copy linux-headers to it. You should end up with a directory layout looking like this: /usr/local/portage/sys-kernel/linux-headers/, now edit linux-headers-2.6.x.ebuild and add x86 to KEYWORDS after -*, run “emerge linux-headers” and you should be done. Only make sure you did emerge the headers matching with your kernel version.
Why have we done this and didn’t edit the ebuild directly? In Gentoo, every update syncs the portage tree with the latest available portage, which overrides any custom editions we have made to any file, this is why there’s a portage overlay feature in Gentoo. emerge consults the portage overlay directory first, before emerging, and if it finds the package it’s looking f or in the overlay first, it emerges it rather than using the package in the portage tree. You’d only need to add a PORTDIR_OVERLAY=/usr/local/portage to /etc/make.conf before doing so.
By the way, there’s a common myth that when you want to compile a 2.6 kernel, you have to emerge a 2.6 linux-headers. This is totally wrong! Using a 2.4 linux-headers you still can compile a 2.6 kernel, 2.4 headers are perfectly compatible with 2.6 kernels. You’d only need 2.6 headers when you plan to have NPTL support, which is also doable with 2.4 headers, although more difficult.
Now, we’ve emerged linux-headers, with the version that matches the kernel you’re planing to use, remove Java from USE (i.e. export USE=”-java”) to speed up bootstrapping, now run bootstrap.sh and go grab yourself something to eat, because this takes a while.
To make sure that your glibc has NPTL support, try running /lib/libc.so.6, you should see NPTL in the output, if you don’t, don’t worry about it, you can always “emerge glibc” after booting to Gentoo. One note though, there’s a bug that might show up after compiling with NPTL support which causes /lib/libc.so.6 not to show up any information, it’s harmless really, but still it’s annoying. I patched glibc when emerging it and fix that. I got the patch from Gentoo’s Bugzilla, get it and patch your glibc when bootstrapping.
Getting yourself a kernel
The rest is relatively easy, when bootstrap is done you “unset USE”, “emerge system”, “emerge <kernel-sources>”. The kernel sources are of your choice, just make sure you choose a 2.6 kernel if you compiled glibc with NPTL. I personally chose gentoo-dev-sources, which are the kernel vanilla sources patched a bit for performance. For more information about this, try Gentoo’s Kernel Guide, you should get an idea of what sources you’re going to emerge.
If you want framebuffer support and bootsplash (a very nice package that allows adding a background to the console), you should emerge bootsplash before compiling the kernel, you don’t need to patch anything if you’re using gentoo-dev-sources, otherwise you should run “bootsplash_patch” to add this to your kernel. Then, when running “make menuconfig” to configure the kernel, make sure you choose the following:
Code maturity level options --->
[*] Prompt for development and/or incomplete code/drivers
Processor type and features --->
[*] MTRR (Memory Type Range Register) support
Device Drivers --->
Block devices --->
<*> Loopback device support
<*> RAM disk support
(4096) Default RAM disk size
[*] Initial RAM disk (initrd) support
Graphics support --->
[*] Support for frame buffer devices
[*] VESA VGA graphics support
Console display driver support --->
[*] Video mode selection support
<*> Framebuffer Console support
Bootsplash configuration --->
[*] Bootup splash screen
This only applies to 2.6 kernels, for more information about bootsplash and framebuffer refer to This HOWTO on Gentoo Wiki.
Next, compile your kernel with the hardware you need, I had to add ALSA to use my Audigy2, otherwise you might be comfortable with OSS (although it’s deprecated). Well, you should know how to compile a kernel, it isn’t a very difficult process.
Continue as described in the handbook, only when you get to Grub configuration, add the following lines to get framebuffer and bootsplash support:
kernel=(hd0,0)/boot/bzImage root=/dev/hda3 video=vesafb:ywrap,mtrr vga=0x317 initrd=/boot/initrd-1024x768
After that, you should copy initrd-1024×768 from /usr/share/bootsplash/ to /boot, otherwise, bootsplash won’t work
This actually depends on your screen configuration, your hard disk partitioning, so you have to change whatever’s applicable.
Important: I actually did this by mistake, but you should note that the kernel=… is on a single line, initrd=/boot/…. is on a new line. No, it’s not being wrapped by your browser, so make sure you do have initrd on a single line afer kernel=…
Now we’re finished, boot up your system and get ready to get a real desktop up and running.
Configuring X
This shouldn’t be very difficult, you can start emerging KDE or Gnome and emerge will automatically emerge XFree86 for you, I should warn you though, tis process takes a lot, so you should go get yourself a nap or read a book or something.
Configuring X should be a breeze if you know what you’re doing, you could use utilities like xf86cfg to help you out, or even better, try running “X -configure” to probe for available devices ad select workable settings, you can try it then with X -xf86config=<file>, where <file> is the generated XF86Config file.
By default, XF86Config, doesn’t enable scroll wheel, so you should do that by changing your mouse protocol to “IMPS/2″ and changing the following in XF86Config “InputDevice” section:
Option "Protocol" "IMPS/2"
Option "Device" "/dev/psaux"
Option "ZAxisMapping" "4 5"
Option "Buttons" "5"
This should make it work. Now, for some nice fonts you should read solka’ s mini HOWTO, it’s in polish but you get the point, I’m not willing to steal any content from others… alright, maybe just a little bit.
Now, I know you might have some fancy graphics card with OpenGL and other stuff, I’m not going to get into that because it can only be handled on a case-by-case basis. Basically, you emerge you’re card’s drivers and start working on XFree’s settings to get Tux Racer to get run. In case of any trouble, try #gentoo on IRC.freenode.net
When you’re done, add to ~/.xinitrc one of the following lines to either start KDE or Gnome:
exec startkde #exec gnome-session
Then run startx, and you should be pleased with what you see.
Finishing Up
At this point, you should have a extreme-performance working desktop, with almost no applications, except for what comes with KDE or Gnome. You should go ahead and start emerging what you might need. I personally emerged openoffice, mozilla, mozilla-thunderbird, evolution, jedit and a couple of other packages. Slowly, but sure, you should end up with a perfectly functioning Gentoo desktop.
For those (like me) with multimedia keyboards, you should try emerging lineak to be able to customize those extra keys, it’s configuration is easy, you can run lineakconfig, but you should add a lineakd line to your .xinitrc so it starts when you startx. If you’re using a Logitech iTouch, try emerging xmms-itouch, it should also be helpful.
Other helpful packages include alsa-tools and alsa-utils for alsamixer, gentoolkit is a must for your portage maintenance, you could get Opera in case you don’t like Mozilla or Firefox very much, Anjuta is my recommendation to developers, Quanta is also a very good editor for Web applications, infact I’m using it to write this tutorial. You could also try Porthole, if you don’t like browsing the portage manually.
Now here’s a tip for those who like clear screens before login and after logout (meaning those who don’t use xdm, gdm and the like), agetty doesn’t support clearing the screen before calling /bin/login, here’s what I had to do to make it work:
tput clear >> /etc/issue
This makes tput add clearscreen characters to /etc/issue, the file that agetty reads and uses to display the login prompt. You need to edit /etc/issue to put the clearscreeen characters before the prompt. If you already have an editor that can write special characters, you wouldn’t need to use tput, it’s just a little hack I did.
One last tip for those who hate it when the system starts up without numlock turned on, you can do this by running:
rc-update add numlock default
rc-update is a utility that modifies boot scripts that start services, it makes it much easier than editing a hell of symlinked scripts, so the command above adds numlock to startup services, simple isn’t it?
Credits
This concludes my Gentoo installation, it was a fairly tiresome process, but it was worth it, I ended up ditching all other Linux distributions, even ditching FreeBSD as a desktop OS in favor of Gentoo. I haven’t done this alone, I had to harass almost everyone on #gentoo, dig up a lot in forums, and google for information, but I’m finally done.
So thank you Daniel Jacobowitz for the glibc patch, Gentoo Wiki, Solka for your X.org font HOWTO, and everyone on #gentoo.
If you find this information useful, or you find any errors, please drop me an email to rami at ramikayyali dot com, I’ll be more than glad to either correct any mistakes, or get flattered.
4 Responses (Add Your Comment)
-
-
I thought I double-checked this article. But I’m so sorry I missed the little “m”, it must’ve been very annoying to figure out.
Reply ↵ -
I like gentoo as well, it’s really my favorite thing in the systems space right now. I can’t wait for the next release that is touted to have a installation GUI. I’d push out more Gentoo boxes if they didn’t take a day to set up.
In the end, it’s fast. We have a dual xeon box that is hauling butt and running a whole slew of web and network apps. My biggest concern is maintenance. I haven’t had a need to unmerge in ‘production’ yet and I know that emerge is a bit weak on checking dependencies.
Reply ↵ -
Merci pour l’information ici
Reply ↵
where you wrote:
CFLAGS=”-O2 -march=athlon-xp -m3dnow -mmmx -msse -fpmath=sse -pipe -fomit-frame-pointer”
it should be:
CFLAGS=”-O2 -march=athlon-xp -m3dnow -mmmx -msse -mfpmath=sse -pipe -fomit-frame-pointer”
(i.e. m infront of fpmath :)
took me a while to work out why my bootstrap kept failing on the first package. other then that, very handy instructions!