Host System Requirements:
Note :Ubuntu is not compliant out of the box, copy-paste the script and run it:
you might need to install some packages which are not present in ubuntu 14.04
bhargav@Inspiron:~$
sudo apt-get install texinfo gawk make sed php gcc g++
Use scripts from documentation to check for packages and libraries
on your host system : sudo blkid -o list
bhargav@Inspiron:~$ sudo ./version-check.sh
script code version-check.sh : Refer documentation for scrip code.
Note : you might need to install few packages showed after running the script :
bhargav@Inspiron:~$ sudo ./
library-check.sh
script code library-check.sh : Refer documentation for script code.
You might get problem while installing mpfr hence just run this command:
sudo apt-get install libmpfr-dev libmpfr-doc libmpfr4 libmpfr4-dbg
Making a partition on disk for lfs using parted application :
Note : If you are not sure how PARTED work then refer to below
link before going forward:
http://www.thegeekstuff.com/2011/09/parted-command-examples/
bhargav-Inspiron:/$ sudo parted
(parted) print free
Now look for space which is free to use and remember the start and end
size to make partition:
Note : Please re-check or make sure before running any command.
Any mistake might lead to losing your data onto disk or HD.
(parted) mkpart
Partition name? []? lfs
File system type? [ext2]? ext4
Start? 238GB
End? 248GB
(parted) print
Model: ATA WDC WD5000LPVX-7 (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/4096B
Partition Table: gpt
Number Start End Size File system Name Flags
1 1049kB 525MB 524MB fat32 EFI system partition boot
2 525MB 567MB 41.9MB fat32 Basic data partition hidden
3 567MB 701MB 134MB Microsoft reserved partition msftres
4 701MB 1488MB 786MB ntfs Basic data partition hidden, diag
5 1488MB 70.1GB 68.6GB ntfs Basic data partition msftdata
6 70.1GB 238GB 168GB ntfs Basic data partition msftdata
11 238GB 248GB 10.5GB lfs
7 248GB 459GB 211GB ntfs Basic data partition msftdata
9 459GB 463GB 4200MB linux-swap(v1)
10 463GB 491GB 27.3GB ext4
8 491GB 500GB 9412MB ntfs Microsoft recovery partition hidden, diag
Format ext2 partition to ext4 partition :
bhargav@Inspiron:~$sudo blkid -o list
//this will show partition blkid
bhargav@Inspiron:~$ sudo
mkfs.ext4 /dev/sda11
We will make a variable link: (OPTIONAL you can use /mnt/lfs in $LFS or viceversa)
bhargav@Inspiron:~$ export LFS=/mnt/lfs
Make directory at /mnt/ name lfs:
bhargav@Inspiron:~$ sudo mkdir -pv /mnt/lfs
Mounting the partition on the location of lfs directory:
bhargav@Inspiron:~$ sudo mount -v -t ext4 /dev/sda11 /mnt/lfs
/dev/sda11 on /mnt/lfs type ext4 (rw)
Make directory inside /mnt/lfs named "sources" :
bhargav@Inspiron:~$ sudo mkdir -v $LFS/sources
mkdir: created directory ‘/mnt/lfs/sources’
Give permission to /mnt/lfs/sources :
bhargav@Inspiron:~$ sudo chmod -v a+wt $LFS/sources
mode of ‘/mnt/lfs/sources’ changed from 0755 (rwxr-xr-x) to 1777 (rwxrwxrwt)
Download all the packages from site :
It includes total 77 files including patches
ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/lfs-packages-7.7-systemd.tar
bhargav@Inspiron:/$
groupadd lfs
bhargav@Inspiron:/$ sudo useradd -s /bin/bash -g lfs -m -k /dev/null lfs
bhargav@Inspiron:/$
sudo adduser lfs sudo
bhargav@Inspiron:/$
sudo passwd lfs
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
lfs@Inspiron:/mnt/lfs$ sudo mkdir -v $LFS/tools
mkdir: created directory '/mnt/lfs/tools'
lfs@bhargav-Inspiron-3443:/mnt/lfs$ sudo ln -sv $LFS/tools /
'/tools' -> '/mnt/lfs/tools'
lfs@Inspiron
:/mnt/lfs$
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/tools
changed ownership of ‘/mnt/lfs/tools’ from root to lfs
bhargav@Inspiron:/$ sudo chown -v lfs /mnt/lfs/sources
changed ownership of ‘/mnt/lfs/sources’ from root to lfs
bhargav@Inspiron:/$
bhargav@Inspiron:/$ su - lfs
Password:
Setting Up the Environment :
lfs@Inspiron:
~$ ~/.bash_profile << "EOF"
> exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
> EOF
-su: /home/lfs/.bash_profile: No such file or directory
lfs@Inspiron:
~$ cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
lfs@Inspiron:
~$ cat > ~/.bashrc << "EOF"
> set +h
> umask 022
> LFS=/mnt/lfs
> LC_ALL=POSIX
> LFS_TGT=$(uname -m)-lfs-linux-gnu
> PATH=/tools/bin:/bin:/usr/bin
> export LFS LC_ALL LFS_TGT PATH
> EOF
lfs@Inspiron:
~$ source ~/.bash_profile
IMP change it back to dash to run in normal enviroment
To change symblic link of sh to bash
sudo ln -sf bash /bin/sh
Change it to dash when it is done
sudo ln -sf dash /bin/sh
Build Binutils package :
cd $LFS/sources
tar xf binutils-2.22.tar.bz2
cd binutils-2.22
mkdir -v ../binutils-build
cd ../binutils-build
../binutils-2.22/configure \
--target=$LFS_TGT --prefix=/tools \
--disable-nls --disable-werror
make
case $(uname -m) in
x86_64) mkdir -v /tools/lib && ln -sv lib /tools/lib64 ;;
esac
make install
cd $LFS/sources
rm -rf binutils-build binutils-2.22
Buils GCC package:
cd $LFS/sources
tar xf gcc-4.6.2.tar.bz2
cd gcc-4.6.2
tar -jxf ../mpfr-3.1.0.tar.bz2
mv -v mpfr-3.1.0 mpfr
tar -Jxf ../gmp-5.0.4.tar.xz
mv -v gmp-5.0.4 gmp
tar -zxf ../mpc-0.9.tar.gz
mv -v mpc-0.9 mpc
The following command
ill change the location of GCC's default dynamic linker to use the one installed in
for file in \
$(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
cp -uv $file{,.orig}
sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
-e 's@/usr@/tools@g' $file.orig > $file
echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
touch $file.orig
done
then making a gcc-build directory:
mkdir -v ../gcc-build
cd ../gcc-build
Installing gcc by running this command :
../gcc-4.9.2/configure \
--target=$LFS_TGT \
--prefix=/tools \
--with-sysroot=$LFS \
--with-newlib \
--without-headers \
--with-local-prefix=/tools \
--with-native-system-header-dir=/tools/include \
--disable-nls \
--disable-shared \
--disable-multilib \
--disable-decimal-float \
--disable-threads \
--disable-libatomic \
--disable-libgomp \
--disable-libitm \
--disable-libquadmath \
--disable-libsanitizer \
--disable-libssp \
--disable-libvtv \
--disable-libcilkrts \
--disable-libstdc++-v3 \
--enable-languages=c,c++
make
make install
cd $LFS/sources
rm -rf gcc-build gcc-4.9.2
Installation of Linux API Headers:
cd $LFS/sources
tar -xf linux-3.19.tar.xz
cd linux-3.19
make mrproper
make INSTALL_HDR_PATH=dest headers_install
cp -rv dest/include/* /tools/include
cd $LFS/sources/
sudo rm -rf linux-3.19
Installation of Glibc-2.21 :
tar xf glibc-2.21.tar.xz
cd glibc-2.21
sudo mkdir -v ../glibc-build
cd ../glibc-build/
../glibc-2.21/configure \
--prefix=/tools \
--host=$LFS_TGT \
--build=$(../glibc-2.21/scripts/config.guess) \
--disable-profile \
--enable-kernel=2.6.32 \
--with-headers=/tools/include \
libc_cv_forced_unwind=yes \
libc_cv_ctors_header=yes \
libc_cv_c_cleanup=yes
make
make install
At this point, it is imperative to stop and ensure that the
basic functions (compiling and linking) of the new
toolchain are working as expected. To perform a sanity
check, run the following commands:
echo 'main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools'
If everything is working correctly, there should be no
errors, and the output of the last command will be of the form:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
rm -v dummy.c a.out
Binutils-2.22 - Pass 2
tar xf binutils-2.25.tar.bz2
cd binutils-2.25
mkdir -v ../binutils-build
cd ../binutils-build
CC=$LFS_TGT-gcc \
AR=$LFS_TGT-ar \
RANLIB=$LFS_TGT-ranlib \
../binutils-2.25/configure \
--prefix=/tools \
--disable-nls \
--disable-werror \
--with-lib-path=/tools/lib \
--with-sysroot
make
make install
Now prepare the linker for the “Re-adjusting” phase in the next chapter:
make -C ld clean
make -C ld LIB_PATH=/usr/lib:/lib
cp -v ld/ld-new /tools/bin
5.10.1. Installation of GCC
tar xf gcc-4.9.2.tar.bz2
cd gcc-4.9.2
cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
Once again, change the location of GCC's default dynamic
linker to use the one installed in /tools
.
for file in \
$(find gcc/config -name linux64.h -o -name linux.h -o -name sysv4.h)
do
cp -uv $file{,.orig}
sed -e 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' \
-e 's@/usr@/tools@g' $file.orig > $file
echo '
#undef STANDARD_STARTFILE_PREFIX_1
#undef STANDARD_STARTFILE_PREFIX_2
#define STANDARD_STARTFILE_PREFIX_1 "/tools/lib/"
#define STANDARD_STARTFILE_PREFIX_2 ""' >> $file
touch $file.orig
done
As in the first build of GCC it requires the GMP, MPFR and
MPC packages. Unpack the tarballs and move them into the
required directory names:
tar -xf ../mpfr-3.1.2.tar.xz
mv -v mpfr-3.1.2 mpfr
tar -xf ../gmp-6.0.0a.tar.xz
mv -v gmp-6.0.0 gmp
tar -xf ../mpc-1.0.2.tar.gz
mv -v mpc-1.0.2 mpc
Before starting to build GCC, remember to unset any
environment variables that override the default optimization
flags.
Now prepare GCC for compilation:
CC=$LFS_TGT-gcc \
CXX=$LFS_TGT-g++ \
AR=$LFS_TGT-ar \
RANLIB=$LFS_TGT-ranlib \
../gcc-4.9.2/configure \
--prefix=/tools \
--with-local-prefix=/tools \
--with-native-system-header-dir=/tools/include \
--enable-languages=c,c++ \
--disable-libstdcxx-pch \
--disable-multilib \
--disable-bootstrap \
--disable-libgomp
Compile the package:
make
Install the package:
make install
As a finishing touch, create a symlink. Many programs and
scripts run cc instead of gcc,which is used to keep programs generic and therefore usable
on all kinds of UNIX systems where the GNU C compiler is not always installed. Running cc leaves the system
administrator free to decide which C compiler to install:
echo 'main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools'
If everything is working correctly, there should be no errors,
and the output of the last command will be of the form:
[Requesting program interpreter: /tools/lib/ld-linux.so.2]
Once all is well, clean up the test files:
rm -v dummy.c a.out
Once all is well, clean up the test files:
HERE YOU HAVE COMPLETED THE TOUGH PART OF LFS.
5.11. Tcl8.6.3 Installation :
tar xf tcl8.6.3-src.tar.gz
cd tcl8.6.3/unix
Prepare Tcl for compilation:
cd tcl8.6.3/unix
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
Make the installed library writable so debugging symbols can be removed later:
chmod -v u+w /tools/lib/libtcl8.6.so
Install Tcl's headers. The next package, Expect, requires them to build.
make install-private-headers
Now make a necessary symbolic link:
ln -sv tclsh8.6 /tools/bin/tclsh
|
5.12. Expect-5.45 Installation :
First, force Expect's configure script to use /bin/stty instead of a /usr/local/bin/stty it may find on the host
system. This will ensure that our test suite tools remain
sane for the final builds of our toolchain:
tar xf expect5.45.tar.gz
cd expect5.45
cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure
Now prepare Expect for compilation:
./configure --prefix=/tools \
--with-tcl=/tools/lib \
--with-tclinclude=/tools/include
Build the package:
make
5.13. DejaGNU package Installation :
tar xf dejagnu-1.5.2.tar.gz
cd dejagnu-1.5.2/
./configure --prefix=/tools
make install
5.14. Check-0.9.14 package Installation :
Prepare Check for complilation:
PKG_CONFIG= ./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.15. Ncurses-5.9 package Installation :
tar xf ncurses-5.9.tar.gz
cd ncurses-5.9
Prepare Ncurses for complilation:
./configure --prefix=/tools \
--with-shared \
--without-debug \
--without-ada \
--enable-widec \
--enable-overwrite
Build the package :
make
Install the package:
make install
5.16. Bash-4.3.30 package Installation :
tar xf bash-4.3.30.tar.gz
cd bash-4.3.30
Prepare Bash for compilation:
./configure --prefix=/tools --without-bash-malloc
Build the package:
make
Install the package:
make install
Make a link for the programs that use sh for a shell:
ln -sv bash /tools/bin/sh
5.17. Bzip2-1.0.6 package Installation :
tar xf bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
The Bzip2 package does not contain a configure script. Compile and test it with:
make
Install the package:
make PREFIX=/tools install
5.18. Coreutils-8.23 package Installation :
tar xf coreutils-8.23.tar.gz
cd coreutils-8.23
Prepare Coreutils for compilation:
./configure --prefix=/tools --enable-install-program=hostname
Build the package:
make
Install the package:
make install
5.19. Diffutils-3.3 package Installation :
tar xf diffutils-3.3.tar.gz
cd diffutils-3.3
Prepare Diffutils for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.20. File-5.22 package Installation :
tar xf file-5.22.tar.gz
cd file-5.22
Prepare File for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.21. Findutils-4.4.2 package Installation :
tar xf findutils-4.4.2.tar.gz
cd findutils-4.4.2
Prepare Findutils for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.22. Gawk-4.1.1 package Installation :
tar xf Gawk-4.1.1.tar.gz
cd gawk-1.1.2
Prepare Gawk for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.23. Gettext-0.19.4 package Installation :
tar xf gettext-0.19.4.tar.gz
cd gettext-0.19.4
Prepare Gettext for compilation:
cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared
Compile the package:
make -C gnulib-lib
make -C intl pluralx.c
make -C src msgfmt
make -C src msgmerge
make -C src xgettext
Install the msgfmt, msgmerge and xgettext programs:
cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin
5.24. Grep-2.21 package Installation :
tar xf grep-2.21.tar.gz
cd grep-2.21
Prepare Grep for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.25. Gzip-1.6 package Installation :
tar xf gzip-1.6.tar.gz
cd gzip-1.6
Prepare Gzip for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.26. M4-1.4.17 package Installation :
tar xf m4-1.4.17.tar.gz
cd m4-1.4.17
Prepare M4 for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.27. Make-4.1 package Installation :
tar xf make-4.1.tar.gz
cd make-4.1
Prepare Make for compilation:
./configure --prefix=/tools --without-guile
Build the package:
make
Install the package:
make install
5.28. Patch-2.7.4 package Installation :
tar xf patch-2.7.4.tar.gz
cd patch-2.7.4
Prepare Make for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.29. Perl-5.20.2 package Installation :
tar xf perl-5.20.2.tar.gz
cd perl-5.20.2
Prepare perl for compilation:
sh Configure -des -Dprefix=/tools -Dlibs=-lm
Build the package:
make
Only a few of the utilities and libraries need to be
installed at this time:
|
|
cp -v perl cpan/podlators/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.20.2
cp -Rv lib/* /tools/lib/perl5/5.20.2
5.30.
Sed-4.2.2 package Installation :
tar xf sed-4.2.2.tar.gz
cd sed-4.2.2
Prepare Sed for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.31.
Tar-1.28 package Installation :
tar xf tar-1.28.tar.xz
cd tar-1.28
Prepare Tar for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.32.
Texinfo-5.2 package Installation :
tar xf texinfo-5.2.tar.xz
cd texinfo-5.2
Prepare
Texinfo
for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install
5.33.
Util-linux-2.26 package Installation :
tar xf util-linux-2.26.tar.xz
cdutil-linux-2.26
Prepare Util-linux for compilation:
./configure --prefix=/tools \
--without-python \
--disable-makeinstall-chown \
--without-systemdsystemunitdir \
PKG_CONFIG=""
Build the package:
make
Install the package:
make install
5.34. Xz-5.2.0
package Installation :
tar xf xz-5.2.0.tar.xz
cd xz-5.2.0
Prepare
Xz
for compilation:
./configure --prefix=/tools
Build the package:
make
Install the package:
make install