Linux from Scratch
This is not one of my personal projects, but a opensource project dedicated to instructing users on how to build their own linux system by providing a bare base. This is the linux system that I use for my own systems & projects. Occassionally you may see me on their mailing list. In the past I was responsible for maintaining the bootscripts & making new releases.
As of the time of this writing, LFS is primarely designed to work on 32bit x86 processors, and recently has been updated to support 64bit as well. At this time, it does not support multilib (Allowing 32bit and 64bit programs to run on the same system.
I have been experimenting with building my own multilib lfs system. There are some changes I have made that would make it unsuitable to be put into the book as is, but as the LFS motto goes, my distro, my rules. The best way to explain it, is that I took a standard 32bit LFS build, updated it to support 64bit (I have consulted CLFS, a simular project for a few patches, but I would have to redo my system if I wanted to follow them), and then added the minimal number of packages required to allow a 32bit program to compile. Basically, these are the rules I followed for my own system.
- /lib, /usr/lib for 64bit libraries. Most programms install in the lib folder by default, and I did not want to work around this for every package
- /lib/32, /usr/lib/32 for 32bit libraries. I like the idea of a clean filesystem, and the only 32bit program I currently use is wine. This is not a standard, and I would not recommend it for anyone who actually wishes to run 32bit software.
- 32bit config files and 32bit binaries (ex:/ ncurses-config) I have stored in /usr/lib/32/bin. again, nonstandard (even more then above).
- Installing a 64bit program should not require any extra work then what it would take on a 64bit system.
- a few hoops to install a 32bit system on mine. CC="gcc -m32" CXX+"g++ -m32" PKG_CONFIG_PATH="/usr/lib/32/pkgconfig" PATH="/usr/lib/32/bin/${PATH}". I do not think there is a easy way to work around this, and for one 32bit program, I am not that worried about it
- Ideally, I do not want 32bit/64bit libraries of everything. I want a pure 64bit system first, and then the ability to add on 32bit after. Other then pesky binaries, this is usually straight forward
Todo:
- This page will be a work in progress for a few page as I post my changes.
- I still have to post the changes made to Chapter 6
- I build zlib before building binutils due to new requiraments, but I want to do further tests that before adding it here
Multilib Tweaks
5 - Binutils Pass 1 [ORIG]
LFS has moved over to a cross compiler toolchain to further distance itself from the host it has been compiled on. Unfortunately I have not been able to adapt the instructions as it currently is to build a multilib compiler. Therefore I have used a standard native build of binutils below. This was taken from LFS before the conversion.
- patch -Np1 -i ../../src/binutils-${BINUTILS_VERSION}-genscripts_multilib-1.patch
- mkdir ../binutils-build
- cd ../binutils-build
- ../binutils-${BINUTILS_VERSION}/configure --prefix=/tools --disable-nls --disable-werror --enable-64-bit-bfd
- make
- make install
- make -C ld clean
- make -C ld LIB_PATH=/tools/lib:/tools/lib/32
- cp -v ld/ld-new /tools/bin
5 - GCC Pass 1 [ORIG]
GCC is where most of the changes made to support a 64bit system reside. I have drawn from the work in LFS, CLFS, and my own experimentation. As with binutils, This is not cross compiled as it is in LFS. I was unable to use the automated GCC build to compile gmp/mpfr in the build in the proper directory (It used /tools/lib64), and I already have these two programs on my host system. This may not be the case on a non LFS linux distribution but I did not address that problem.
- sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
- sed -i -e 's@/lib/ld-linux.so.2@/lib/32/ld-linux.so.2@g' -e 's@/lib64/ld-linux-x86-64.so.2@/lib/ld-linux-x86-64.so.2@g' gcc/config/i386/linux64.h
- sed -i -e '/MULTILIB_OSDIRNAMES/d' gcc/config/i386/t-linux64
- echo "MULTILIB_OSDIRNAMES = ../lib ../lib/32" >> gcc/config/i386/t-linux64
- mkdir ../gcc-build
- cd ../gcc-build
- ../gcc-${GCC_VERSION}/configure --prefix=/tools --disable-nls --disable-shared --disable-decimal-float --disable-threads --disable-libmudflap --disable-libssp --disable-libgomp --enable-languages=c --enable-long-long
- make
- make install
- ln -vsf gcc /tools/bin/cc
- ln -vsf libgcc.a `gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
- ln -vsf libgcc.a `gcc -m32 -print-libgcc-file-name | sed 's/libgcc/&_eh/'
5 - Glibc 32bit [ORIG]
Not many modifications here, I did not install the locale's at this stage as they will be build in the 64bit glibc, and I had a coupple of workarounds to get glibc to support my library locations
- patch -Np1 -i ../../src/glibc-${GLIBC_VERSION}-binutils-1.patch
- mkdir ../glibc-build
- cd ../glibc-build
- echo "CFLAGS += -march=i686" > configparms
- echo "slibdir=/tools/lib/32" >> configparms
- CC="gcc -m32" CXX="g++ -m32" \
- ../glibc-${GLIBC_VERSION}/configure --prefix=/tools --disable-profile --enable-add-ons --enable-kernel=2.6.29 --with-headers=/tools/include --host=i686-pc-linux-gnu --libexecdir=/tools/lib/32/glibc --libdir=/tools/lib/32 libc_cv_forced_unwind=yes libc_cv_c_cleanup=yes
- make
- sed -i -e 's@/lib/ld-linux.so.2@lib/32/ld-linux.so.2@' -e 's@/lib64/ld-linux-x86-64.so.2@/lib/ld-linux-x86-64.so.2@' elf/ldd
- make install
5 - Glibc 64bit [ORIG]
All I modified in my 64bit build of glibc, was removing --host and --build from the arguments
5 - Adjusting [ORIG]
My toolchain is different from LFS's current toolchain, so I am using their previous adjustment method. Also a few tweaks to support my lib locations
- mv -v /tools/bin/{ld,ld-old}
- mv -v /tools/$(gcc -dumpmachine)/bin/{ld,ld-old}
- mv -v /tools/bin/{ld-new,ld}
- ln -sv /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
- gcc -dumpspecs | sed -e 's@/lib/ld-linux.so.2@/tools/lib/32/ld-linux.so.2@g' -e 's@/lib64/ld-linux-x86-64.so.2@/tools/lib/ld-linux-x86-64.so.2@g'& `dirname $(gcc -print-libgcc-file-name)`/specs
5 - GMP
When I follow LFS as is, GMP ends up in /tools/lib64, so I compile it before gcc
- ./configure --prefix=/tools --enable-cxx --enable-mpbsd
- make
- make install
5 - MPFR
When I follow LFS as is, MPFR ends up in /tools/lib64, so I compile it before gcc
- ./configure --prefix=/tools --enable-thread-safe
- make
- make install
5 - Binutils Pass 2 [ORIG]
This package, and GCC pass 2 are the reasons I did not build a cross compiler. When I use -B, I could not get it to compile multilib support w/o errors. The Patch I use (Found above in 5 - Binutils Pass 1) is from CLFS, that allows me to use the lib path as I have below.
- patch -Np1 -i ../../src/binutils-${BINUTILS_VERSION}-genscripts_multilib-1.patch
- mkdir ../binutils-build
- cd ../binutils-build
- ../binutils-${BINUTILS_VERSION}/configure --prefix=/tools --disable-nls --with-lib-path=/tools/lib:/tools/lib/32
- make
- make install
- cp -v ld/ld-new /tools/bin/ld
- ln -svf /tools/bin/ld /tools/$(gcc -dumpmachine)/bin/ld
- make -C ld clean
- make -C ld LIB_PATH=/usr/lib:/lib:/usr/lib/32:/lib/32
- cp -v ld/ld-new /tools/bin
5- GCC Pass 2 [ORIG]
- patch -Np1 -i ../../src/gcc-${GCC_VERSION}-startfiles_fix-1.patch
- sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in
- sed -i -e 's@/lib/ld-linux.so.2@/tools/lib/32/ld-linux.so.2@g' -e 's@/lib64/ld-linux-x86-64.so.2@/tools/lib/ld-linux-x86-64.so.2@g' -e 's@/usr@/tools@g' gcc/config/i386/linux64.h
- sed -i -e 's@/lib/ld-linux.so.2@/tools/lib/ld-linux.so.2@g' -e 's@/usr@/tools@g' gcc/config/i386/linux.h
- sed -i -e '/MULTILIB_OSDIRNAMES/d' -e 's@/usr@/tools@g' gcc/config/i386/t-linux64
- mkdir ../gcc-build
- cd ../gcc-build
- ../gcc-${GCC_VERSION}/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-bootstrap --enable-long-long
- make
- make install
Appendix:
LFS Build Scripts
I created the above LFS automatic build scripts, so I could easly test/rebuild a linux system without manually building every package. I have posted them above if anyone is interested in seeing how such a system could be built. To save space, I have removed all packages/patches from the above tarball. I am not planning on supporting this if anyone uses it (I released it for informational purposes), but feel free to ask questions if you like.