[lfs-support] Prepare for Chapter 6

Paul Rogers paulgrogers at fastmail.fm
Tue Nov 24 14:08:44 PST 2015


> Now that I am about to start Chapter 6 I plan on putting the mount
> commands in sections 6.2.2 and 6.2.3 in the .bash_profile for root on
> my host system.

I recommend Willie's suggestion below.

>
> Since, afaik, the chroot command does not survive a reboot, I also
> plan on putting the chroot command in section 6.4 in the same
> .bash_profile file.

Correct.  All chroot does is what it says: changes the root directory
from which files are looked up in the running system.  It does not
change any configuration.

>
> >
>
> Not sure if you should put those in a bash_profile, I would write them
> in a file or script so you can run it on demand when you need it. But
> you covered most of the important things, the PATH variable and the
> chroot command.
>
> Don't forget to mount the virtual filesystems again like /mnt/lfs/dev
> and /mnt/lfs/proc etc before entering chroot. Also set CFLAGS and
> makeflags again if you were using those.

Here's what I have.  It's patterened on the script template I use
for building each package in Ch6, so it's a bit more elaborate
than needs be here.  Note, depending on how I expect things to go, I
may choose to run "ch6-00 all", or "ch6-00 setup; ch6-00 build; ^D;
ch6-00 build; ^D; (repeat); ch6-00 finish"

[ 14:07 scripts]# cat ch6-00
#!/bin/bash -e
function describe () {
# Describe this package, and/or how it's built, however you want.

if [ x$1 = "xshort" -o x$1 = "xbrief" ]; then
  echo " Enter the chroot environment to build Stage 2"
else
  cat <<"EOF"
In order to build a clean set of Stage 2 programs we need to isolate
ourselves from the host environment.  This script must be run before
each "build session" to setup the proper, isolated environment so we can 
compile the Stage 2 programs without "contaminating" them with anything 
from the host's environment.  So run this script to enter the "clean 
room", build as much as you want, then "logout" (^D).  Later you can 
start another session by running this script again, pick up building 
where you left off, build some more, repeating the process until all of 
Stage 2 is built.  Then there will be another similar, but slightly 
different script to continue from there.
EOF
fi

}

function setup () {

# Normally these things wouldn't be in setup, but since ch6-00 isn't
# used in cloning POD, it's safe & logical to do it here.

# Prepare & enter the build environment for a session
if [ ! -d $LFS/proc ]; then
 # Prepare first entry
 mkdir -p $LFS/{proc,sys,dev} &&
 mknod -m 600 $LFS/dev/console c 5 1 &&
 mknod -m 666 $LFS/dev/null c 1 3 
fi
# Mount $LFS/dev, bind to host's /dev
mount -v --bind /dev $LFS/dev &&
# Mount "virtual" file systems
mount -vt proc proc $LFS/proc &&
mount -vt sysfs sysfs $LFS/sys &&
mount -vt tmpfs none $LFS/dev/shm &&
mount -vt devpts -o gid=4,mode=620 devpts $LFS/dev/pts 
}

function build () {

# enter the chroot environment, keeping the default CPU architecture
  # The FHS has been built, it can take care of itself
  chroot "$LFS" /tools/bin/env -i HOME=/root TERM="$TERM" PS1='\u:\w\$ '
  \
  PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
  /tools/bin/bash --login +h 
}

function finish () {

# wait for logout, then unmount "virtual" filesystems
umount $LFS/dev/shm || :        # don't stop (-e) in case of errors
umount $LFS/dev/pts || :        # there shouldn't be any  ;-)
umount $LFS/dev || :
umount $LFS/sys || :
umount $LFS/proc || :
}

function remove () {

:                               # null functions are disallowed
}

case "$1" in

# The correct way to replace this package is to run the "remove"
# function on the installed package, and have pio remove the as-builts. 
# Then you can build a replacement.  When it comes to restoring a
# damaged package, sometimes you can just have pio restore the files,
# when nothing done in the setup or finish functions needs to be
# changed.  However, note carefully: the backups made by pio in the
# build function are of the generic as-built package files.  The
# customizations done by the finish function are not saved in those
# backups.  They're not saved anywhere!  They may have to be redone.

        describe)
                # short or brief produces a one-liner, anything else
                # produces a longer description.
                describe $2
                ;;
        setup)
                setup
                ;;
        build)
                build
                ;;
        finish)
                finish
                ;;
        all)
                setup
                build
                finish
                ;;
        remove)
                remove
                ;;

        *)
                echo "Usage: $0
                {describe|setup|build|finish|all|remove}"
                exit 1
                ;;
esac
-- 
Paul Rogers
paulgrogers at fastmail.fm
Rogers' Second Law: "Everything you do communicates."
(I do not personally endorse any additions after this line. TANSTAAFL :-)

  	

-- 
http://www.fastmail.com - The professional email service



More information about the lfs-support mailing list