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

Finalizing the Core OS


Putting the finishing touches on (branch off page 225)

For this task, I've copied a couple of sections in from the CLFS book, and have provided some links to the CBLFS book and other parts of the internet. Your goal here is to get your system to the state where you can boot into it.



 

File System


You can create a standard directory tree with the following commands:

mkdir -pv ${CLFS}/{bin,boot,dev,{etc/,}opt,home,lib,mnt}
mkdir -pv ${CLFS}/{proc,media/{floppy,cdrom},run,sbin,srv,sys}
mkdir -pv ${CLFS}/var/{lock,log,mail,spool}
mkdir -pv ${CLFS}/var/{opt,cache,lib/{misc,locate},local}
install -dv -m 0750 ${CLFS}/root
install -dv -m 1777 ${CLFS}{/var,}/tmp
mkdir -pv ${CLFS}/usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv ${CLFS}/usr/{,local/}share/{doc,info,locale,man}
mkdir -pv ${CLFS}/usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -pv ${CLFS}/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
for dir in ${CLFS}/usr{,/local}; do
  ln -sv share/{man,doc,info} $dir
done

The directory tree above is based on a standard called the "File Heirarchy Standard". You can learn more about the FHS here,

http://www.pathname.com/

but for now it's enough to know that it's a standard layout for Unix systems.

If you came here from chapters 6 and 7, branching from the "To Boot or Chroot?" section, you'll need the following symlinks as well:

ln -sv /tools/bin/{bash,cat,echo,grep,login,pwd,sleep,stty} ${CLFS}/bin
ln -sv /tools/sbin/{agetty,blkid} ${CLFS}/sbin
ln -sv /tools/bin/file ${CLFS}/usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1} ${CLFS}/usr/lib
ln -sv /tools/lib/libstd*so* ${CLFS}/usr/lib
ln -sv bash ${CLFS}/bin/sh
ln -sv /run /var/run

 

Making your system bootable


Here I'll give you the short version as far as installing a boot loader. When you first turn on your computer, it will run a program that is placed at the very beginning of a disk; that program is called a "boot loader" because it, in turn, runs the other programs which boot up your operating system. Here, we'll install the grub boot loader.

In chapter 10.63, it recommends installing the following script at /etc/default/grub :

# Begin /etc/default/grub
GRUB_DEFAULT=0
#GRUB_SAVEDEFAULT=true
GRUB_HIDDEN_TIMEOUT=
GRUB_HIDDEN_TIMEOUT_QUIET=false
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=Cross-LFS
GRUB_CMDLINE_LINUX=""
GRUB_CMDLINE_LINUX_DEFAULT=""
#GRUB_TERMINAL=console

#GRUB_GFXMODE=640x480
#GRUB_GFXPAYLOAD_LINUX=keep
#GRUB_DISABLE_LINUX_UUID=true
#GRUB_DISABLE_LINUX_RECOVERY=true
#GRUB_INIT_TUNE="480 440 1"
#GRUB_DISABLE_OS_PROBER=true
# End /etc/default/grub

Once we've done that, we can install the bootloader and its config file. The config file can be created with the command

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

Caution!

Warning (from page 248)

The following command will overwrite the current boot loader. Do not run the command if this is not desired, for example, if using a third party boot manager to manage the Master Boot Record (MBR). In this scenario, it would make more sense to install GRUB into the “boot sector” of the CLFS partition. In this case, this next command would become grub-install /dev/sda2.

The preceeding warning can be safely ignored if you built CLFS onto a USB stick with no other operating system. Please see the Windows task, however, for more warnings if you are going this route, even on other operating systems.

To install grub into the boot sector of the disk sda, the command is:

# grub-install /dev/sda

Windows Users

Because Grub configuration can be complicated with windows (you use a technique called "chain loading"), a technique I use that is compatible with Windows up to Windows 7 is to grab a Slackware installation CD, and use it to install the LILO boot loader to my MBR. This will take care of all configuration, and set Windows as the default operating system, automatically.

LILO and Grub are very similar, and each has advantages and disadvantages. Grub is probably my favorite choice overall because it is easy to configure from user space, but LILO is very easy to configure automatically. In fact, when you are building new drivers for your computer or upgrading to a new kernel, LILO can be updated automatically; in Grub you'd have to reconfigure your system manually.

Configuring your System


Here I'll very briefly go over the most essential parts of chapter 11. First and foremost, you're going to want to install your Sys V init scripts. Because this package consists almost entirely of configuration files which you'll edit frequently, we won't build from a spec this time. You'll want to run:

# cd /home/you/clfs/build
# tar jxvf ../sources/
bootscripts-cross-lfs-2.0-pre1.tar.bz2
# cd bootscripts-cross-lfs-2.0-pre1
# make install-bootscripts
# make install-network

Next, into /etc/sysconfig/clock, put the following:

#  Begin /etc/sysconfig/clock
UTC=1
# End /etc/sysconfig/clock

Next, into /etc/profile, put the following:

# Begin /etc/profile
export LANG=[ll]_[CC].[charmap]
export INPUTRC=/etc/inputrc
# End /etc/profile

Finally, in section 11.7 (page 233), there are instructions for configuring your CD device and resolving any potential device shortcut conflicts, and in section 11.9 (page 235), there are instructions for international configuration settings, including keyboard and language settings. These can wait until later if you choose.

Getting Online


Chapter 12, unfortunately, can't be very easily summarized, as you all will have very different network connection needs. So part of your task here will be reviewing the chapter and setting aside time to get your network working. However, the information in chapter 12 is incomplete, especially since most of you are likely to have WiFi connections. First, you will need a few more packages than what you've installed already. I'll link to their CBLFS pages here:

DHCPCD: http://cblfs.cross-lfs.org/index.php/Dhcpcd

Wireless Tools: http://cblfs.cross-lfs.org/index.php/Wireless_tools

WPA Supplicant: http://cblfs.cross-lfs.org/index.php/WPA_Supplicant

I'll briefly explain what each of those do.

You know how when you get online somewhere, you get a randomly assigned IP address? DHCPCD is a client program that negotiates with your server to get that IP address. It will do all the heavy lifting as far as connecting to the internet for you, including updating your /etc/resolv.conf file with your new IP address and other connection info. Once it is installed, getting online is usually simply a matter of calling either

# dhcpcd wlan0

or

# dhcpcd eth0

depending on whether you are connecting through your wifi or ethernet connections, respectively.

That command will only work when your hardware on your end is configured. You can run the command

# ifconfig eth0 up

to set up your ethernet card, but for a wifi connection, things are a little more complicated, and that's where the wireless tools package comes into play. A tool called iwlist can be used to scan for local hotspots. It outputs a lot of information, so we'll pipe it through grep to just give you the output you're likely to need:

# iwlist wlan0 scan | grep '\(ESSID\|Encryption\)'

That will generate a list of ESSIDs (the name of the network you're connection to), preceeded with an "Encryption key" flag that will let you know if the network is locked. On means locked, off means unlocked.

Once you know the ESSID of the network you'd like to connect to, you can connect to it with the following command:

# iwconfig wlan0 essid 'EXAMPLE_HOTSPOT in quotes since theres spaces'

If there were two hotspots (we'll say named "NETGEAR") and you wanted to differentiate between them (say you wanted the one with mac address 0A:BC:DE:F1:23:45), you would run

# iwlist wlan0 scan | grep '\(ESSID\|Encryption\|Address\)'
# iwconfig wlan0 essid NETGEAR ap '0A:BC:DE:F1:23:45'

to both get the mac address of the access point you want, and to pick the correct NETGEAR.

To see if you've connected successfully, simply run:

# iwconfig

If you did connect successfully, you'll see an ESSID and Mac Address associated with your name. You can now run the dhcpcd command we discussed earlier to get an IP address, and then open up your browser.

If you need a secure password protected connection, then iwconfig won't be enough for you. You'll need another program called WPA supplicant. To use WPA Supplicant, you'll first need a configuration file. The following will work with most WPA password protected access points. Add it at /etc/wpa_supplicant.conf :

# See /usr/doc/wpa_supplicant-0.6.10/wpa_supplicant.conf.sample
# for many more options that you can use in this file.

# This line enables the use of wpa_cli which is used by rc.wireless
# if possible (to check for successful association)
ctrl_interface=/var/run/wpa_supplicant
# By default, only root (group 0) may use wpa_cli
#ctrl_interface_group=0
#eapol_version=1
#ap_scan=1
#fast_reauth=1
#country=US

# WPA protected network, supply your own ESSID and WPAPSK here:
network={
  scan_ssid=1
  ssid="CHANGEME"
  proto=WPA RSN
  key_mgmt=WPA-PSK
  pairwise=CCMP TKIP
  group=CCMP TKIP WEP104 WEP40
  psk="CHANGEME"
  priority=0
}

# Plaintext connection (no WPA, no IEEE 802.1X),     
# nice for hotel/airport types of WiFi network.      
#network={                                           
#  key_mgmt=NONE                                     
#  priority=0                                        
#}

You'll want to change the words CHANGEME in the above script to your ESSID (which you can find with the iwlist command as discussed earlier) and your password (which you can get from whoever owns the access point you are connecting to).

You can then connect to the access point with the following command:

# wpa_supplicant -iwlan0 -Dwext -c/etc/wpa_supplicant.conf -B

If the command fails, you can omit the -B flag. This will prevent wpa_supplicant from running in the background, and will give you useful information you can use to track down the problem.

Once you have wpa_supplicant running, you will then want to run dhcpcd as discussed earlier to get an IP address, and you'll be connected to the internet.

Hardware


If none of those commands are working for you at all, it's possible you don't have a driver for your wireless card. You'll want to refer to chapter 11 of the CLFS book, and possibly a tutorial on building the linux kernel.

The kernel is the software on your computer that talks to your hardware, including all your drivers, and with linux, all that software is kept together in a single package that is frequently updated. It is very likely that you can solve your problem simply by upgrading your kernel to a more recent version and installing a new wireless driver. Unfortunately, since all the drivers are in one place, the linux kernel is very big and complicated. Therefore, teaching you how to build drivers is a little beyond the scope of this tutorial. What I can do is show you where to get information so you can learn on your own.

First, you'll want to go to http://www.kernel.org/pub/linux/kernel/ and look at the kernels they have there. While you as an LFSer are in a good position to simply grab the most recent bleeding edge kernel source, do understand that if you have an old and stable system it's usually a better idea to do a little homework and grab a version that's as low as possible while still being high enough to have the updated drivers you need. For us, though, and assuming you're reading this in 2012 or 2013, you'll want to click on the 3.0 link and then grab the highest versioned kernel available. Be careful not to grab a patch.

Next, if you untar that (sorry, it takes a while) and go into the package, you can explore all the options available to you by running the command

# make menuconfig

Aside from that, the website http://kerneltrap.org/ has a very helpful community that can help you on the road to being able to resolve your own linux hardware problems and building your own kernels from source.

Task Discussion