From the book, "[i]f the intended user is not a programmer and does not plan to do any debugging on the system software". Hmm. Cough, cough. OOOOOOH FUCK, YES THAT'S ME.
To make sure that we are clear to strip the files we need to exit the chroot:
logout
Now, when I wanted to exit the chroot environment to either mount the sources directory or download nano, I just automatically ran 'exit'. Apparently, however, the flavour of the day is 'logout'... Followed straight away by chrooting back in:
sudo chroot "/media/lfs" /tools/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ ' PATH=/bin:/usr/bin:/sbin:/usr/sbin CORES_TO_USE=-j2 /tools/bin/bash --login
What we omit this time around is the [/tools/bin] bit of the PATH, because of course it is no longer needed, and the [+h] option to the [bash] shell option. For some reason though, we are still running the Toolchain [bash] instead of the newly built one.
/tools/bin/find /{,usr/}{bin,lib,sbin} -type f -exec /tools/bin/strip --strip-debug '{}' ';'
This command uses the Toolchain [find] command to apply the command [strip] with option [strip-debug] to every [f] regular file type in the directories specified.
If, for any reason we need to exit the Chroot, then instead of running the command set out in Part 1, we need to run the following command instead:
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
The next thing we need to do is install the LFS scripts that the SysVInit programs are going to use to get everything up and running on boot. First change into the correct directory, if not already there:
cd /tmp tar -xjvf /sources/lfs-bootscripts-20100124.tar.bz2 cd lfs-bootscripts-20100124 make install
This installs a lot of scripts, perhaps the most important is the 'rc' script that we saw referenced as a command in the SysVInit configuration file. What you basically end up with is a directory in /etc called rc.d. It is common in Linux from configuration files to get so unwieldy that they effectively end up as directories of individual configuration files. When that happens you tend to append '.d' to the end of the original filename to signify that it is now a directory.
That directory contains a further directory called init.d, in which there are the scripts we have just installed which run the various boot commands. The rc.d directory also contains other folders rc{0-6}.d which contain symbolic links to the scripts in init.d. The way these scripts are named are important. They start with an 'S' if they start a script and 'K' of they stop a script. That is followed by a number which denotes the order the scripts in the folder are run.
cd .. rm -rvf lfs-bootscripts-20100124
Next we setup the clock configuration file. The UTC=1 means that we are one hour ahead of UTC. You can find the appropriate number for you by running:
hwclock --localtime --show
If that time is an hour behind your watch then UTC=1, as it does for me. If it is 7 hours ahead then presumably your number is UTC=-7. Check out a LFS hint explaining all this here.
cat > /etc/sysconfig/clock << "EOF" # Begin /etc/sysconfig/clock UTC=1 # Set this to any options you might need to give to hwclock, # such as machine hardware clock type for Alphas. CLOCKPARAMS= # End /etc/sysconfig/clock EOF
The next file configures various settings for the console. I am selecting only the [uk] [KEYMAP]. I am keeping the [FONT] command in, but because I have no idea what it does I am commenting [#] it out.
cat > /etc/sysconfig/console << "EOF" # Begin /etc/sysconfig/console KEYMAP="uk" #FONT="lat1-16 -m 8859-1" # End /etc/sysconfig/console EOF
Next the "The inputrc file handles keyboard mapping for specific situations." Which is pretty damn vague. I think it sets up how the text input to the command line is actually handled.
cat > /etc/inputrc << "EOF" # Begin /etc/inputrc # Modified by Chris Lynn# Allow the command prompt to wrap to the next line set horizontal-scroll-mode Off # Enable 8bit input set meta-flag On set input-meta On # Turns off 8th bit stripping set convert-meta Off # Keep the 8th bit for display set output-meta On # none, visible or audible set bell-style none # All of the following map the escape sequence of the value # contained in the 1st argument to the readline specific functions "\eOd": backward-word "\eOc": forward-word # for linux console "\e[1~": beginning-of-line "\e[4~": end-of-line "\e[5~": beginning-of-history "\e[6~": end-of-history "\e[3~": delete-char "\e[2~": quoted-insert # for xterm "\eOH": beginning-of-line "\eOF": end-of-line # for Konsole "\e[H": beginning-of-line "\e[F": end-of-line # End /etc/inputrc EOF
We are now going to skip ahead to the BLFS book, and will install their [/etc/profile] scripts. Instead of having a very basic profile file, that file will scan the [/etc/profile.d] directory and will run all scripts in it.
cat > /etc/profile << "EOF" # Begin /etc/profile # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # modifications by Dagmar d'Surreal <rivyqntzne@pbzpnfg.arg> # System wide environment variables and startup programs. # System wide aliases and functions should go in /etc/bashrc. Personal # environment variables and startup programs should go into # ~/.bash_profile. Personal aliases and functions should go into # ~/.bashrc. # Functions to help us manage paths. Second argument is the name of the # path variable to be modified (default: PATH) pathremove () { local IFS=':' local NEWPATH local DIR local PATHVARIABLE=${2:-PATH} for DIR in ${!PATHVARIABLE} ; do if [ "$DIR" != "$1" ] ; then NEWPATH=${NEWPATH:+$NEWPATH:}$DIR fi done export $PATHVARIABLE="$NEWPATH" } pathprepend () { pathremove $1 $2 local PATHVARIABLE=${2:-PATH} export $PATHVARIABLE="$1${!PATHVARIABLE:+:${!PATHVARIABLE}}" } pathappend () { pathremove $1 $2 local PATHVARIABLE=${2:-PATH} export $PATHVARIABLE="${!PATHVARIABLE:+${!PATHVARIABLE}:}$1" } # Set the initial path export PATH=/bin:/usr/bin if [ $EUID -eq 0 ] ; then pathappend /sbin:/usr/sbin unset HISTFILE fi # Setup some environment variables. export HISTSIZE=1000 export HISTIGNORE="&:[bf]g:exit" # Setup a red prompt for root and a green one for users. NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ $EUID == 0 ]] ; then PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" else PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi for script in /etc/profile.d/*.sh ; do if [ -r $script ] ; then . $script fi done # Now to clean up unset pathremove pathprepend pathappend # End /etc/profile EOF
Now we make a directory to stick all the little scripts in:
install --directory --mode=0755 --owner=root --group=root /etc/profile.d
And now for the little scripts themselves. The first configures coloured directories when we are [ls]ing around the file system.
cat > /etc/profile.d/dircolors.sh << "EOF" # Setup for /bin/ls to support color, the alias is in /etc/bashrc. if [ -f "/etc/dircolors" ] ; then eval $(dircolors -b /etc/dircolors) if [ -f "$HOME/.dircolors" ] ; then eval $(dircolors -b $HOME/.dircolors) fi fi alias ls='ls --color=auto' EOF
This next one sets up the paths. Note that at the end of it the path [.] for our current folder is commented out. Uncommenting makes the current directory part of the path. This is described as a security risk though, so we'll leave it commented out just now.
cat > /etc/profile.d/extrapaths.sh << "EOF" if [ -d /usr/local/lib/pkgconfig ] ; then pathappend /usr/local/lib/pkgconfig PKG_CONFIG_PATH fi if [ -d /usr/local/bin ]; then pathprepend /usr/local/bin fi if [ -d /usr/local/sbin -a $EUID -eq 0 ]; then pathprepend /usr/local/sbin fi if [ -d ~/bin ]; then pathprepend ~/bin fi #if [ $EUID -gt 99 ]; then # pathappend . #fi EOF
Don't really know what this does, don't really care:
cat > /etc/profile.d/readline.sh << "EOF" # Setup the INPUTRC environment variable. if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ] ; then INPUTRC=/etc/inputrc fi export INPUTRC EOF
This next one affects what permissions bullshit is set on new files and folders created.
cat > /etc/profile.d/umask.sh << "EOF" # By default we want the umask to get set. if [ "$(id -gn)" = "$(id -un)" -a $EUID -gt 99 ] ; then umask 002 else umask 022 fi EOF
We also need to add the X folders to the path - if it is installed.
cat > /etc/profile.d/X.sh << "EOF" if [ -x /usr/X11R6/bin/X ]; then pathappend /usr/X11R6/bin fi if [ -d /usr/X11R6/lib/pkgconfig ] ; then pathappend /usr/X11R6/lib/pkgconfig PKG_CONFIG_PATH fi EOF
And, some localisation crap:
cat > /etc/profile.d/i18n.sh << "EOF" # Set up i18n variables export LANG=en_GB.ISO-8859-1 EOF
We also want to setup our prompt:
cat > /etc/bashrc << "EOF" # Begin /etc/bashrc # Written for Beyond Linux From Scratch # by James Robertson <jameswrobertson@earthlink.net> # updated by Bruce Dubbs <bdubbs@linuxfromscratch.org> # System wide aliases and functions. # System wide environment variables and startup programs should go into # /etc/profile. Personal environment variables and startup programs # should go into ~/.bash_profile. Personal aliases and functions should # go into ~/.bashrc # Provides a colored /bin/ls command. Used in conjunction with code in # /etc/profile. alias ls='ls --color=auto' # Provides prompt for non-login shells, specifically shells started # in the X environment. [Review the LFS archive thread titled # PS1 Environment Variable for a great case study behind this script # addendum.] NORMAL="\[\e[0m\]" RED="\[\e[1;31m\]" GREEN="\[\e[1;32m\]" if [[ $EUID == 0 ]] ; then PS1="$RED\u [ $NORMAL\w$RED ]# $NORMAL" else PS1="$GREEN\u [ $NORMAL\w$GREEN ]\$ $NORMAL" fi # End /etc/bashrc EOF
We also want to set our variable to use multicores when compiling packages. We may want to add other custom variables in the future, so lets name the file something sensible:
cat > /etc/profile.d/custom_variables.sh << "EOF" # Set up a variable to let us use multicores when compiling CORES_TO_USE=-j2 EOF
Finally we want to generate a file for the directory colours, not sure why.
dircolors -p > /etc/dircolors
We set the hostname by sending the contents of the following file:
echo "HOSTNAME=amiga" > /etc/sysconfig/network
I am not going to be configuring a network card using scripts. Instead I am going to use the dhcpcd program (ah, fuck gotta download that as well now) to grab all the network settings from my router. I still need a hosts file, but we can make it basic:
cat > /etc/hosts << "EOF" # Begin /etc/hosts (no network card version) 127.0.0.1 amiga.localdomain amiga localhost # End /etc/hosts (no network card version) EOF
I am going to replace our earlier resolv.conf with the following entirely commented out version. The actual DNS services will be handled by my router.
cat > /etc/resolv.conf << "EOF" # Begin /etc/resolv.conf #domain#nameserver #nameserver # End /etc/resolv.conf EOF
And that should complete the configuration scripts.
To summarise, now we have changed our chroot command, the list of commands to get into the chroot from a cold boot LiveCD is as follows:
umount -v /media/amiga sudo mkdir /media/lfs sudo mount -v -t ext3 /dev/disk/by-label/amiga /media/lfs sudo mount -v --bind /dev /media/lfs/dev sudo mount -vt devpts devpts /media/lfs/dev/pts sudo mount -vt tmpfs shm /media/lfs/dev/shm sudo mount -vt proc proc /media/lfs/proc sudo mount -vt sysfs sysfs /media/lfs/sys 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
From this point on, you should not use the Ramdisk. We will need to keep some source files around - especially the kernel source. Also we will be downloading more source code directly to the Amiga Key. We therefore now need the /sources/ directory to be persistent. So, from now on do not go into /tmp to make your packages; go to /sources instead. I have therefore NOT included the /tmp --bind command in the above list.
Now, onto matters of boot.
No comments:
Post a Comment