Friday, 6 August 2010

LAP - E-UAE (Text Test)

Let's now try e-uae.  Why the hell would we do that without any kind of graphical user interface having been installed I hear you ask?  Well, the e-uae program has a really interesting, and completely fucking useless, feature.  It can be run without a graphical interface.  It uses the ncurses software to display the amiga video output using the text only terminal.  Oh, yes, you are going to want to see this.  Is it any use?  Fuck no, but it is amusing nonetheless.
umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources

Make a directory for the amiga software ...
mkdir amiga
chmod -v a+wt amiga
... and move into it and download the amiga emulator.  I should point out at this stage that there is actually a more up to date version of the emulator available. It is in beta though, and I have not tested it yet. I will set out how to download and configure it in an appendix post at the end of the build.

cd amiga
wget http://www.rcdrummond.net/uae/e-uae-0.8.29-WIP4/e-uae-0.8.29-WIP4.tar.bz2

Then reboot into the Amiga Key.  Run the following commands to unpack the Amiga emulator:

cd /sources/amiga
tar -xjvf e-uae-0.8.29-WIP4.tar.bz2
cd e-uae-0.8.29-WIP4

Again, you can autocomplete with [tab] to speed this up.  Now configure the install:
./configure --enable-autoconfig --with-curses | tee config_report.txt 

The [autoconfig] option may not strictly be necessary for this simple test, but I want to keep things as auto as possible, so lets stick it in.  The [curses] tells the configuration that we want to use the text graphics display.  The command then [|] pipes the output to [tee] which sticks it in the [config_report.txt] file.  That way we can peruse that file at our leisure to check for any error messages in the configure report.

Then build with:

make $CORES_TO_USE

I wouldn't actually install the software yet, because we are going to go through a few more configurations before we get one I will be happy with.  The executable file can be found in the [src] directory and it is called [uae].  Test it with:

./src/uae

It will fail.  If you read the failure properly it will tell you that it cannot find a .rom file.  This is the only thing which is stopping it working, but you wouldn't know that from the less than helpful text report.  So I jumped back into the LiveCD Key and copied a 1.3 kickstart rom file, and a 1.3 workbench disk to /root on the Amiga Key.  I renamed them to something very very simple.  I then rebooted to the Amiga Key, moved back to the e-uae sources folder and ran the command again as follows:

cd /sources/amiga/e-uae-0.8.29-WIP4/src
./uae -r ~/1.3.rom

That runs the emulator in default mode with the [r]om file [~/1.3.rom].  And, bugger me.  That looks surprisingly like an Amiga boot screen rendered in text symbols!

Lets try a workbench disk.  First we need to close the emulator.  The only way I would work out how to do that was to find the id number of the [uae] application in a new terminal:

ps aux | grep uae

and then [kill] that application number

kill 1234

Where 1234 is whatever the last command told us was the number.

For some reason that terminal window was rendered useless, so I switched to number 3.  However, thanks to the Ubuntu UK Podcast, I now know I can run the command [reset] when the terminal window is fubarred, and right enough it came back to life! I moved back to the [src] directory and ran [uae] again:

./uae -r ~/1.3.rom -0 ~/1.3.adf

This runs the previous command, with the disk image [~/1.3.adf] loaded in drive df[0]:
A, hahahahahaha, that's Workbench in text!  Completely indecipherable but entertaining nonetheless.  Mouse is non-functional.

Ok, clearly this is entertaining, and the emulator, roms and disks are working, but what we need is a proper graphical interface.  It is time for the X windows system to be installed.  Just tidy up the mess here first:

cd /sources/amiga/
rm -rvf e-uae-0.8.29-WIP4

Thursday, 5 August 2010

LAP - Audio

The next thing to install is the linux audio software, also known as alsa or [a]dvanced [l]inux [s]ound [a]rchitecture.

Again, we need to download from the LiveCD:
umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir audio
chmod -v a+wt audio
cd audio
wget ftp://ftp.alsa-project.org/pub/lib/alsa-lib-1.0.21.tar.bz2
wget ftp://ftp.alsa-project.org/pub/plugins/alsa-plugins-1.0.21.tar.bz2
wget ftp://ftp.alsa-project.org/pub/utils/alsa-utils-1.0.21.tar.bz2
wget http://www.linuxfromscratch.org/patches/blfs/svn/alsa-utils-1.0.21-no_xmlto-1.patch
wget http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20090302.tar.bz2

I'm downloading the BLFS bootscripts again, just incase we didn't grab them when doing the network install. We'll adopt the same approach as for the network and documentation software:
cd /sources/audio
tar -jxvf /sources/audio/alsa-lib-1.0.21.tar.bz2

The [alsa-lib-1.0.21.tar.bz2] contains Alsa's libraries, and is absolutely essential to what follows. These are the core pieces of software that let programs, inlcuding alsa programs that we are about to install, access the ALSA drivers that we activated in the Kernel configuration earlier.

cd alsa-lib-1.0.21
./configure --enable-static

The [enable-static] option presumably makes static instead of dynamic libraries. Someone is going to have to take the time to explain that to me in the future.

make $CORES_TO_USE
make install
install -v -m644 -D doc/asoundrc.txt /usr/share/doc/alsa-lib-1.0.21/asoundrc.txt
make doc
install -v -d -m755 /usr/share/doc/alsa-1.0.21/html
install -v -m644 doc/doxygen/html/* /usr/share/doc/alsa-1.0.21/html
cd ..
rm -rvf alsa-lib-1.0.21
tar -jxvf /sources/audio/alsa-plugins-1.0.21.tar.bz2

In [alsa-plugins-1.0.21.tar.bz2] there are several add on libraries that seem to mostly assist in making alsa interact with other sound software in Linux. We are only going to be using alsa, and not pulseaudio or jack, so these may not be necessary. There is a huge gulf between 'may not be necessary' and 'actually not necessary' filled with nightmarish problem solving, so I am just going to install these anyway.

cd alsa-plugins-1.0.21
./configure
make $CORES_TO_USE
make install
install -v -m755 -d /usr/share/doc/alsa-plugins-1.0.21
install -v -m644 doc/{README*,*.txt} /usr/share/doc/alsa-plugins-1.0.21
cd ..
rm -rvf alsa-plugins-1.0.21
tar -jxvf /sources/audio/alsa-utils-1.0.21.tar.bz2

We now need to actually have some programs to configure the sound card settings, and more importantly at this stage, test to see if it is working. The [alsa-utils-1.0.21.tar.bz2] package achieves this.

cd alsa-utils-1.0.21
patch -Np1 -i /sources/audio/alsa-utils-1.0.21-no_xmlto-1.patch

BLFS contains precisely no information about why we want to apply this patch, but given the name it is probably something to do with stopping some xml documentation being produced.

./configure
make $CORES_TO_USE
make install
cd ..
rm -rvf alsa-utils-1.0.21

We now need to do some setup work so that alsa will work when we restart. The first thing to do is to install a script from BLFS which starts up alsa on boot.

tar -xjvf /sources/audio/blfs-bootscripts-20090302.tar.bz2
cd blfs-bootscripts-20090302
make install-alsa
cd ..
rm -rvf blfs-bootscripts-20090302

We also need to create the file which stores the settings (volume and stuff):

touch /etc/asound.state

And we need to fill it with the current settings:

alsactl store

Finally, udev needs a rule to tell it to reload the settings file we just made when it detects a soundcard at boot time. Not exactly sure what the difference is between this and the BLFS bootscript we just installed.

cat > /etc/udev/rules.d/40-alsa.rules << "EOF"
# /etc/udev/rules.d/40-alsa.rules

# When a sound device is detected, restore the volume settings
KERNEL=="controlC[0-9]*", ACTION=="add", RUN+="/usr/sbin/alsactl restore %n"
EOF
chmod -v 644 /etc/udev/rules.d/40-alsa.rules

What you then have to do is run the control program to activate your speakers. It is fairly self explanatory to use.

alsamixer

You can test the installation has worked by running:
speaker-test

If that does not work (and it did for me) then I can only suggest going back to the kernel configuration and making double sure that your hardware is supported in the kernel you have built. If in doubt, activate everything and try it then.

And, now for the wonder command that makes all of that into an executable script (apart from the last two commands):

sudo cat > install_alsa.sh << "ARSE" 
cd /sources/audio
tar -jxvf /sources/audio/alsa-lib-1.0.21.tar.bz2
cd alsa-lib-1.0.21
./configure --enable-static &&
make $CORES_TO_USE
make install &&
install -v -m644 -D doc/asoundrc.txt /usr/share/doc/alsa-lib-1.0.21/asoundrc.txt
make doc
install -v -d -m755 /usr/share/doc/alsa-1.0.21/html
install -v -m644 doc/doxygen/html/* /usr/share/doc/alsa-1.0.21/html
cd ..
rm -rvf alsa-lib-1.0.21
tar -jxvf /sources/audio/alsa-plugins-1.0.21.tar.bz2
cd alsa-plugins-1.0.21
./configure
make $CORES_TO_USE
make install
install -v -m755 -d /usr/share/doc/alsa-plugins-1.0.21
install -v -m644 doc/{README*,*.txt} /usr/share/doc/alsa-plugins-1.0.21
cd ..
rm -rvf alsa-plugins-1.0.21
tar -jxvf /sources/audio/alsa-utils-1.0.21.tar.bz2
cd alsa-utils-1.0.21
patch -Np1 -i /sources/audio/alsa-utils-1.0.21-no_xmlto-1.patch
./configure
make $CORES_TO_USE
make install
cd ..
rm -rvf alsa-utils-1.0.21
tar -xjvf /sources/audio/blfs-bootscripts-20090302.tar.bz2
cd blfs-bootscripts-20090302
make install-alsa
cd ..
rm -rvf blfs-bootscripts-20090302
touch /etc/asound.state
alsactl store
cat > /etc/udev/rules.d/40-alsa.rules << "EOF"
# /etc/udev/rules.d/40-alsa.rules

# When a sound device is detected, restore the volume settings
KERNEL=="controlC[0-9]*", ACTION=="add", RUN+="/usr/sbin/alsactl restore %n"
EOF
chmod -v 644 /etc/udev/rules.d/40-alsa.rules
ARSE
chmod +x ./install_alsa.sh
sudo mv ./install_alsa.sh /media/lfs/root 

Wednesday, 4 August 2010

LAP - Documentation

It was after I first installed the alsa software, when I looked through the commands that I had used and realised that I had probably not installed all the documentation properly. You see, some text files had been installed but the actual documentation was to be in more sophisticated html files. We need another package to create those files, and I have decided that it would be a good idea to actually install that software.

You have probably realised that we have not installed any software which can actually read html files. Hmm. We'd probably best do that then. I have chosen lynx which is a text based browser and therefore will work without any graphical interface. Which we do not have just now.

The openssl package that I am going to install before lynx allows lynx to support web security - the padlock icon that you see in firefox and internet explorer in other words. We absolutely do not need that just to access the html documentation, but it may be useful in the future if we web-enable this installation. The bc package is another maths type package, like the ones needed for gcc. This is needed to test openssl, and with any security stuff, we want to make sure it works. Note that if you want [wget] to be able to download from secure sites, you need to reinstall it now - the same commands should work it will just automatically detect that we have installed OpenSSL.

This whole bc -> ssl -> lynx chain will arise time and time again with Linux From Scratch. These connections are known as dependencies. In other words, lynx is dependant on openssl to provide security and needs it to be installed first. Openssl is dependant on bc to test itself. Normally, Ubuntu, or other advances distributions handle all this sort of dependency stuff for you and tuck it away in the background. No such joy with LFS - we have to do it all by hand.

Again, I will set out all the commands with comments, but as they are a bit complicated I will also include them as an executable script. So what you end up doing is copying and pasting the commands which then create a script on the Amiga Key. Once you are in the LFS system you can just run that script.

Again, we need to download from the LiveCD:
umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir extras
chmod -v a+wt extras
cd extras
wget http://ftp.stack.nl/pub/users/dimitri/doxygen-1.6.3.src.tar.gz
wget http://lynx.isc.org/current/lynx2.8.7rel.1.tar.bz2
wget http://www.openssl.org/source/openssl-0.9.8n.tar.gz
wget http://anduin.linuxfromscratch.org/files/BLFS/BLFS-ca-bundle-3.12.5.tar.bz2
wget http://www.linuxfromscratch.org/patches/blfs/svn/openssl-0.9.8n-fix_manpages-1.patch
wget http://ftp.gnu.org/gnu/bc/bc-1.06.tar.gz
And then reboot to the Amiga Key:

cd /sources/extras
tar -xzvf /sources/extras/bc-1.06.tar.gz
cd bc-1.06

There is a problem with this package speaking nicely to readline. We correct it with a [sed] command.

sed -i '/PROTO.*readline/d' bc/scan.l

The same applies to Flex:

sed -i '/flex -I8/s/8//' configure

We also need a missing header. I do not know what this is or why it is missing, but the following [sed] fixes it.
sed -i '/stdlib/a #include <string.h>' lib/number.c

Lastly, there can be a fault with the program which is fixed with this [sed]:
sed -i 's/program.*save/static &/' bc/load.c
./configure --prefix=/usr --with-readline

[with-readline] makes the compiled software aware that we have installed readline on our system.

make $CORES_TO_USE

We may as well run a check, which we do as follows:

echo "quit" | ./bc/bc -l Test/checklib.b
Percent Failed: 0
make install
cd ..
rm -rvf bc-1.06

tar -xzvf /sources/extras/openssl-0.9.8n.tar.gz
cd openssl-0.9.8n

Firstly we apply the patch we downloaded. BLFS is curiously reticent about telling us what this does, but the name of the patch does tend to give the game away.

patch -Np1 -i /sources/extras/openssl-0.9.8n-fix_manpages-1.patch

Next we need to install basic security certificates which are omitted from the source code package:

tar -vxf /sources/extras/BLFS-ca-bundle-3.12.5.tar.bz2
./config --prefix=/usr --openssldir=/etc/ssl shared zlib-dynamic

[openssldir] just specified the particular install directory for the configuration stuff - I am not sure where this would default to otherwise. [shared] once again relates to the libraries. [zlib-dynamic] makes openssl aware that we have installed zlib and it can use it.

make $CORES_TO_USE
make test
The test output looks very cool to start with and then descends into screeds and screeds of crap. There was no discernible success or failure message.
make MANDIR=/usr/share/man install
cp -v -r certs /etc/ssl
install -v -d -m755 /usr/share/doc/openssl-0.9.8n
cp -v -r       doc/{HOWTO,README,*.{txt,html,gif}} /usr/share/doc/openssl-0.9.8n

Most of that we have seen before. In addition to the installation of the documentation we also install the [cert]ificates to [/etc/ssl].

for pem in /etc/ssl/certs/*.pem
do
cat $pem
echo ""
done > /etc/ssl/ca-bundle.crt

Hmm that looks tricky. What this is doing is taking the contents of every [pem] file in the [/etc/ssl/certs] directory and sticking them together in one big file called [ca-bundle.crt]. Why, I have no idea. Apparently though, if we ever add any more [pem] files we are supposed to re-run that command.

cd ..
rm -rvf openssl-0.9.8n

tar -xjvf /sources/extras/lynx2.8.7rel.1.tar.bz2
cd lynx2-8-7

That is about the most annoyingly different directory name over archive name that I have found so far ... just as well I tested it before actually implementing it in the script.

./configure --prefix=/usr --sysconfdir=/etc/lynx --datadir=/usr/share/doc/lynx-2.8.7rel.1 --with-zlib --with-bzlib --with-screen=ncursesw --enable-locale-charset --with-ssl

Mostly self explanatory - we tell it about [zlib] and [bzlib] (bzip2), and [ncurses] (for the chubby letters). I think the [enable-locale-charset] tells it to use the same character set as we have configure for the terminal in the config files at the end of the main build.
make $CORES_TO_USE
make install-full
chgrp -v -R root /usr/share/doc/lynx-2.8.7rel.1/lynx_doc

The locale setting we used for the [configure] script is not reflected in the config file for the browser, so we need to fix that by the magic of [sed]:
sed -i 's/#\(LOCALE_CHARSET\):FALSE/\1:TRUE/' /etc/lynx/lynx.cfg

Apparently there is a built in editor in Lynx. I am not sure what this is for. In any event, it is prone to breaking if it sees something complicated, so we can tell it to use the nano editor that we have installed as follows:

sed -i 's/#\(DEFAULT_EDITOR\):/\1:nano/' /etc/lynx/lynx.cfg

We also probably want to save cookies between sessions, so that websites will remember us. Again this is not something that we will be using unless we set up an internet connection in due course. We need to change another setting in the [.cfg] file.

sed -i 's/#\(PERSISTENT_COOKIES\):FALSE/\1:TRUE/' /etc/lynx/lynx.cfg

It should be noted here that we could probably just have opened the [.cfg] file in nano and made the changes manually, but there is clearly a sed fanatic at work who has spent several years mastering their sed skills, and it would be rude to ignore the results.

cd ..
rm -rvf lynx2-8-7

There is literally nothing surprising about the commands to install doxygen - just watch out of the name of the unpacked directory:

tar -xzvf /sources/extras/doxygen-1.6.3.src.tar.gz
cd doxygen-1.6.3
./configure --prefix /usr --docdir /usr/share/doc/doxygen-1.6.3
make $CORES_TO_USE
make install
make install_docs
cd ..
rm -rvf doxygen-1.6.3

And for those intending to create a script to run all these from the LFS system itself, copy and paste this bad boy. Note that it does not run the tests because there is no point if the results just go flying past. There is also little point in automating an install if you then build in pauses to check test results.

sudo cat > install_docs.sh << "ARSE" 
cd /sources/extras
tar -xzvf /sources/extras/bc-1.06.tar.gz 
cd bc-1.06 
sed -i '/PROTO.*readline/d' bc/scan.l 
sed -i '/flex -I8/s/8//' configure 
sed -i '/stdlib/a #include <string.h>' lib/number.c 
sed -i 's/program.*save/static &/' bc/load.c 
./configure --prefix=/usr --with-readline 
make $CORES_TO_USE 
make install 
cd .. 
rm -rvf bc-1.06 
tar -xzvf /sources/extras/openssl-0.9.8n.tar.gz 
cd openssl-0.9.8n 
patch -Np1 -i /sources/extras/openssl-0.9.8n-fix_manpages-1.patch 
tar -vxf /sources/extras/BLFS-ca-bundle-3.12.5.tar.bz2 
./config --prefix=/usr --openssldir=/etc/ssl shared zlib-dynamic 
make $CORES_TO_USE 
make MANDIR=/usr/share/man install 
cp -v -r certs /etc/ssl 
install -v -d -m755 /usr/share/doc/openssl-0.9.8n 
cp -v -r       doc/{HOWTO,README,*.{txt,html,gif}} /usr/share/doc/openssl-0.9.8n 
for pem in /etc/ssl/certs/*.pem 
do 
cat $pem 
echo "" 
done > /etc/ssl/ca-bundle.crt 
cd .. 
rm -rvf openssl-0.9.8n 
tar -xjvf /sources/extras/lynx2.8.7rel.1.tar.bz2 
cd lynx2-8-7 
./configure --prefix=/usr --sysconfdir=/etc/lynx --datadir=/usr/share/doc/lynx-2.8.7rel.1 --with-zlib --with-bzlib --with-screen=ncursesw --enable-locale-charset --with-ssl 
make $CORES_TO_USE
make install-full 
chgrp -v -R root /usr/share/doc/lynx-2.8.7rel.1/lynx_doc 
sed -i 's/#\(LOCALE_CHARSET\):FALSE/\1:TRUE/' /etc/lynx/lynx.cfg 
sed -i 's/#\(DEFAULT_EDITOR\):/\1:nano/' /etc/lynx/lynx.cfg 
sed -i 's/#\(PERSISTENT_COOKIES\):FALSE/\1:TRUE/' /etc/lynx/lynx.cfg 
cd .. 
rm -rvf lynx2-8-7 
tar -xzvf /sources/extras/doxygen-1.6.3.src.tar.gz 
cd doxygen-1.6.3 
./configure --prefix /usr --docdir /usr/share/doc/doxygen-1.6.3 
make $CORES_TO_USE
make install 
make install_docs 
cd .. 
rm -rvf doxygen-1.6.3 
ARSE
chmod +x ./install_docs.sh
sudo mv ./install_docs.sh /media/lfs/root

Tuesday, 3 August 2010

LAP - Compression

Now, first of all lets deal with the kernel sources that we have left around in the sources directory. We are going to compress these into an archive file that will take up less space. We'll need a more powerful compressor than gzip or bzip2. We're going to use lzma. Now would also be a good time to install [.zip] file support. We aren't going to use it immediately, but we will do so eventually.

umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir extras
chmod -v a+wt extras
cd extras
wget http://tukaani.org/lzma/lzma-4.32.7.tar.gz
wget http://downloads.sourceforge.net/infozip/unzip60.tar.gz
wget http://downloads.sourceforge.net/infozip/zip30.tar.gz

These commands make an [extras] folder inside the [/sources] folder on the Amiga Key. I am going to use that to store some of the add on bits of software. As some of these are optional (including technically this one) I will just repeat the [mkdir] command on the other occasions, just in case I have missed it out at any stage.

The install commands are quite simple, so unlike the networking utilities, we will just make a text file to remind us of the commands - much like installing wireless utilities. We have to make the text file and then move it into the LFS /root directory, because permissions bullshit(TM) prevents [cat] making the file directly.

sudo cat > compression.txt << "EOF"
cd /sources/extras
tar -xzvf /sources/extras/lzma-4.32.7.tar.gz
cd lzma-4.32.7
./configure --prefix=/usr
make $CORES_TO_USE
make check
make install
cd ..
rm -rvf lzma-4.32.7
tar -xzvf /sources/extras/unzip60.tar.gz
cd unzip60
make -f unix/Makefile linux
make prefix=/usr install
cd ..
rm -rvf unzip60
tar -xzvf /sources/extras/zip30.tar.gz
cd zip30
make -f unix/Makefile generic_gcc
make prefix=/usr -f unix/Makefile install
cd ..
rm -rvf zip30
EOF
sudo mv ./compression.txt /media/lfs/root 

We then reboot into the new system and run:
cat /root/compression.txt

and that will give you the commands to repeat. There may be a way to copy and paste using the command line only, but I haven't found it yet. If you want to be ultra lazy you could just rename the file to *.sh and [chmod +x] it to be executable and then run it. Just sayin.

Once installed, we can compress the kernel folder:

cd /sources
tar -c linux-2.6.32.8 | lzma --best > linux.tar.lzma
rm -rf linux-2.6.32.8

That command is pretty tricky. It is really in two bits. The first, before the [|] pipe uses the [tar] command to lump the contents of the kernel source directory into one large file which it then passes to the [lzma] on the other side of the pipe. The [best] bit tells it to really, really compress the data. Like up to an hour to compress. You can omit the [best] bit and it will do it quicker, but the resulting file will obviously be larger.

To uncompress in the future, run these commands:

cd /sources
cat linux.tar.lzma | lzma -d | tar x

That command is in THREE sections, which is even more complicated. What this does is pass the contents of the [.lzma] file to the [lzma] command, telling it to [d]ecompress before passing the outcome of that to the [tar] command to e[x]tract the file structure. This is much quicker, but still expect a couple of minutes to get the whole thing unpacked. This probably says more about the speed of the USB stick than the efficiency of the code though.

Lets just leave reminder of those instructions for ourselves in the system:

cat > compress_kernel_source.txt << "EOF"
cd /sources
tar -c linux-2.6.32.8 | lzma --best > linux.tar.lzma
rm -rf linux-2.6.32.8

cd /sources
cat linux.tar.lzma | lzma -d | tar x
EOF
sudo mv ./compress_kernel_source.txt /media/lfs/root

Monday, 2 August 2010

LAP - Network

Now that we have a booting system we are officially finished with the LFS Book. We now move onto the BLFS, or [B]eyond LFS. This is not a book as such, because all of the packages in it are optional.

This post deals with the installation and configuration of Network drivers. These are entirely optional; the Amiga was not primarily known as a network machine. If you skip over this section there are three main implications:

You will have to use the LiveCD USB stick to download the additional software onto the Amiga Key, then reboot to the Amiga Key and build the software from there.

You will not be able to surf the internet from the Amiga Key using the Lynx text only web browser that we will be installing.

You will not be able to use the Aweb browser under the Amiga OS to surf the internet.

That is it. You will still be able to install software and use the emulator, you will just be missing out on these three things. So if you can't work out how to get your network card functioning in (B)LFS then just skip over this stuff and go to the next post. You won't be missing much. I have written all the other blog entries so that they work without networking being installed on the Amiga Key. If you DO manage to get the network to work, you can do all the [wget]s in the coming posts from the Amiga Key instead of the LiveCD Key. That may speed things up, because you won't be repeatedly booting back into the LiveCD just to download stuff.

We are going to download quite a bit of software throughout the BLFS stages, and as Networking is optional we are going to download our software with the LiveCD booted. The procedure will be the same each time we download packages. Attach the Amiga Key, and run the following commands before running your [wget]s.

umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources

The installation of the network hardware is tricky. It very much depends on the hardware in your machine. I am building this installation on two systems, a desktop system using a Linksys WMP54GS, PCI card, and a Compaq Mini 700 which has networking built in. Both systems use a Broadcom chipset for the network functions. Happily both appear to work perfectly well with the b43 module in the kernel. There is another option for the compaq, which involves some dedicated drivers (linux sta) for the specific chipset it uses. This is, I think, a better option. However, since b43 works, I am going to put the linux STA stuff in a kind of appendix post as an option. Well, I was, but then the b43 drivers on the netbook turned into a pain in the arse and stopped working. So, I'll download and setup the STA drivers along with the other network stuff.

The b43 driver for my desktop is easier to deal with, as it is built into the Kernel. We still need to download some software for the card - the firmware. I have set out more fully in my blog here exactly how you go about this, so I am not going to repeat that here. I just copied the b43 folder containing the firmware to the /lib/firmware folder on the Amiga Key. Oh, and as a stop press I also got my Abit Airpace PCI-Express card working. It was the easiest of the three; all it needed was for the Atheros option in the kernel configuration to be selected (I mention this on the 'boot' post). No firmware and no hybrid driver needed. Funnily enough this card was the biggest pain in the arse to get working in Windows.

The network software that we will be compiling here is DHCPCD to grab our network settings from a router, some BLFS bootscripts for DHCPCD, wireless utilities to configure the connection, some general networking utilities, and then wget to download files from the internet. First of all we are going to install the wireless utilities because that will give us the network device name which we need to configure the DHCPCD package.

So run the following commands from the LiveCD to download the necessary packages to /sources on the Amiga Key

umount -v /media/amiga
sudo mkdir /media/lfs
sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs
cd /media/lfs/sources
mkdir network
chmod -v a+wt network
cd network
wget http://anduin.linuxfromscratch.org/sources/BLFS/svn/d/dhcpcd-4.0.11.tar.bz2
wget http://www.linuxfromscratch.org/blfs/downloads/svn/blfs-bootscripts-20090302.tar.bz2
wget http://www.hpl.hp.com/personal/Jean_Tourrilhes/Linux/wireless_tools.28.tar.gz
wget http://www.tazenda.demon.co.uk/phil/net-tools/net-tools-1.60.tar.bz2
wget http://ftp.gnu.org/gnu/wget/wget-1.12.tar.bz2
wget http://www.broadcom.com/docs/linux_sta/hybrid-portsrc-x86_32-v5.60.48.36.tar.gz

In a stunning example of me being right, the links from BLFS for dhcpcd are down at the time of writing, so I am using the link to the Server Beach copy. The last command may fail, as the creators of the driver remove old versions when they upload new ones. If so, just go to the website and download the driver manually and save to the Amiga Key. The filename should be the same - with an update in the numbering. The installation should be similar, but be sure to check any README files.

Now, we need to run the build and install commands from either a chroot environment or from the actual System we now have working on the Amiga Key. I would prefer if possible to use the real system we have built. But how then do we copy the commands? Well we could print off these commands and then type them in but the install commands are quite complicated, and a mistaken key press could land us in trouble. So, we could save the commands to a text file on the USB Key. If we made that text file into an executable shell script we could just run the name of the file and all of the commands would execute. Just like magic.

What I will do now is set out all the commands with comments, as with the Actual Build, and then at the end of the post I will list a command which if pasted into the command line of the LiveCD will create an executable script.

Once we have rebooted to the Amiga Key, we move to the sources directory:

cd /sources/network

On the desktop the network card should be up and running and ready to be configured, now that I have loaded the firmware on to the key. You can run ...
dmesg | grep b43
... and you should see some encouraging messages.

To get the compaq into the same state, we need to install the STA drivers. This SHOULD be simple.

mkdir hybrid_wl
cd hybrid_wl
tar -xzvf /sources/network/hybrid-portsrc-x86_32-v5.60.48.36.tar.gz
make clean
make
install -D -m 755 wl.ko /lib/modules/2.6.32.8/kernel/drivers/net/wireless/wl.ko 
depmod -a
cd ..
rm -rvf hybrid_wl

Instead of typing all of the filename in, you can just hit [tab] after the first couple of letters and it should auto complete for you. The [install] command copies the driver module (the wl.ko) file we just built to the appropriate place. The [depmod] command makes the kernel rescan all of the installed modules. Now we need to activate the module. It is not compatible with the b43 module so we need to remove it. We also need to remove a couple of others that hang around with it.

rmmod b43 
rmmod ssb 
rmmod lib80211
modprobe lib80211
modprobe wl

You should get some similarly comforting messages from a [dmesg | grep wl], which hopefully should confirm that it is working. Once you have installed the wireless tools, you will get a hold of [iwconfig] which will tell you the new name for the interface.

Talking of those tools, it is now time to install them. First of all we want the utilities to actually configure the wireless connection. Mainly we want these now because they identify the name of our wireless connection, and we are going to have to take that name and plug it into the rest of the commands.

tar -xzvf /sources/network/wireless_tools.28.tar.gz
cd wireless_tools.28
make
make PREFIX=/usr install
cd ..
rm -rvf wireless_tools.28

That was pretty straightforwards. Lets do the general tools next. These are mostly useful for [ifconfig] which gives you further information over and above iwconfig. It also configures wired internet connections, in case you are using one of those. Like a luddite.

tar -xjvf /sources/network/net-tools-1.60.tar.bz2
cd net-tools-1.60
patch -Np1 -i ../net-tools-1.60-gcc34-3.patch
patch -Np1 -i ../net-tools-1.60-kernel_headers-2.patch
patch -Np1 -i ../net-tools-1.60-mii_ioctl-1.patch
I have no idea what those patches accomplish, but the books wants them, and what the book wants, the book gets. The normal installation asks you a series of questions about which type of networking protocols you want support for. The default options are fine here. If the default options are not suitable for you, then by definition you know a fuck of a lot more about networking than I do, and you should be able to sort this out your self. To auto-answer [yes] to everything, run this command:
yes "" | make config
By default some programs are not installed, and we can change that by [sed]ing the configuration files we just generated:
sed -i -e 's|HAVE_IP_TOOLS 0|HAVE_IP_TOOLS 1|g' -e 's|HAVE_MII 0|HAVE_MII 1|g' config.h
sed -i -e 's|# HAVE_IP_TOOLS=0|HAVE_IP_TOOLS=1|g' -e 's|# HAVE_MII=0|HAVE_MII=1|g' config.make
Now just make and install:
make $CORES_TO_USE
make update
cd ..
rm -rvf net-tools-1.60

Now for dhcp, which grabs our network settings for us from our router.

tar -xjvf /sources/network/dhcpcd-4.0.11.tar.bz2
cd dhcpcd-4.0.11
make PREFIX= LIBEXECDIR=/lib/dhcpcd DBDIR=/var/lib/dhcpcd SYSCONFDIR=/etc/dhcpcd
make PREFIX= LIBEXECDIR=/lib/dhcpcd DBDIR=/var/lib/dhcpcd SYSCONFDIR=/etc/dhcpcd install

There is no particular explanation for the options here, but they seem self explanatory. Presumably, we tell it where to put the libraries and executable files, then the database files, and finally the system configuration files. We have to repeat all these when we run the [make ... install] command.

According to BLFS:
By default, a plain text lease info file isn't created but the dhcpcd provides a hook which can be used for creating such a file. Install the hook by running the following commands as the root user:
I imagine that all of that guff makes sense if you study the man pages for dhcp with the intensity of a 12 year old with his first playboy magazine. I say imagine, because I cannot be arsed doing it. As best as I can tell the hooks allow dhcp to overwrite files like resolv.conf on the fly. That is a total guess though. We have not installed to the usual location, so we need to [sed] the file to make a change before installing it.

sed -i "s;/var/lib/dhcpcd-;/var/lib/dhcpcd/dhcpcd-;g" dhcpcd-hooks/50-dhcpcd-compat
install -v -m 644 dhcpcd-hooks/50-dhcpcd-compat /lib/dhcpcd/dhcpcd-hooks/
cd ..
rm -rvf dhcpcd-4.0.11

We need some new bootscripts for the rc system.

tar -xjvf /sources/network/blfs-bootscripts-20090302.tar.bz2
cd blfs-bootscripts-20090302
make install-service-dhcpcd
cd ..
rm -rvf blfs-bootscripts-20090302

We now need to find out what name has been assigned to our network card. To find this out run [iwconfig] and it should tell you. [iwconfig] was installed as part of the wireless utilities package above. On my Compaq with the wl driver it is eth1, but with the b43 driver it is wlan0, and on my desktop is it wlan1. It could also be ath0 depending on your card. We then need to replace the [XXXX] parts in the next commands with that name. You will need to re run these commands for the network adaptor on any other machine that you run the Amiga Key on - once you have obtained the XXXX network name!

Stop press. I have just figured out that udev automatically keeps track of all the network cards that you expose the system to. It keeps a list of their MAC addresses matched to interface names in the file [/etc/udev/rules.d/70-persistent-net-rules]. It is first come first served, which means if I first booted the system on my desktop, I would see wlan0 being assigned to the desktop's wireless card, and wlan1 to the compaqs. Presumably you can wipe this file, and it will be recreated. So, if you have a problem with finding your interface name, check in this file.

If we were typing in the commands step by step instead of using the script method, we can now run the command:
iwconfig XXXX essid "YYYY" key ZZZZ

Where XXXX=whatever iwconfig told you was the name of the network connection, YYYY=the wireless network name, and ZZZZ=the WEP key. This will connect you to the network - if you use WEP security. Then to get the all useful IP addresses, run:
dhcpcd XXXX

You should now be connected to the internet - congratulations. To semi-automate the connection, I will stick a couple of scripts in the /root folder - one for each of my network cards:

cat > ~/wifi_wl.sh << "EOF"
rmmod b43 
rmmod ssb 
rmmod wl
rmmod lib80211
modprobe lib80211
modprobe wl
dhcpcd -L -t 1 XXXX
iwconfig XXXX essid "YYYY" key ZZZZ
dhcpcd XXXX
EOF
chmod +x ~/wifi_wl.sh
The first [dhcpcd] line looks odd, and so it fucking should. For reasons known only to itself the wl.ko driver will not fucking work the first time you try to connect to a network. It just won't. Don't know why. So the command here runs [dhcpcd] with a [t]imeout of [1] second so it fails really fast. The [L] option stops it trying to assign a manual IP address when it can't get one from the router. It then connects quite happily the second time we ask it to. And no, it is nothing to do with the fact that I haven't [iwconfig]'d the interface before the first command. Of course I tried that. Did nothing. This is annoying, but it is the only way I can get the bastard to work. There are no such problems with the b43 driver. It has an entirely different problem. Udev leaps in when the driver loads and renames the interface. It doesn't do it quickly enough for the script though, with the result that the interface cannot be found. I need to insert a [sleep 1] line to make the script pause for a second to allow udev to do its thing:
cat > ~/wifi_b43.sh << "EOF"
rmmod b43 
rmmod ssb 
rmmod wl
rmmod lib80211
modprobe b43
sleep 1
iwconfig XXXX essid "YYYY" key ZZZZ
dhcpcd XXXX
EOF
chmod +x ~/wifi_b43.sh

Now you can reconnect to the network once you have booted by running [~/wifi_(driver of choice).sh]. To download anything from the internet, you use the wget program, which we have been using a lot anyway in the LiveCD. You need to compile this again once you have installed the OpenSSL package, which will come along shortly.

tar -xjvf /sources/network/wget-1.12.tar.bz2
cd wget-1.12
./configure --prefix=/usr --sysconfdir=/etc
make $CORES_TO_USE
make install
install-info --info-dir=/usr/share/info /usr/share/info/wget.info
cd ..
rm -rvf wget-1.12

Now for the script to automatically do all of that. Because part of the commands that we are pasting into the script is an actual [cat] command with an EOF, we cannot use the EOF marker for the surrounding script. Otherwise the [cat] command would just terminate as soon as it hit the first EOF. If only I could think of some other marker to use ...

sudo cat > install_network.sh << "ARSE" 
cd /sources/network
tar -xzvf /sources/network/wireless_tools.28.tar.gz 
cd wireless_tools.28 
make 
make PREFIX=/usr install 
cd .. 
rm -rvf wireless_tools.28
tar -xjvf /sources/network/net-tools-1.60.tar.bz2
cd net-tools-1.60
patch -Np1 -i ../net-tools-1.60-gcc34-3.patch
patch -Np1 -i ../net-tools-1.60-kernel_headers-2.patch
patch -Np1 -i ../net-tools-1.60-mii_ioctl-1.patch
yes "" | make config
sed -i -e 's|HAVE_IP_TOOLS 0|HAVE_IP_TOOLS 1|g' -e 's|HAVE_MII 0|HAVE_MII 1|g' config.h
sed -i -e 's|# HAVE_IP_TOOLS=0|HAVE_IP_TOOLS=1|g' -e 's|# HAVE_MII=0|HAVE_MII=1|g' config.make
make $CORES_TO_USE
make update
cd ..
rm -rvf net-tools-1.60
tar -xjvf /sources/network/dhcpcd-4.0.11.tar.bz2
cd dhcpcd-4.0.11
make PREFIX= LIBEXECDIR=/lib/dhcpcd DBDIR=/var/lib/dhcpcd SYSCONFDIR=/etc/dhcpcd 
make PREFIX= LIBEXECDIR=/lib/dhcpcd DBDIR=/var/lib/dhcpcd SYSCONFDIR=/etc/dhcpcd install 
sed -i "s;/var/lib/dhcpcd-;/var/lib/dhcpcd/dhcpcd-;g" dhcpcd-hooks/50-dhcpcd-compat 
install -v -m 644 dhcpcd-hooks/50-dhcpcd-compat /lib/dhcpcd/dhcpcd-hooks/ 
cd .. 
rm -rvf dhcpcd-4.0.11 
tar -xjvf /sources/network/blfs-bootscripts-20090302.tar.bz2 
cd blfs-bootscripts-20090302 
make install-service-dhcpcd 
cd .. 
rm -rvf blfs-bootscripts-20090302 
cat > ~/wifi_wl.sh << "EOF"
rmmod b43 
rmmod ssb 
rmmod wl
rmmod lib80211
modprobe lib80211
modprobe wl
dhcpcd -L -t 1 XXXX
iwconfig XXXX essid "YYYY" key ZZZZ
dhcpcd XXXX
EOF
chmod +x ~/wifi_wl.sh
cat > ~/wifi_b43.sh << "EOF"
rmmod b43 
rmmod ssb 
rmmod lib80211
rmmod wl
modprobe b43
sleep 1
iwconfig XXXX essid "YYYY" key ZZZZ
dhcpcd XXXX
EOF
chmod +x ~/wifi_b43.sh
tar -xjvf /sources/network/wget-1.12.tar.bz2 
cd wget-1.12 
./configure --prefix=/usr --sysconfdir=/etc 
make $CORES_TO_USE
make install 
install-info --info-dir=/usr/share/info /usr/share/info/wget.info 
cd .. 
rm -rvf wget-1.12
ARSE
chmod +x ./install_network.sh
sudo mv ./install_network.sh /media/lfs/root 

Once you have pasted that script, you reboot to the Amiga Key, login in, and run the script [~/install_network.sh]. You will then need to run the [iwconfig] command to get your network interface name, and then [nano] the script in your [~] directory and paste in the name instead of XXXX. Complete the YYYY and ZZZZ stuff per your own network configuration.

Finally, remember that you may want to reinstall the wget program once you have SSL support installed in due course.

Friday, 30 July 2010

LAP - Actual Build - Part 9a, What Went Wrong

As I have remarked a couple of times, the first build of this did not boot. As a result, I decided to use Grub 0.97 instead of 1.97. The failure may not have been the fault of Grub 1.97, and I am therefore going to repeat all the Grub 1.97 instructions here, as I may want to review this in the future to try to get it to work.

There are 3 reasons, to my mind, why a boot might fail. The first is the Grub bootloader. If this is configured incorrectly, then you do not pass go. The second is the Kernel. If you are trying to boot off a USB Key but you have not configured USB Storage support in the Kernel, it ain't going to work with even the best grub configuration. The third potential issue is if you haven't configured your /etc/fstab file to actually mount [/] properly.

When I tried to boot from the USB Key the boot process would continually fail, and complain that the 'root=' that I was trying to mount could not be found. No matter what combination of options I put into the grub configuration nothing seemed to work. Irritatingly, sometimes it failed saying sdb1 could not be found, and then listed the possible partitions -INCLUDING FUCKING sdb1. However, sometimes it did not. One of the things that really fucks me off is an intermittent problem, and here I had one. So I went looking for solutions. I went in the reverse order of the potential problems in the previous paragraph.

I had started with an fstab which used the UUID for the USB Key. That's the long-string-of-letters-and-numbers you find if you look in /dev/disk/by-uuid. However, due to the collossal fuckup that was trying to boot, I reverted to mounting the drive by reference to its label, which I called 'amiga', way back when I formatted it in the configuration stages. Why are either of these options not in the book? The book supposes that you are installing to a Harddisk drive. We are installing to a USB Key. As we have already seen if we shift from PC to PC the /dev/sd{a-d}1 changes. So, if we boot on a PC using an [fstab] file which just references the sdb1 location, for instance, then we'll be fucked if it is not exactly the same. One way we can avoid this is by referring to disks by their UUID number. This is the random string and is allocated at the time of (I think) formatting the disk. The UUID is built into the USB Key and will follow it from machine to machine, so referring to it directly is always going to work. That may, however, have contributed to the grand boot fuckup, as I shall now be calling it. So I switched the fstab to use the label instead. This did not immediately fix the problem, but it is now working and being a strong proponent of the 'if it ain't broke don't fix it' school, I am not fucking around with the fstab file now.

So I had tried fstab. My next move was to try the kernel. I actually went through:

<*> ATA/ATAPI/MFM/RLL support  --->
<*> Serial ATA (prod) and Parallel ATA (experimental) drivers  --->
Sonics Silicon Backplane  ---> (apart from debuggin)
USB

*** NOTE: USB_STORAGE depends on SCSI but BLK_DEV_SD may ***                                                             
*** also be needed; see USB_STORAGE Help for more info ***
<*>   USB Mass Storage support

and activated every single option I could find. I then compiled what must have been a massive Kernel file. Did it work? Did it fuck.

I then tried to get to grips with the settings for Grub 1.97. Few of them made any sense to me. I couldn't work out what the 'search' line in the configuration file was supposed to do. It looked quite unlike anything in the 0.97 version of grub. I suspected that the problem was the reassignation of drive identities when booting from the USB Key. This is relatively easy to fix in grub 0.97, but most definitely NOT in 1.97. So I decided to use Grub 0.97. The only way I could think to do this (because there is no automatic package management in LFS) was to format the disk and start again. This took a few hours. They were not particularly happy hours. Especially when it changed precisely fuck all about the boot problem.

However, I now at least had a simple grub file to work with. The first thing I could fix was the [root (hdX,X) line. I knew that using the same [hdX] as the Key was using during the install was a bad idea, because it would be reassigned on boot. I changed this to [root (hd0,0)], and this let me at least start the boot. I then got the same error messages as before. I thought that the [kernel=] line may have had a problem with finding the USB Key because of the stupid messages like 'sdb1 cannot be found, try sdb1 instead'. Fucking ridiculous. I thought if I set it find the disk by UUID or Label instead it might fix this. It turns out that you can't do that without configuring an [init]ial [r]am[d]isk. That does not sound like fun, so I turned to the Kernel Documentation instead to try and find an alternative. In there I came across the [rootdelay] option. This tells the Kernel to wait for a specified number of seconds before trying to boot. In particular it lets us wait for the USB Keys to show up. 10 seconds seems to work fine. Once I had put this setting in the grub.lst file, it ACTUALLY FUCKING BOOTED LINUX!

POSSIBLY if hd0,0 and rootdelay=10 AND fstab had been correct it may have worked with grub 1.97. Maybe. So, in case I want to revert to grub 1.97 at some point in the future, I am going to repeat its install commands here. Firstly you need to install the package - run these commands from the /sources directory.

tar -xzvf archive/grub-1.97.2.tar.gz
cd grub-1.97.2
mkdir build 
cd build 
../configure --prefix=/usr --sysconfdir=/etc --disable-grub-emu --disable-grub-emu-usb --disable-grub-fstest --disable-efiemu 

The [sysconfdir] presumably tells the install where to put the configuration files for grub.  According to the book, the [disable] options block program features that we have no need for in LFS.  Fair enough.

make -j2
make install
cd ../..
rm -rvf grub-1.97.2

There is much more to do to install Grub to the boot sector of the disk in question. 

First we setup a [device.map] file, which will be no fucking use once we reboot from the USB Key:

grub-mkdevicemap --device-map=device.map

Let's have a look at the contents:

cat device.map

I got:

(hd0) /dev/sda 
(hd1) /dev/sdb 
(hd2) /dev/sdc

[sda] is the harddisk in my laptop. [sdb] is the USB Key which the LiveCD is running from. [sdc] is the USB Key which has Linux From Scratch installed on it. To install the operative files for grub (as opposed to installing the package which we did earlier) I ran this command:

grub-install --grub-setup=/bin/true /dev/sdc

The [grub-setup=/bin/true] option makes sure that the actual MBR remains untouched for the time being. We can now automatically make the configuration file for grub:

grub-mkconfig -o /boot/grub/grub.cfg

This produced these messages:

Generating grub.cfg ... 
Found linux image: /boot/vmlinux-2.6.32.8-lfs-6.6 
done

I then ran the following command to install Grub to the MBR of the USB Key:

grub-setup /dev/sdc 

And that should be that. Only it won't be. We'll have to change the grub.cfg and probably device.map to reflect the reality of what will happen when the USB Key is the boot device.  And I am bollocksed if I am going to work out how to do that when 0.97 just bloody works.

Thursday, 29 July 2010

LAP - Actual Build - Part 9, Making it Boot

We now need to actually make our USB Key bootable.  The first step in that is to create the configuration file which tells the system what filesystems are connected.
cat > /etc/fstab << "EOF"
# Begin /etc/fstab
# file system  mount-point type   options        dump fsck
#                                                     order
/dev/disk/by-label/amiga     /           ext3  defaults,barrier=1       1    1
#/dev/disk/by/uuid/????     none        swap   pri=1          0    0
proc           /proc       proc   defaults       0    0
sysfs          /sys        sysfs  defaults       0    0
devpts         /dev/pts    devpts gid=4,mode=620 0    0
tmpfs          /dev/shm    tmpfs  defaults       0    0
# End /etc/fstab
EOF

The file contains filesystem objects on the left handside, then where they are mounted in the filesystem in the next column.  The third column has the type of the filesystem that you are mounting.  The rest of the settings depend on the particular mount, and are not worth going into here.

I mount the USB Key by reference to its label which I set way back in the configuration phase.  That way I do not have to rewrite the [fstab] file every time I move the USB Key between filesystems.  We already know about proc, sysfs, devpts and tmpfs.  These are all the filesystems we had to mount to use the chroot.  I am not going to bother with swap, it does not make sense on a USB Key, so I have [#] commented that line out.  I am leaving the information in the file, though, just in case.

The next stage is to, finally, actually compile our Kernel. I've gone through this process a couple of times and it is mind numbingly complex. The menu system for setting all the kernel options is, and I am being charitable here, obtuse. There appears to be absolutely no rhyme nor reason to the ordering of menu entries or indeed the whole menu structure.

It strikes me strongly as a historical bodge job. Each time someone has a bright idea to modify the kernel, another option goes into the menu structure. It is just added in wherever the author fancies. Multiply this by several hundred times and you get some idea of how unstructured the whole thing is. Frankly, a LOT of work could be done to make this system more intuitive.

And I don't mean that the names of the vast majority of various menu entries are bizarre. I mean there is a certain stupidity in having a menu right on the opening screen for "File systems", a separate opening screen menu for "Block Layers" (which are the storage devices that are going to get the fucking file systems) AND THEN a menu under the Device Drivers menu for "Block Devices". There is a separate Device Driver menu for PATA, SCSI and SATA drivers. Waaaaaay down the list is an entry for USB Support and waaaaaaaay down the sub-menu is finally the entry for USB Mass Storage support. All of this stuff relates to storage devices. Why the fuck is it spread all over the place?

Here's a suggestion. Menu entry: "Storage". All the storage shit in there. You want to change something to do with Storage? You go to the Storage menu. You could also just DUPLICATE the entry for USB Mass Storage in the Menu entry: "USB Shit". There is no reason why you need to only have one of each item.

Don't get me started on the fucking network nonsense. Opening screen menu called "Networking Support" and then a separate Device Driver section for "Network device support". Confused yet?

What they also need is some kind of indication about the fuck up potential of each of the settings. As it is, when you start up the editor you get a whole load of default settings. You have no idea which ones can go and which have to stay. Now, what I would like to see is the menu not only structured by hardware function, but also by complexity. So, something like a beginner gets all the default stuff and then a quiz about what graphics card, sound card, network card and hard disk type he has. A more intermediate user is let into all the multiple choice settings, but the real confusing stuff is hidden away. Stuff like CPU settings and I2C and debugging crap.

Frankly this menu system requires someone to take the interface design equivalent to a blowtorch to it. Anyway, it is all we've got. What I would absolutely recommend, when you get stuck, and you will, is that you go and read Linux Kernel in a Nutshell, specifically chapters 4 (which explains how you use the menu configuration program), 7 (which explains how you go about working out what kernel settings you need for your machine) and 8 (which sets out some common configuration groups for stuff like USB Storage support). The book is excellent, and available under the Creative Commons licence. It is not entirely up to date (it is for kernel 2.6.18 and we are using 2.6.32) but it is a brilliant primer.

OK, lets get on with this bollocks. Here is what I did, and it seems to work. It is probably quite bloated though, and an after-project job will be to trim this down to get rid of the stuff I do not need.

cd /sources
tar -jxvf /sources/linux-2.6.32.8.tar.bz2
cd linux-2.6.32.8
make mrproper
make LANG=en_GB.utf8 LC_ALL= menuconfig

I am then faced with the following menu of options.

                         General setup  --->                                                                     
                        [*] Enable loadable module support  --->                                                    
                        -*- Enable the block layer  --->                                                           
                            Processor type and features  --->                                                       
                            Power management and ACPI options  --->                                                 
                            Bus options (PCI etc.)  --->                                                            
                            Executable file formats / Emulations  --->                                              
                        [*] Networking support  --->                                                                
                            Device Drivers  --->                                                                   
                            Firmware Drivers  --->                                                                  
                            File systems  --->                                                                     
                            Kernel hacking  --->                                                                    
                            Security options  --->                                                                  
                        -*- Cryptographic API  --->                                                                 
                        [*] Virtualization  --->                                                                   

The first thing you want to do is to go into filesystems and make sure that EXT2-EXT4 is all supported in the kernel.  Select the following options:

                      <*> Second extended fs support                                                              
                      [*]   Ext2 extended attributes                                                              
                      [*]     Ext2 POSIX Access Control Lists                                                     
                      [*]     Ext2 Security Labels                                                                
                      [ ]   Ext2 execute in place support                                                         
                      <*> Ext3 journalling file system support                                                    
                      [ ]   Default to 'data=ordered' in ext3                                                     
                      [*]   Ext3 extended attributes                                                              
                      [*]     Ext3 POSIX Access Control Lists                                                     
                      [*]     Ext3 Security Labels                                                                
                      <*> The Extended 4 (ext4) filesystem                                                        
                      [*]   Ext4 extended attributes (NEW)                                                        
                      [*]     Ext4 POSIX Access Control Lists                                                     
                      [*]     Ext4 Security Labels 

If using EXT4 then make sure that the following is set:

                      [*]   Support for large (2TB+) block devices and files (NEW)

You also need to install your sound drivers.  You find these as follows:

 Device Drivers  --->
<*> Sound card support  --->
<*>   Advanced Linux Sound Architecture  --->
[*]   PCI sound devices  --->

If, of course you are using a PCI based soundcard.  I select the following to fit with my various machines:

<*>   Emu10k1 (SB Live!, Audigy, E-mu APS)
<*>   Intel HD Audio  --->
<*>   Intel/SiS/nVidia/AMD/ALi AC97 Controller

I have a couple of nVidia motherboards, and need support for their onboard controllers:

 Device Drivers  --->
<*> Serial ATA (prod) and Parallel ATA (experimental) drivers  --->
<*>     NVIDIA SATA support 

To get high resolution (!) text screens on boot I made sure these settings were activated:

Device Drivers  --->
Graphics support  --->
<*> /dev/agpgart (AGP Support)  --->
<*>   Intel 440LX/BX/GX, I8xx and E7x05 chipset support

Device Drivers  --->
Graphics support  --->
<*> Direct Rendering Manager (XFree86 4.1.0 and higher DRI support)  --->
<*>   Intel 830M, 845G, 852GM, 855GM, 865G (i915 driver)  --->                              
                             i915 driver

I actually came back and changed this setting during a later build. X was complaining that it could not find 'i915'. I have to say, it did not seem to make any difference whatsoever to the system, but I don't like errors. I changed this to build this as a module. This lets you also choose the i830 driver as a module as well. This way the system can choose whatever it likes. X stopped complaining once I did this. Still made no change to the performance.

Device Drivers  --->
Graphics support  --->
-*- Support for frame buffer devices  --->
<*>   Userspace VESA VGA graphics support                                                   
                     [*]   VESA VGA graphics support 

I did NOT enable the nvidia framebuffer driver. Also, do NOT set the -> Device Drivers -> Graphics -> Console display driver support -> Framebuffer Console support to install as a module. It will give you a blank screen.

To ensure that wireless networking was going to work I set the following options:

Device Drivers  --->
[*] Network device support  --->
[*]   Wireless LAN (NEW)  --->
[*]   Wireless LAN (IEEE 802.11)  --->
<m>   Broadcom 43xx wireless support (mac80211 stack)

Note, I have set that to [M] for module.  This means I can load or unload it depending on the machine I am running the USB Key from.  You would want to look through the rest of that menu to find out if there are any other wireless drivers you want to install. After I finished the build, I went back and rebuilt the kernel with the Atheros driver selected as a module. This allowed me to get my PCI Express Abit Airpace card to work. No firmware needed.

Device Drivers  --->
[*] Network device support  --->
-*-   PHY Device support and infrastructure  --->
<m>   Drivers for Broadcom PHYs

[*] Networking support  --->
<*>   RF switch subsystem support  --->

I turned this RF option off in a later build and it made no difference. Best to remove unnecessary crap thinks I.

[*] Networking support  --->
[*]   Wireless  ---> 
[*]   Old wireless static regulatory definitions
[*]   Wireless extensions
[*]     Wireless extensions sysfs files
<m>   Common routines for IEEE802.11 drivers
<*>   Generic IEEE 802.11 Networking Stack (mac80211)
[*]   Enable LED triggers

To help with USB I set the following:

Device Drivers  --->
[*] USB support  --->
<*>   Support for Host-side USB
The trackpad on my laptop can be erratically detected so I am going to build the 'mouse' driver as a module:

Device Drivers  --->
Input device support  --->
[*]   Mice  --->
<m>   PS/2 mouse

Once I set all that I went to

Save an Alternate Configuration File

and made sure that my changes were saved.  I then selected:

< Exit >

and it dropped me back to the prompt.  From there I ran the by now customary:

make $CORES_TO_USE

The build messages ended with:

Root device is (8, 33) 
Setup is 12156 bytes (padded to 12288 bytes). 
System is 4189 kB 
CRC 25b759c7 
Kernel: arch/x86/boot/bzImage is ready  (#1) 

The build itself took 28m50s on my celeron laptop.  I also need to run a separate command to compile the drivers I specified as [M]odules.

make modules_install

Then we copy the files we just made to the /boot directory:

cp -v arch/x86/boot/bzImage /boot/vmlinux-2.6.32.8-lfs-6.6
cp -v System.map /boot/System.map-2.6.32.8
cp -v .config /boot/config-2.6.32.8

We can also install the documentation:

install -d /usr/share/doc/linux-2.6.32.8
cp -r Documentation/* /usr/share/doc/linux-2.6.32.8

We also want to convert all the files in this directory to root ownership to protect them in the future:

chown -R 0:0

This returned the following helpful message:

chown: missing operand after `0:0' 
Try `chown --help' for more information.

Ah. Perhaps we need the '.' to tell it we are referring to the current directory.

chown -R 0:0 .

Seems to have worked.  To ensure that any USB drivers start up in the right order, we install the following modprobe configuration file:

install -v -m755 -d /etc/modprobe.d
cat > /etc/modprobe.d/usb.conf << "EOF"
# Begin /etc/modprobe.d/usb.conf

install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true
install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true

# End /etc/modprobe.d/usb.conf
EOF

Next, according to the LFS6.6 instructions is the configuration of Grub 1.97.  For reasons I will go into in full in due course, I am using Grub 0.97 instead.

Grub 0.97, or legacy grub, is an older version of grub than is used in the LFS 6.6 book.  I am going to use it instead of Grub 1.97, for reasons I go into in more detail elsewhere.  As 0.97 is not in the large .tar file I downloaded, the first thing I will have to do is download the 0.97 version.  As with nano, this means exiting the chroot to get internet access back.

exit
cd /media/lfs/sources
sudo wget ftp://alpha.gnu.org/gnu/grub/grub-0.97.tar.gz
sudo wget http://www.linuxfromscratch.org/patches/lfs/6.5/grub-0.97-disk_geometry-1.patch
sudo wget http://www.linuxfromscratch.org/patches/lfs/6.5/grub-0.97-256byte_inode-1.patch
sudo chroot "/media/lfs" /usr/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin CORES_TO_USE=-j2 /bin/bash --login
cd /sources

tar -xzvf grub-0.97.tar.gz
cd grub-0.97
patch -Np1 -i /sources/grub-0.97-disk_geometry-1.patch

Disk Geometry sounds a bit scary, but actually this just makes grub more compatible with some newer SATA drives, and makes it better are detecting drives in general.  Brings it up to date in other words.  The second patch make grub compatible with ext2 systems which use 256 byte inodes.  No word on how it works with 128 bit earnodes.

patch -Np1 -i /sources/grub-0.97-256byte_inode-1.patch
./configure --prefix=/usr
make CFLAGS="-march=i486 -mtune=native -Os"
make check

==================
All 1 tests passed
==================

make install

We need to make a directory in the boot folder to contain all the [grub] files.  Some systems will have the /boot folder contained in its own partition, and it is therefore important to have all the relevant files in one place:

mkdir -v /boot/grub

What we then do is copy some … important files that do … something … important to the new directory:

cp -v /usr/lib/grub/i386-pc/stage{1,2} /boot/grub
cp -v /usr/lib/grub/i386-pc/e2fs_stage1_5 /boot/grub

What I am going to do next is create a script to use to configure grub.  I am doing this so I do not have to use the grub interactive system, but can simply automate it instead.

cat > /etc/grub.conf << "EOF"
root (hd1,0)
setup (hd1)
quit
EOF

In the script, we first tell grub that our root partition is [hd1,0].  In the language of grub this means /dev/sdb1.  Why does grub have to be different?  Well it just does, but I am not going to rant about this too much, because I understand it is much better in the latest versions of grub, which I am stubbornly refusing to use.  I did once get caught out with this, I had done a bit of disk swapping and my Amiga Key was [sdd1]. However there was NO [sdc1] on the system, so I had to point grub at [hd2] instead of [hd3]. The next command tells grub to install itself to the MBR of [hd1] or [sdb].  It then quits.  Obviously, if the Amiga Key has a different designation (sdc) for instance, you would replace hd1 (hd2 for sdc). To find the correct drive, you can run grub, and use the command [geometry (hdX)] where X is where you think you should install grub. The response will tell you the device name so you can double check. We then have to run the script:

grub --batch < /etc/grub.conf

The [<] in this scenario reverses the direction of the file that follows, so the [grub] program when used with the [batch] option looks for input which is then supplied by the [<].

Next we will create the configuration file for Grub which actually sets up what happens when grub tries to boot. When you first do this you probably want the timeout to be, say, 30 seconds. However, once it is up and running you can change it to, say, 1 second.

cat > /boot/grub/menu.lst << "EOF"
# Begin /boot/grub/menu.lst
# By default boot the first menu entry.
default 0
# Allow 30 seconds before booting the default.
timeout 30
# Use prettier colors.
color green/black light-green/black
# The first entry is for LFS.
title LFS 6.6
root (hd0,0)
kernel /boot/vmlinux-2.6.32.8-lfs-6.6 root=/dev/sdd1 vga=773 rootdelay=10
EOF

Right, first of all you will have noted that we are using [hd0,0] here, not the [hd3,0] from earlier.  Why?  Well my best guess is that when we actually boot from the device it becomes the first drive, at least as far as grub is concerned.

The [kernel] line tells grub what kernel file to load and where to find it.  The file referred to was created when we built our kernel, and we copied it to that directory.  We next set the partition that contains the root drive.  This is the tricky bit.  This will vary from machine to machine, and even on the same machine, depending on how the machine dishes out the names at boot.  We cannot use [label] or [uuid] settings here.  Potentially we could if we used an [init]ial [r]am [d]isk, or we upgraded Grub, but I'm not exploring that for now.  The bottom line is that if I get a boot error when I move to a new machine, I can just edit the grub commands on boot, and then re-write the menu.lst file.  Editing the grub commands on boot is EASY, we just hit 'e' when selecting the entry and we can change whatever we want.

[vga=773] tells the kernel to use a graphical mode of 1024x768.  771 is 800x600.  [rootdelay=10] is most likely to be the solution to my grand boot fuckup.  The kernel doesn't always, and hardly never, detects USB devices before it decides to try to boot from them.  This is monumentally stupid, and is partially corrected by this command.  It tells the kernel to wait 10 seconds to let and USB devices get configure before trying to boot.  This prevents the system shitting itself when it can't find the disk you have told it exists.

Adding another boot option is really easy. You just copy the [title], [root] and [kernel] lines and give them alternative options. You will want to do this if you regularly move the Amiga Key between machines, as hitting 'e' and manually editing the lines is going to get very boring after a while.

mkdir -v /etc/grub

We then just make a symbolic link, the need for which escapes me at present.

ln -sv /boot/grub/menu.lst /etc/grub
cd ..
rm -rf grub-0.97

Then you just reboot into a functional system.  Maybe!

You will probably want to rebuild your kernel at some stage, and if so the commands are as follows (assuming you are in either chroot or running on metal).  This will start you with a clean default kernel build.  If that does not work for you, then you should omit the [make mrproper] line, and it should load your last settings.

cd /sources/linux-2.6.32.8
make mrproper
make LANG=en_GB.utf8 LC_ALL= menuconfig
make $CORES_TO_USE
make modules_install
cp -v /boot/vmlinux-2.6.32.8-lfs-6.6 /boot/vmlinux-2.6.32.8-lfs-6.6.backup
cp -v /boot/System.map-2.6.32.8 /boot/System.map-2.6.32.8.backup
cp -v /boot/config-2.6.32.8 /boot/config-2.6.32.8.backup
cp -v arch/x86/boot/bzImage /boot/vmlinux-2.6.32.8-lfs-6.6
cp -v System.map /boot/System.map-2.6.32.8
cp -v .config /boot/config-2.6.32.8