Skip to content

Commit

Permalink
Merge pull request #5 from EvilFreelancer/master
Browse files Browse the repository at this point in the history
Update to LFS 8.2
  • Loading branch information
reinterpretcat committed Sep 6, 2018
2 parents 15bd80d + f9a4a8b commit ece7b0b
Show file tree
Hide file tree
Showing 107 changed files with 1,012 additions and 511 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
toolchain
/.idea/
/toolchain/
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM debian:8

# image info
LABEL description="Automated LFS build"
LABEL version="8.1"
LABEL version="8.2"
LABEL maintainer="ilya.builuk@gmail.com"

# LFS mount point
Expand All @@ -18,7 +18,7 @@ ENV MAKEFLAGS="-j 1"
# 0 use LFS wget file
# 1 use binaries from toolchain folder
# 2 use github release artifacts
ENV FETCH_TOOLCHAIN_MODE=2
ENV FETCH_TOOLCHAIN_MODE=1

# set 1 to run tests; running tests takes much more time
ENV LFS_TEST=0
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@

## Description

This repository contains docker configuration to build bootable iso image with [Linux From Scratch 8.1](http://www.linuxfromscratch.org/lfs/downloads/8.1/LFS-BOOK-8.1.pdf).
This repository contains docker configuration to build bootable iso
image with [Linux From Scratch 8.2](http://www.linuxfromscratch.org/lfs/downloads/8.2/LFS-BOOK-8.2.pdf).

## Why

General idea is to learn Linux by building and running LFS system in isolation from the host system.
General idea is to learn Linux by building and running LFS system in
isolation from the host system.

## Structure

Scripts are organized in the way of following book structure whenever it makes sense. Some deviations are done to make a bootable iso image.
Scripts are organized in the way of following book structure whenever
it makes sense. Some deviations are done to make a bootable iso image.

## Build

Use the following command:

docker rm lfs ; \
docker build --tag lfs . && \
sudo docker run -it --privileged --name lfs lfs && \
docker rm lfs && \
docker build --tag lfs:8.2 . && \
sudo docker run -it --privileged --name lfs lfs:8.2 && \
sudo docker cp lfs:/tmp/lfs.iso .
# Ramdisk you can find here: /tmp/ramdisk.img

Please note, that extended privileges are required by docker container in order to execute some commands (e.g. mount).
Please note, that extended privileges are required by docker container
in order to execute some commands (e.g. mount).

## Usage

Final result is bootable iso image with LFS system which, for example, can be used to load the system inside virtual machine (tested with VirtualBox).
Final result is bootable iso image with LFS system which, for
example, can be used to load the system inside virtual machine (tested
with VirtualBox).

## License

This work is based on instructions from [Linux from Scratch](http://www.linuxfromscratch.org/lfs) project and provided with MIT license.
This work is based on instructions from [Linux from Scratch](http://www.linuxfromscratch.org/lfs)
project and provided with MIT license.
4 changes: 2 additions & 2 deletions scripts/build/6.12-make-file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ echo "Building file.."
echo "Approximate build time: 0.1 SBU"
echo "Required disk space: 16 MB"

# 6.12. File package contains a utility for determining
# the type of a given file or files
# 6.12. The File package contains a utility for determining the
# type of a given file or files.
tar -xf /sources/file-*.tar.gz -C /tmp/ \
&& mv /tmp/file-* /tmp/file \
&& pushd /tmp/file
Expand Down
9 changes: 6 additions & 3 deletions scripts/build/6.13-make-readline.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e
echo "Building readline.."
echo "Approximate build time: less than 0.1 SBU"
echo "Approximate build time: 0.1 SBU"
echo "Required disk space: 15 MB"

# 6.13. Readline package is a set of libraries that offers command-line
Expand All @@ -22,8 +22,11 @@ make SHLIB_LIBS="-L/tools/lib -lncurses" install
mv -v /usr/lib/lib{readline,history}.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libreadline.so) /usr/lib/libreadline.so
ln -sfv ../../lib/$(readlink /usr/lib/libhistory.so ) /usr/lib/libhistory.so
# install the documentation
if [ $LFS_DOCS -eq 1 ]; then install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-7.0; fi

# If desired, install the documentation
if [ $LFS_DOCS -eq 1 ]; then
install -v -m644 doc/*.{ps,pdf,html,dvi} /usr/share/doc/readline-7.0
fi

popd \
&& rm -rf /tmp/readline
6 changes: 3 additions & 3 deletions scripts/build/6.14-make-m4.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
set -e
echo "Building m4.."
echo "Building M4.."
echo "Approximate build time: 0.4 SBU"
echo "Required disk space: 30 MB"
echo "Required disk space: 31 MB"

# 6.14. M4 package contains a macro processor
# 6.14. The M4 package contains a macro processor.
tar -xf /sources/m4-*.tar.xz -C /tmp/ \
&& mv /tmp/m4-* /tmp/m4 \
&& pushd /tmp/m4
Expand Down
18 changes: 10 additions & 8 deletions scripts/build/6.15-make-bc.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
#!/bin/bash
set -e
echo "Building bc.."
echo "Building Bc.."
echo "Approximate build time: 0.1 SBU"
echo "Required disk space: 3.6 MB"
echo "Required disk space: 3.7 MB"

# 6.15. Bc package contains an arbitrary precision numeric processing language
# 6.15. The Bc package contains an arbitrary precision numeric
# processing language.
tar -xf /sources/bc-*.tar.gz -C /tmp/ \
&& mv /tmp/bc-* /tmp/bc \
&& pushd /tmp/bc
# use sed instead of ed
# First, change an internal script to use sed instead of ed:
cat > bc/fix-libmath_h <<"EOF"
#! /bin/bash
sed -e '1 s/^/{"/' \
-e 's/$/",/' \
-e '2,$ s/^/"/' \
-e '$ d' \
sed -e '1 s/^/{"/' \
-e 's/$/",/' \
-e '2,$ s/^/"/' \
-e '$ d' \
-i libmath.h
sed -e '$ s/$/0}/' \
-i libmath.h
EOF
Expand Down
17 changes: 9 additions & 8 deletions scripts/build/6.16-make-binutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@ echo "Required disk space: 4.2 Gb"

# 6.16. Binutils package contains a linker, an assembler, and other tools
# for handling object files
tar -xf /sources/binutils-*.tar.bz2 -C /tmp/ \
tar -xf /sources/binutils-*.tar.xz -C /tmp/ \
&& mv /tmp/binutils-* /tmp/binutils \
&& pushd /tmp/binutils
# verify that the PTYs are working properly inside the chroot environment
expect -c "spawn ls"
mkdir -v build
cd build
../configure --prefix=/usr \
--enable-gold \
--enable-ld=default \
--enable-plugins \
--enable-shared \
--disable-werror \
--with-system-zlib
../configure --prefix=/usr \
--enable-gold \
--enable-ld=default \
--enable-plugins \
--enable-shared \
--disable-werror \
--enable-64-bit-bfd \
--with-system-zlib
make tooldir=/usr
if [ $LFS_TEST -eq 1 ]; then make -k check || true; fi
make tooldir=/usr install
Expand Down
4 changes: 2 additions & 2 deletions scripts/build/6.17-make-gmp.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
set -e
echo "Building gmp.."
echo "Building GMP.."
echo "Approximate build time: 1.2 SBU"
echo "Required disk space: 59 MB"
echo "Required disk space: 60 MB"

# 6.17. GMP package contains math libraries
tar -xf /sources/gmp-*.tar.xz -C /tmp/ \
Expand Down
14 changes: 7 additions & 7 deletions scripts/build/6.18-make-mpfr.sh
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#!/bin/bash
set -e
echo "Building mpfr.."
echo "Approximate build time: 0.8 SBU"
echo "Required disk space: 45 MB"
echo "Building MPFR.."
echo "Approximate build time: 1.0 SBU"
echo "Required disk space: 36 MB"

# 6.18. MPFR package contains functions for multiple precision math
tar -xf /sources/mpfr-*.tar.xz -C /tmp/ \
&& mv /tmp/mpfr-* /tmp/mpfr \
&& pushd /tmp/mpfr

./configure --prefix=/usr \
--disable-static \
--enable-thread-safe \
--docdir=/usr/share/doc/mpfr-3.1.5
./configure --prefix=/usr \
--disable-static \
--enable-thread-safe \
--docdir=/usr/share/doc/mpfr-4.0.1
make
make html
if [ $LFS_TEST -eq 1 ]; then make check; fi
Expand Down
22 changes: 15 additions & 7 deletions scripts/build/6.19-make-mpc.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
#!/bin/bash
set -e
echo "Building mpc.."
echo "Building MPC.."
echo "Approximate build time: 0.3 SBU"
echo "Required disk space: 17 MB"
echo "Required disk space: 21 MB"

# 6.19. MPC package contains a library for the arithmetic of complex
# numbers with arbitrarily high precision and correct rounding of the result
# 6.19. The MPC package contains a library for the arithmetic of
# complex numbers with arbitrarily high precision and correct
# rounding of the result.
tar -xf /sources/mpc-*.tar.gz -C /tmp/ \
&& mv /tmp/mpc-* /tmp/mpc \
&& pushd /tmp/mpc

./configure --prefix=/usr \
--disable-static \
--docdir=/usr/share/doc/mpc-3.1.5
# Prepare MPC for compilation:
./configure --prefix=/usr \
--disable-static \
--docdir=/usr/share/doc/mpc-1.1.0

# Compile the package and generate the HTML documentation:
make
make html

# To test the results, issue:
if [ $LFS_TEST -eq 1 ]; then make check; fi

# Install the package and its documentation:
make install
if [ $LFS_DOCS -eq 1 ]; then make install-html; fi

Expand Down
88 changes: 62 additions & 26 deletions scripts/build/6.20-make-gcc.sh
Original file line number Diff line number Diff line change
@@ -1,64 +1,100 @@
#!/bin/bash
set -e
echo "Building gcc.."
echo "Approximate build time: 82 SBU"
echo "Required disk space: 3.2 GB"
echo "Building GCC.."
echo "Approximate build time: 81 SBU (with tests)"
echo "Required disk space: 3.1 GB"

# 6.20. GCC package contains the GNU compiler collection, which
# includes the C and C++ compilers
tar -xf /sources/gcc-*.tar.xz -C /tmp/ \
&& mv /tmp/gcc-* /tmp/gcc \
&& pushd /tmp/gcc
# change the default directory name for 64-bit libraries to “lib”

# If building on x86_64, change the default directory name for
# 64-bit libraries to “lib”:
case $(uname -m) in
x86_64)
sed -e '/m64=/s/lib64/lib/' -i.orig gcc/config/i386/t-linux64
sed -e '/m64=/s/lib64/lib/' \
-i.orig gcc/config/i386/t-linux64
;;
esac
# remove the symlink created earlier as the final gcc includes will be installed here

# Remove the symlink created earlier as the final gcc includes will
# be installed here
rm -f /usr/lib/gcc
# create build directory
mkdir -v build && cd build

# The GCC documentation recommends building GCC in a dedicated
# build directory:
mkdir -v build
cd build

# prepare for compilation
SED=sed \
../configure --prefix=/usr \
--enable-languages=c,c++ \
--disable-multilib \
--disable-bootstrap \
--with-system-zlib
# compile package
SED=sed \
../configure --prefix=/usr \
--enable-languages=c,c++ \
--disable-multilib \
--disable-bootstrap \
--with-system-zlib

# Compile the package:
make
# increase the stack size prior to running the tests

# One set of tests in the GCC test suite is known to exhaust the
# stack, so increase the stack size prior to running the tests:
ulimit -s 32768
# test the results, but do not stop at errors

# Test the results, but do not stop at errors:
if [ $LFS_TEST -eq 1 ]; then
make -k check || true
# check results (manual)
# To receive a summary of the test suite results, run:
../contrib/test_summary | grep -A7 Summ
fi
# install

# Install the package:
make install
# make symlinks

# Create a symlink required by the FHS for "historical" reasons.
ln -sv ../usr/bin/cpp /lib

# Many packages use the name cc to call the C compiler.
# To satisfy those packages, create a symlink:
ln -sv gcc /usr/bin/cc
# add a compatibility symlink to enable building programs with
# Link Time Optimization (LTO)

# Add a compatibility symlink to enable building programs with
# Link Time Optimization (LTO):
install -v -dm755 /usr/lib/bfd-plugins
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/7.2.0/liblto_plugin.so \
ln -sfv ../../libexec/gcc/$(gcc -dumpmachine)/7.3.0/liblto_plugin.so \
/usr/lib/bfd-plugins/
# perform sanity checks (as above)

# Now that our final toolchain is in place, it is important to again
# ensure that compiling and linking will work as expected. We do this
# by performing the same sanity checks as we did earlier in the chapter:
echo 'int main(){}' > dummy.c
cc dummy.c -v -Wl,--verbose &> dummy.log
readelf -l a.out | grep ': /lib'

# Now make sure that we're setup to use the correct start files
grep -o '/usr/lib.*/crt[1in].*succeeded' dummy.log

# Verify that the compiler is searching for the correct header files:
grep -B4 '^ /usr/include' dummy.log

# Next, verify that the new linker is being used with the correct search paths:
grep 'SEARCH.*/usr/lib' dummy.log |sed 's|; |\n|g'

# Next make sure that we're using the correct libc:
grep "/lib.*/libc.so.6 " dummy.log

# Lastly, make sure GCC is using the correct dynamic linker:
grep found dummy.log
# cleanup

# Once everything is working correctly, clean up the test files:
rm -v dummy.c a.out dummy.log
# move a misplaced file

# Finally, move a misplaced file:
mkdir -pv /usr/share/gdb/auto-load/usr/lib
mv -v /usr/lib/*gdb.py /usr/share/gdb/auto-load/usr/lib

# Cleanup
popd \
&& rm -rf /tmp/gcc
Loading

0 comments on commit ece7b0b

Please sign in to comment.