- - - - - As of February 1st 2014 this blog is no longer updated - - - - -
LFS 7.1 on Ubuntu 12.04
Posted 07-21-2012 at 11:33 AM by druuna
Updated 01-31-2014 at 03:23 AM by druuna (Updated to current situation.)
Updated 01-31-2014 at 03:23 AM by druuna (Updated to current situation.)
I noticed that a lot of people try to build LFS using Ubuntu as host and are struggling, this article describes how to make Ubuntu compliant, create the partition and lfs user and set up the toolchain (basically chapters 1 to 5.9).
# -------------------------------------------------------------------------- #
# General information
# -------------------------------------------------------------------------- #
Steps below are done on a freshly installed ubuntu 12.04 running in a virtual machine. LFS 7.1 stable version is being installed.
Partition layout:
/dev/sda1 -> swap
/dev/sda2 -> /
/dev/sda3 -> empty partition dedicated for LFS
# -------------------------------------------------------------------------- #
# Preparing Ubuntu
# -------------------------------------------------------------------------- #
1 - Enable full root access:
Open a terminal
2 - Check root access:
Stay logged in as root!
3 - Host System Requirements: Ubuntu is not compliant out of the box, copy-paste the script and run it:
As shown in the above output the following needs attention:
/bin/sh -> /bin/dash
version-check.sh: line 8: bison: command not found
yacc not found
version-check.sh: line 27: m4: command not found
version-check.sh: line 17: gawk: command not found
/usr/bin/awk -> /usr/bin/mawk
version-check.sh: line 29: patch: command not found
version-check.sh: line 33: makeinfo: command not found
Texinfo:
- The kernel used by Ubuntu is newer then mentioned in the LFS book, this isn't a problem,
- EGLIBC isn't a problem either.
# -------------------------------------------------------------------------- #
# LFS - First steps
# -------------------------------------------------------------------------- #
Reminder: These steps are done as root.
- 2.3. Creating a File System on the Partition
no swap, use the swap space already present for Ubuntu (/dev/sda1)
- 2.4. Mounting the New Partition
(a new window might be opened by Ubuntu after the mount command, close it)
no need to activate swap
- 3.1. Introduction / packages and patches
If the md5sum command spits out errors about missing file(s); Check the LFS book for alternative download locations or check here ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/
man-pages-3.35.tar.gz and zlib-1.2.6.tar.bz2 where mentioned as missing when I ran the above commands:
All packages and patches are now downloaded and placed in $LFS/sources.
# -------------------------------------------------------------------------- #
# The lfs user
# -------------------------------------------------------------------------- #
- 4.1. About $LFS
- 4.3. Adding the LFS User
From now on you work as user lfs!
- 4.4. Setting Up the Environment
# -------------------------------------------------------------------------- #
# LFS - Building the toolchain
# -------------------------------------------------------------------------- #
- Chapter 5. Constructing a Temporary System
Do not use the make -j x flag when building: binutils, gcc and glibc!
Safe yourself the time and do not run the checks/tests in chapter 5 (read 4.6. About the Test Suites).
- 5.4. Binutils-2.22 - Pass 1
- 5.5. GCC-4.6.2 - Pass 1
- 5.6. Linux-3.2.6 API Headers
- 5.7. Glibc-2.14.1
- 5.8. Adjusting the Toolchain
- 5.9. Binutils-2.22 - Pass 2
- 5.10. GCC-4.6.2 - Pass 2
The hard part is now done, follow the rest of the LFS book to finish building an LFS system.
Warning: The latest stable LFS version is not 7.1.
The information below can be used as a reference for newer LFS versions. Do keep in mind that steps/actions are probably (slightly?) different in newer versions!
The information below can be used as a reference for newer LFS versions. Do keep in mind that steps/actions are probably (slightly?) different in newer versions!
# -------------------------------------------------------------------------- #
# General information
# -------------------------------------------------------------------------- #
Steps below are done on a freshly installed ubuntu 12.04 running in a virtual machine. LFS 7.1 stable version is being installed.
Code:
druuna@ubuntu-vm:~$ uname -a Linux ubuntu-vm 3.2.0-23-generic #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
/dev/sda1 -> swap
/dev/sda2 -> /
/dev/sda3 -> empty partition dedicated for LFS
Code:
sudo fdisk -l /dev/sda Disk /dev/sda: 17.2 GB, 17179869184 bytes . . Device Boot Start End Blocks Id System /dev/sda1 2048 6047743 3022848 82 Linux swap / Solaris /dev/sda2 * 6047744 22048767 8000512 83 Linux /dev/sda3 22048768 33552383 5751808 83 Linux
# Preparing Ubuntu
# -------------------------------------------------------------------------- #
1 - Enable full root access:
Open a terminal
Code:
druuna@ubuntu-vm:~$ sudo passwd root [sudo] password for druuna: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
Code:
druuna@ubuntu-vm:~$ su - Password: root@ubuntu-vm:~#
3 - Host System Requirements: Ubuntu is not compliant out of the box, copy-paste the script and run it:
Code:
root@ubuntu-vm:~# bash version-check.sh bash, version 4.2.24(1)-release /bin/sh -> /bin/dash Binutils: (GNU Binutils for Ubuntu) 2.22 version-check.sh: line 8: bison: command not found yacc not found bzip2, Version 1.0.6, 6-Sept-2010. Coreutils: 8.13 diff (GNU diffutils) 3.2 find (GNU findutils) 4.4.2 version-check.sh: line 17: gawk: command not found /usr/bin/awk -> /usr/bin/mawk gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 (Ubuntu EGLIBC 2.15-0ubuntu10) 2.15 grep (GNU grep) 2.10 gzip 1.4 Linux version 3.2.0-23-generic (buildd@crested) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu4) ) #36-Ubuntu SMP Tue Apr 10 20:39:51 UTC 2012 version-check.sh: line 27: m4: command not found GNU Make 3.81 version-check.sh: line 29: patch: command not found Perl version='5.14.2'; GNU sed version 4.2.1 tar (GNU tar) 1.26 version-check.sh: line 33: makeinfo: command not found Texinfo: xz (XZ Utils) 5.1.0alpha gcc compilation OK
/bin/sh -> /bin/dash
Code:
root@ubuntu-vm:~# rm /bin/sh root@ubuntu-vm:~# ln -s /bin/bash /bin/sh
yacc not found
version-check.sh: line 27: m4: command not found
Code:
root@ubuntu-vm:~# apt-get install bison
/usr/bin/awk -> /usr/bin/mawk
Code:
root@ubuntu-vm:~# apt-get install gawk
Code:
root@ubuntu-vm:~# apt-get install patch
Texinfo:
Code:
root@ubuntu-vm:~# apt-get install texinfo
- EGLIBC isn't a problem either.
# -------------------------------------------------------------------------- #
# LFS - First steps
# -------------------------------------------------------------------------- #
Reminder: These steps are done as root.
- 2.3. Creating a File System on the Partition
Code:
mke2fs -jv /dev/sda3
- 2.4. Mounting the New Partition
Code:
export LFS=/mnt/lfs mkdir -pv $LFS mount -v -t ext3 /dev/sda3 $LFS
no need to activate swap
- 3.1. Introduction / packages and patches
Code:
mkdir -v $LFS/sources chmod -v a+wt $LFS/sources wget http://www.linuxfromscratch.org/lfs/downloads/7.1/wget-list wget -i wget-list -P $LFS/sources pushd $LFS/sources wget http://www.linuxfromscratch.org/lfs/downloads/7.1/md5sums md5sum -c md5sums popd
man-pages-3.35.tar.gz and zlib-1.2.6.tar.bz2 where mentioned as missing when I ran the above commands:
Code:
pushd $LFS/sources wget ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/7.1/man-pages-3.35.tar.gz wget ftp://ftp.lfs-matrix.net/pub/lfs/lfs-packages/7.1/zlib-1.2.6.tar.bz2 popd
# -------------------------------------------------------------------------- #
# The lfs user
# -------------------------------------------------------------------------- #
- 4.1. About $LFS
Code:
echo $LFS export LFS=/mnt/lfs mkdir -v $LFS/tools ln -sv $LFS/tools /
Code:
groupadd lfs useradd -s /bin/bash -g lfs -m -k /dev/null lfs passwd lfs chown -v lfs $LFS/tools
Code:
su - lfs
Code:
cat > ~/.bash_profile << "EOF" exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash EOF 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 source ~/.bash_profile
# LFS - Building the toolchain
# -------------------------------------------------------------------------- #
- Chapter 5. Constructing a Temporary System
Do not use the make -j x flag when building: binutils, gcc and glibc!
Safe yourself the time and do not run the checks/tests in chapter 5 (read 4.6. About the Test Suites).
- 5.4. Binutils-2.22 - Pass 1
Code:
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
Code:
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 patch -Np1 -i ../gcc-4.6.2-cross_compile-1.patch mkdir -v ../gcc-build cd ../gcc-build ../gcc-4.6.2/configure \ --target=$LFS_TGT --prefix=/tools \ --disable-nls --disable-shared --disable-multilib \ --disable-decimal-float --disable-threads \ --disable-libmudflap --disable-libssp \ --disable-libgomp --disable-libquadmath \ --disable-target-libiberty --disable-target-zlib \ --enable-languages=c --without-ppl --without-cloog \ --with-mpfr-include=$(pwd)/../gcc-4.6.2/mpfr/src \ --with-mpfr-lib=$(pwd)/mpfr/src/.libs make make install ln -vs libgcc.a `$LFS_TGT-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'` cd $LFS/sources rm -rf gcc-build gcc-4.6.2
Code:
cd $LFS/sources tar xf linux-3.2.6.tar.xz cd linux-3.2.6 make mrproper make headers_check make INSTALL_HDR_PATH=dest headers_install cp -rv dest/include/* /tools/include cd $LFS/sources rm -rf linux-3.2.6
Code:
cd $LFS/sources tar xf glibc-2.14.1.tar.bz2 cd glibc-2.14.1 patch -Np1 -i ../glibc-2.14.1-gcc_fix-1.patch patch -Np1 -i ../glibc-2.14.1-cpuid-1.patch mkdir -v ../glibc-build cd ../glibc-build case `uname -m` in i?86) echo "CFLAGS += -march=i486 -mtune=native" > configparms ;; esac ../glibc-2.14.1/configure --prefix=/tools \ --host=$LFS_TGT --build=$(../glibc-2.14.1/scripts/config.guess) \ --disable-profile --enable-add-ons \ --enable-kernel=2.6.25 --with-headers=/tools/include \ libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes make make install cd $LFS/sources rm -rf glibc-build glibc-2.14.1
Code:
SPECS=`dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/specs $LFS_TGT-gcc -dumpspecs | sed \ -e 's@/lib\(64\)\?/ld@/tools&@g' \ -e "/^\*cpp:$/{n;s,$, -isystem /tools/include,}" > $SPECS echo "New specs file is: $SPECS" unset SPECS echo 'main(){}' > dummy.c $LFS_TGT-gcc -B/tools/lib dummy.c readelf -l a.out | grep ': /tools' output should read: for 32 bit: [Requesting program interpreter: /tools/lib/ld-linux.so.2] for 64 bit: [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2] rm -v dummy.c a.out
Code:
Make sure you removed the previsious build: cd $LFS/sources rm -rf binutils-build binutils-2.22 tar xf binutils-2.22.tar.bz2 cd binutils-2.22 mkdir -v ../binutils-build cd ../binutils-build CC="$LFS_TGT-gcc -B/tools/lib/" \ AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \ ../binutils-2.22/configure --prefix=/tools \ --disable-nls --with-lib-path=/tools/lib make make install make -C ld clean make -C ld LIB_PATH=/usr/lib:/lib cp -v ld/ld-new /tools/bin cd $LFS/sources rm -rf binutils-build binutils-2.22
Code:
Make sure you removed the previsious build: cd $LFS/sources rm -rf gcc-build gcc-4.6.2 tar xf gcc-4.6.2.tar.bz2 cd gcc-4.6.2 patch -Np1 -i ../gcc-4.6.2-startfiles_fix-1.patch cp -v gcc/Makefile.in{,.orig} sed 's@\./fixinc\.sh@-c true@' gcc/Makefile.in.orig > gcc/Makefile.in cp -v gcc/Makefile.in{,.tmp} sed 's/^T_CFLAGS =$/& -fomit-frame-pointer/' gcc/Makefile.in.tmp > gcc/Makefile.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_INCLUDE_DIR #define STANDARD_INCLUDE_DIR 0 #define STANDARD_STARTFILE_PREFIX_1 "" #define STANDARD_STARTFILE_PREFIX_2 ""' >> $file touch $file.orig done case $(uname -m) in x86_64) for file in $(find gcc/config -name t-linux64) ; do \ cp -v $file{,.orig} sed '/MULTILIB_OSDIRNAMES/d' $file.orig > $file done ;; esac 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 mkdir -v ../gcc-build cd ../gcc-build CC="$LFS_TGT-gcc -B/tools/lib/" \ AR=$LFS_TGT-ar RANLIB=$LFS_TGT-ranlib \ ../gcc-4.6.2/configure --prefix=/tools \ --with-local-prefix=/tools --enable-clocale=gnu \ --enable-shared --enable-threads=posix \ --enable-__cxa_atexit --enable-languages=c,c++ \ --disable-libstdcxx-pch --disable-multilib \ --disable-bootstrap --disable-libgomp \ --without-ppl --without-cloog \ --with-mpfr-include=$(pwd)/../gcc-4.6.2/mpfr/src \ --with-mpfr-lib=$(pwd)/mpfr/src/.libs make make install ln -vs gcc /tools/bin/cc echo 'main(){}' > dummy.c cc dummy.c readelf -l a.out | grep ': /tools' output should read: for 32 bit: [Requesting program interpreter: /tools/lib/ld-linux.so.2] for 64 bit: [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2] rm -v dummy.c a.out cd $LFS/sources rm -rf gcc-build gcc-4.6.2