Build Environment Set-Up [June 1, 2012, 3:09 p.m.]
Goal
At this point, we'll start to lay out our foundation. Our goals are all of the following:
-
A "bootstrapping" filesystem that closely mirrors the one found in the book, makes it easy to keep track of what we're doing, and allows us to build programs as an ordinary user while making sure the only user that can install software is an administrator. This usually has the creative name "build environment".
-
A way to "rewind" in case we mess anything up. This is usually done with something called "version control".
- A way to modularize components so that they can be used on multiple systems. This is called "packaging".
We'll be using git for version control, and RPM for packaging.
Build Environment
Okay, whether you're here from a Windows, BSD, Mac, Linux, or other environment, the rest of the commands are going to be similar. I'll explain any differences. If you haven't run the version-check.shhttp://greenback.gremlin.net/version-check.sh script from a bash shell successfully yet, you don't belong here; please look over the other tasks. Even if you're on another OS, the videos in the Windows task might be helpful to you as well.
To start off with, we're going to make a folder with the following directory tree layout.
clfs -+-> book
|
+-> build
|
+-> patches
|
+-> scripts
|
+-> sources
|
+-> specs
You can do this from your home directory with the following command:
mkdir -p ~/clfs/{book,build,patches,scripts,sources,specs}
If that last command didn't work for you, it's possible you're running from a busybox bash shell. I'll be using {,} substitution frequently through these instructions, and it would be easiest to follow along if you went ahead and installed a proper bash shell. However, you can always expand that manually any time you see it. The expanded version of that command would look like this:
mkdir -p ~/clfs/book ~/clfs/build ~/clfs/patches ~/clfs/scripts \
~/clfs/sources ~/clfs/scripts
You can check to see which bash shell you have with the command
bash --version
Next, if you haven't already done so, go ahead and populate the sources and patches directories like so:
cd clfs/sources
wget http://greenback.gremlin.net/downloads.txt
wget -i downloads.txt
mv *.patch ../patches
Next, if you haven't already done so, go ahead and populate the scripts directory like so:
cd
cd clfs/scripts
wget http://greenback.gremlin.net/chown
wget http://greenback.gremlin.net/RENAME.profile
wget http://greenback.gremlin.net/version-check.sh
Finally, we'll add the seed spec to the specs folder:
cd ~/clfs/specs
wget http://greenback.gremlin.net/seed.spec
It might be a good idea right now to back up your clfs directory (everything we just created). How this is done is up to you. Two good options are creating a tarball, and burning everything to CD or DVD.
Next, we're going to need to set up our clfs directory. First, let's go ahead and create it in a shell with admin rights:
mkdir -p /mnt/clfs
If you are actually making CLFS on another device, you can go ahead and mount it now. This is going to be environment dependent. In an MSYS environment, as an administrator, assuming I wanted to build on my USB stick which Windows recognizes as my H drive, it's
echo "H:/ /mnt/clfs" >> /etc/fstab
In most unix-likes, assuming I have a USB stick which the OS recognizes as /dev/sdb1, as an administrator (or for you hotshots, an ordinary user with permissions set up correctly in /etc/fstab) it's
mount /dev/sdb1 /mnt/clfs
If you're building CLFS in another directory, you can either remove your clfs directory and make /mnt/clfs a symbolic link, or you can loop mount. The sytnax for loop-mounting in MSYS is exactly the same as mounting a device. Just make sure no paths have spaces and use short path names (like "Progra~1") if there are spaces. In a unix-like, as an admin and assuming I'm really building in a folder called clfs in my home directory, it's
mount --bind ~/clfs /mnt/clfs
This way is also my personal favorite, especially for a first-time build.
Once you've got your clfs directory made and mounted, you're going to need to make some directories. For this command, you can use either an ordinary user or an admin shell. Just be sure you've got permission to write to the directory /mnt/clfs.
mkdir -p /mnt/clfs/{bin,usr/bin,tools,cross-tools}
Next, we'll need to create a couple links.
Msys users, don't use ln -s. In the second video in the windows task, I tell you how to use mklink to create symbolic links. You'll want to do that instead of ln -s any time you see the command. So from msys, as an admin, you'll either do:
cd /
cmd
mklink /J tools H:\tools
mklink /J cross-tools H:\tools
or
mkdir /{,cross-}tools
echo "H:/tools /tools" >> /etc/fstab
echo "H:/cross-tools /cross-tools" >> /etc/fstab
If you are NOT using MSYS, it's a little easier (as root):
ln -sv /mnt/clfs/tools /tools
ln -sv /mnt/clfs/cross-tools /cross-tools
The book recommends creating a clfs user at this point. If you're interested in doing this, it's in section 4.4. This is entirely optional and won't affect any of my instructions.
Section 4.5 has in depth advice for setting up your environment. For my instructions, I will assume you only have one profile script. If you are not in an msys environment, I'd like to advise you to set up a bashrc script so that it simply sources your .bash_profile script, like so:
cat > ~/.bashrc << "EIO"
#!/bin/bash
. ~/.bash_profile
EIO
And as I mentioned earlier, in msys the name of the script is ~/.profile . For me, you only need to make sure that inside your profile script (either ~/.profile or ~/.bash_profile), your PATH environment variable leads off with "/cross-tools/bin" and that you have your CLFS environment variable set. The two lines might look like this (not literally; the "..." expands into my full PATH variable; I just wanted to get across that /cross-tools/bin is at the front):
export PATH="/cross-tools/bin:.:/usr/local/bin:/mingw/bin:..."
export CLFS=/mnt/clfs
You also need the following line in there somewhere:
set +h
That line turns off "hashing", which means that bash has to search your entire PATH environment variable fresh each time instead of caching results.
For MSYS, I have an example profile script called RENAME.profile2. For other operating systems, you can examine this script and the three lines I just mentioned.
Once you have your profile script written, you source it like so:
Unix,
. ~/.bash_profile
MSYS,
. ~/.profile
Okay! We have our environment completely set up and we're done with this task. Before we're completely ready to build CLFS, we'll make a couple tools from source that will help us out a lot.