This course will become read-only in the near future. Tell us at community.p2pu.org if that is a problem.

Build Environment Set-Up [May 18, 2012, 2:30 p.m.]



Prerequisites


First and foremost, building Linux is going to take you using the shell a lot. If you aren't comfortable using a bash shell and the "make" utility to build software, you'll want to check out these links first (this list is in the book in the "Prerequisites" section of the Foreword)

http://www.tldp.org/HOWTO/Software-Building-HOWTO.html

http://www.linuxhq.com/guides/LUG/guide.html

http://hints.cross-lfs.org/index.php/Essential_Prereading

Cross linux from scratch can be built from just about any operating system with a working C compiler. I'll be building mine on a Windows machine using the free MinGW compiler, using MSYS for my shell and environment. I made a quick video in three parts weighing in at about half an hour helping you if you're starting out this way (you might want to full screen):

http://youtu.be/U2Agy6ulJtc

http://youtu.be/it4kGicvADI

I didn't get around to it in the next video, but you can chain configure and make together with a double-ampersand like

./configure --all-your-config-options && make

http://youtu.be/-Tl2WsGfw1M

And you'll want to grab your dependencies from the following URLs:

http://www.mingw.org/wiki/Getting_Started

http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express

http://sourceforge.net/projects/gnuwin32/files/

ftp://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.9.tar.gz

 

If you're on windows and you want to be able to create and use native linux ext2 filesystems, there's two more dependencies you'll need:

http://www.fs-driver.org/

http://cygwin.com/install.html

If you're on windows 7, you have to install ext2 IFS in compatibility mode for Windows Vista Service Pack 2. You can change the compatibility mode by right clicking on the installer and then going to Preferences->Compatibility.

Cygwin installation is a little involved for this tutorial (which is why I linked to the install help page instead of the download page), but make sure that these two things are true:

  1. You've installed cygwin to a different top-level directory from mingw/msys (in other words, something like C:\cygwin and C:\mingw would work)
  2. You've installed the e2fsprogs and e2fsimage packages, found under "System"

Once everything's installed, you can create your new ext2 filesystem with these commands in an administrator shell:

# create a 4 GB file

dd if=/dev/zero of=fs.ext2 bs=32M count=128

# make ext2 filesystem

mkdir rootdir

e2fsimage -f fs.ext2 -d rootdir -v

All of those commands so far were completely safe. You can build cross linux from scratch using rootdir as your LFS directory, and run the e2fsimage command any time you want to copy things into your e2fs filesystem image. Doing things this way poses no threat to your host operating system.

The next command is not safe. The next command copies the filesystem image to your USB stick. The danger here is that if you are not careful, you run the risk of replacing an existing filesystem image with your LFS filesystem image. As long as you are careful, you should be okay. But I recommend backing up important files on your host system and having a recovery disk handy just in case.

First, you'll want to find your USB stick in cygwin. You can do that by running, with your USB stick plugged in and in a cygwin shell,

ls /dev > devlist_a.txt

Next, unplug your USB stick, and run
 

ls /dev > devlist_b.txt

diff devlist_{a,b}.txt

The device that shows up should be your USB stick. If you know what you're doing, you might also want to look at devlist_a.txt to double check and make sure you've got the correct device.

For me, the correct device was /dev/sdb1 . If you're 100% positive you've found your USB stick and you want to install your filesystem image to it, you can run

#replace this with your USB device file

export USBSTICK=/dev/sdb1

dd if=fs.ext2 of=$USBSTICK

You can do that at any time, including before building cross linux from scratch. Don't worry about the 4 GB filesize; we can grow that to fill the whole 8 GB USB stick later once we have the OS installed. If you do this before you build CLFS, you'll want to use your USB stick directly as your LFS directory. If you go into "my computer" and double click the drive letter your USB stick had, you'll see it says "removeable disk" and it thinks the file size is 4 GB now. You'll mount it in msys the same way we mounted Program files in the video above.

 

Using fat32 (what windows uses natively) works perfectly well, but you'll have to put up with some linux tools being unreliable and slower disk access, and on top of the slowdown you already get with a USB stick I highly recommend the ext2 approach instead.

I reccomend against ntfs, because older versions of linux only have read-only support. The last time I build the linux kernel there was experimental support for being able to write ntfs. That was fairly recent, and I want to stress the word "experimental". Fat32, on the other hand, has been supported for years and years.

 

I've also copied in some scripts from the CLFS book, and written a couple myself, here

http://greenback.gremlin.net/chown

http://greenback.gremlin.net/RENAME.profile

http://greenback.gremlin.net/downloads.txt

http://greenback.gremlin.net/version-check.sh

 


It's probably easiest if you're having trouble, though, to do this from a BSD, Mac, or a Linux computer. Linux has several LiveCD, LiveUSB, and virtualized distributions that are worth checking out. I think Linux from Scratch even has their own LiveCD made just for us. Any of these will have working c compilers and environments that will suit our needs. You can run the version-check.sh script (above) to see if your OS has everything we need to build CLFS.

 

You'll also need to download all the sources to local media. I reccomend a DVD so that everything's nice and indestructable. The book has a list of all the sources we'll need in sections 3.2 through 3.5. Probably the easiest way to get all of them is grab the downloads.txt file (above) and then use it with the wget utility like this:

wget -i downloads.txt

If you don't have wget, you can find generic instructions that will work in any build environment for building and installing it from source in wget's page in the CBLFS book, here:

http://cblfs.cross-lfs.org/index.php/Wget

 

Finally, whatever you're installing LFS to, it would help a lot if it were bootable. I picked an 8 GB USB stick. It doesn't have to be formatted, and in fact it would help a lot if you didn't care what was on it.

I will not be teaching you how to create LiveCDs, although there are tutorials that exist online, including here:

http://www.linux-live.org/

You can of course ignore all tasks past program installation. This will give you a "chroot" distribution, or a distribution you can use as an embedded distro from another linux distro with a compatible kernel via the "chroot" command. It's up to you if you want a bootable OS.

 

That's it; everything else we'll be building for ourselves.

Goal


In this stage, we 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


 

Git


 

RPM