linux:lfs

Ceci est une ancienne révision du document !


Linux From Scratch

http://fr.linuxfromscratch.org/view/lfs-systemd-stable/index.html

Fonctionnement général: à partir d'un système existant, on construit LFS sur une partition à côté du système existant. On pourra ensuite booter sur LFS situé sur la nouvelle partition.

Dans une machine virtuelle avec 80 Go de stockage et 2 Go de RAM, installer une Debian Stable, en partitionnant comme suit:

  • 20 Go pour le système hôte, type ext4, monté sur / avec l'indicateur d'amorçage
  • 55 Go pour LFS, type ext4, non monté
  • le reste pour le swap

Exécuter le script fournit ici.

Correction à apporter:

  • faire pointer /bin/sh vers bash au lieu de dash (Source):
    sudo dpkg-reconfigure dash
  • installer les paquets build-essential bison gawk m4 texinfo
export LFS=/mnt/lfs
sudo mkdir -pv $LFS
sudo mount -v -t ext4 /dev/<xxx> $LFS
sudo mkdir -v $LFS/sources
sudo chmod -v a+wt $LFS/sources
wget http://fr.linuxfromscratch.org/view/lfs-systemd-stable/wget-list
sudo wget --input-file=wget-list --continue --directory-prefix=$LFS/sources

Passer root, c'est bien plus simple (ne pas oublier de définir $LFS !).

mkdir -v $LFS/tools
ln -sv $LFS/tools / # '/tools' -> '/mnt/lfs/tools'
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
passwd lfs
chown -v lfs $LFS/tools
chown -v lfs $LFS/sources

Se connecter avec l'utilisateur lfs.

~/.bash_profile
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
~/.bashrc
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
source ~/.bash_profile

Si on redémarre la machine maintenant, il faut monter la partition dans $LFS et se connecter avec l'utilisateur lfs, tout est déjà défini.

cd $LFS/sources/
tar fxv binutils-2.34.tar.xz
cd binutils-2.34
mkdir build
cd build
../configure --prefix=/tools --with-sysroot=$LFS --with-lib-path=/tools/lib --target=$LFS_TGT --disable-nls --disable-werror
make 
mkdir -v /tools/lib && ln -sv lib /tools/lib64
make install
cd $LFS/sources/
tar xfv gcc-9.2.0.tar.xz
cd gcc-9.2.0
 
tar -xf ../mpfr-4.0.2.tar.xz
mv -v mpfr-4.0.2 mpfr
tar -xf ../gmp-6.2.0.tar.xz
mv -v gmp-6.2.0 gmp
tar -xf ../mpc-1.1.0.tar.gz
mv -v mpc-1.1.0 mpc
 
for file in gcc/config/{linux,i386/linux{,64}}.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
 
sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
 
mkdir build
cd build
 
../configure                                       \
    --target=$LFS_TGT                              \
    --prefix=/tools                                \
    --with-glibc-version=2.11                      \
    --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-libquadmath                          \
    --disable-libssp                               \
    --disable-libvtv                               \
    --disable-libstdcxx                            \
    --enable-languages=c,c++
make
make install 
cd $LFS/sources/
tar xfv linux-5.5.3.tar.xz
cd linux-5.5.3
make mrproper
make headers
cp -rv usr/include/* /tools/include
cd $LFS/sources/
tar xfv glibc-2.31.tar.xz
cd glib-2.31
 
mkdir build
cd build
 
../configure                             \
      --prefix=/tools                    \
      --host=$LFS_TGT                    \
      --build=$(../scripts/config.guess) \
      --enable-kernel=3.2                \
      --with-headers=/tools/include
make
make install
 
 
 
echo 'int main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools' # doit retourner [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]
rm dummy.c a.out
cd $LFS/sources/gcc-9.2.0/build
 
../libstdc++-v3/configure           \
    --host=$LFS_TGT                 \
    --prefix=/tools                 \
    --disable-multilib              \
    --disable-nls                   \
    --disable-libstdcxx-threads     \
    --disable-libstdcxx-pch         \
    --with-gxx-include-dir=/tools/$LFS_TGT/include/c++/9.2.0
make
make install
cd $LFS/srouces/binutils-2.34/build
rm -rf *
CC=$LFS_TGT-gcc                \
AR=$LFS_TGT-ar                 \
RANLIB=$LFS_TGT-ranlib         \
../configure                   \
    --prefix=/tools            \
    --disable-nls              \
    --disable-werror           \
    --with-lib-path=/tools/lib \
    --with-sysroot
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/gcc-9.2.0
 
cat gcc/limitx.h gcc/glimits.h gcc/limity.h >  `dirname \
  $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h
 
for file in gcc/config/{linux,i386/linux{,64}}.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
 
sed -e '/m64=/s/lib64/lib/' \
        -i.orig gcc/config/i386/t-linux64
 
sed -e '1161 s|^|//|' \
    -i libsanitizer/sanitizer_common/sanitizer_platform_limits_posix.cc
 
cd build
rm -rf *
CC=$LFS_TGT-gcc                                    \
CXX=$LFS_TGT-g++                                   \
AR=$LFS_TGT-ar                                     \
RANLIB=$LFS_TGT-ranlib                             \
../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
make
make install
ln -sv gcc /tools/bin/cc
 
echo 'int main(){}' > dummy.c
cc dummy.c
readelf -l a.out | grep ': /tools' # doit retourner [Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]
rm -v dummy.c a.out
cd $LFS/sources/
tar xfv tcl8.6.10-src.tar.gz
cd tcl8.6.10/unix
./configure --prefix=/tools
make
TZ=UTC make test
make install
chmod -v u+w /tools/lib/libtcl8.6.so
make install-private-headers
ln -sv tclsh8.6 /tools/bin/tclsh
cd $LFS/sources/
tar xfv expect5.45.4.tar.gz
cd expect5.45.4
cp -v configure{,.orig}
sed 's:/usr/local/bin:/bin:' configure.orig > configure
./configure --prefix=/tools       \
            --with-tcl=/tools/lib \
            --with-tclinclude=/tools/include
make
make test
make SCRIPTS="" install
cd $LFS/sources/
tar xfv dejagnu-1.6.2.tar.gz
cd dejagnu-1.6.2
./configure --prefix=/tools
make install
make check
cd $LFS/sources/
tar xfv m4-1.4.18.tar.xz
cd m4-1.4.18
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h
./configure --prefix=/tools
make
make check
make install
cd $LFS/sources/
tar xfv ncurses-6.2.tar.gz
cd ncurses-6.2
sed -i s/mawk// configure
./configure --prefix=/tools \
            --with-shared   \
            --without-debug \
            --without-ada   \
            --enable-widec  \
            --enable-overwrite
make
make install
ln -s libncursesw.so /tools/lib/libncurses.so
 
 
==== Bash-5.0 ====
 
<code bash>
cd $LFS/sources/
tar xfv bash-5.0.tar.gz
cd bash-5.0
./configure --prefix=/tools --without-bash-malloc
make
make tests
make install
ln -sv bash /tools/bin/sh
cd $LFS/sources/
tar xfv bison-3.5.2.tar.xz
cd bison-3.5.2
./configure --prefix=/tools
make
make check
make install
cd $LFS/sources/
tar xfv bzip2-1.0.8.tar.gz
cd bzip2-1.0.8
make -f Makefile-libbz2_so
make clean
make
make PREFIX=/tools install
cp -v bzip2-shared /tools/bin/bzip2
cp -av libbz2.so* /tools/lib
ln -sv libbz2.so.1.0 /tools/lib/libbz2.so
cd $LFS/sources/
tar xfv coreutils-8.31.tar.xz
cd coreutils-8.31
./configure --prefix=/tools --enable-install-program=hostname
make
make install
cd $LFS/sources/
tar xfv diffutils-3.7.tar.xz
cd diffutils-3.7
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv file-5.38.tar.gz
cd file-5.38
make
make install
cd $LFS/sources/
tar xfv findutils-4.7.0.tar.xz
cd findutils-4.7.0
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv gawk-5.0.1.tar.xz
cd gawk-5.0.1
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv gettext-0.20.1.tar.xz
cd gettext-0.20.1
make
cp -v gettext-tools/src/{msgfmt,msgmerge,xgettext} /tools/bin
cd $LFS/sources/
tar xfv grep-3.4.tar.xz
cd grep-3.4
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv gzip-1.10.tar.xz
cd gzip-1.10
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv make-4.3.tar.gz
cd make-4.3
./configure --prefix=/tools --without-guile
make
make install
cd $LFS/sources/
tar xfv patch-2.7.6.tar.xz
cd patch-2.7.6
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv perl-5.30.1.tar.xz
cd perl-5.30.1
sh Configure -des -Dprefix=/tools -Dlibs=-lm -Uloclibpth -Ulocincpth
make
cp -v perl cpan/podlators/scripts/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.30.1
cp -Rv lib/* /tools/lib/perl5/5.30.1
cd $LFS/sources/
tar xfv Python-3.8.1.tar.xz
cd  Python-3.8.1
sed -i '/def add_multiarch_paths/a \        return' setup.py
./configure --prefix=/tools --without-ensurepip
make
make install
cd $LFS/sources/
tar xfv sed-4.8.tar.xz
cd sed-4.8
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv tar-1.32.tar.xz
cd tar-1.32
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv texinfo-6.7.tar.xz
cd texinfo-6.7
./configure --prefix=/tools
make
make install
cd $LFS/sources/
tar xfv util-linux-2.35.1.tar.xz
cd util-linux-2.35.1
./configure --prefix=/tools                \
            --without-python               \
            --disable-makeinstall-chown    \
            --without-systemdsystemunitdir \
            --without-ncurses              \
            PKG_CONFIG=""
make
make install
cd $LFS/sources/
tar xfv xz-5.2.4.tar.xz
cd xz-5.2.4
./configure --prefix=/tools
make
make install
strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*

En tant que root (ne pas oublie $LFS !)

chown -R root:root $LFS/tools

En tant que root:

mkdir -pv $LFS/{dev,proc,sys,run}
 
mknod -m 600 $LFS/dev/console c 5 1
mknod -m 666 $LFS/dev/null c 1 3
 
mount -v --bind /dev $LFS/dev
 
mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount -vt proc proc $LFS/proc
mount -vt sysfs sysfs $LFS/sys
mount -vt tmpfs tmpfs $LFS/run
chroot "$LFS" /tools/bin/env -i \
    HOME=/root                  \
    TERM="$TERM"                \
    PS1='(lfs chroot) \u:\w\$ ' \
    PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
    /tools/bin/bash --login +h
mkdir -pv /{bin,boot,etc/{opt,sysconfig},home,lib/firmware,mnt,opt}
mkdir -pv /{media/{floppy,cdrom},sbin,srv,var}
install -dv -m 0750 /root
install -dv -m 1777 /tmp /var/tmp
mkdir -pv /usr/{,local/}{bin,include,lib,sbin,src}
mkdir -pv /usr/{,local/}share/{color,dict,doc,info,locale,man}
mkdir -v  /usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -v  /usr/libexec
mkdir -pv /usr/{,local/}share/man/man{1..8}
mkdir -v  /usr/lib/pkgconfig
 
case $(uname -m) in
 x86_64) mkdir -v /lib64 ;;
esac
 
mkdir -v /var/{log,mail,spool}
ln -sv /run /var/run
ln -sv /run/lock /var/lock
mkdir -pv /var/{opt,cache,lib/{color,misc,locate},local}
ln -sv /tools/bin/{bash,cat,chmod,dd,echo,ln,mkdir,pwd,rm,stty,touch} /bin
ln -sv /tools/bin/{env,install,perl,printf}         /usr/bin
ln -sv /tools/lib/libgcc_s.so{,.1}                  /usr/lib
ln -sv /tools/lib/libstdc++.{a,so{,.6}}             /usr/lib
ln -sv bash /bin/sh
 
ln -sv /proc/self/mounts /etc/mtab
 
cat > /etc/passwd << "EOF"
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/dev/null:/bin/false
daemon:x:6:6:Daemon User:/dev/null:/bin/false
messagebus:x:18:18:D-Bus Message Daemon User:/var/run/dbus:/bin/false
systemd-bus-proxy:x:72:72:systemd Bus Proxy:/:/bin/false
systemd-journal-gateway:x:73:73:systemd Journal Gateway:/:/bin/false
systemd-journal-remote:x:74:74:systemd Journal Remote:/:/bin/false
systemd-journal-upload:x:75:75:systemd Journal Upload:/:/bin/false
systemd-network:x:76:76:systemd Network Management:/:/bin/false
systemd-resolve:x:77:77:systemd Resolver:/:/bin/false
systemd-timesync:x:78:78:systemd Time Synchronization:/:/bin/false
systemd-coredump:x:79:79:systemd Core Dumper:/:/bin/false
nobody:x:99:99:Unprivileged User:/dev/null:/bin/false
EOF
 
cat > /etc/group << "EOF"
root:x:0:
bin:x:1:daemon
sys:x:2:
kmem:x:3:
tape:x:4:
tty:x:5:
daemon:x:6:
floppy:x:7:
disk:x:8:
lp:x:9:
dialout:x:10:
audio:x:11:
video:x:12:
utmp:x:13:
usb:x:14:
cdrom:x:15:
adm:x:16:
messagebus:x:18:
systemd-journal:x:23:
input:x:24:
mail:x:34:
kvm:x:61:
systemd-bus-proxy:x:72:
systemd-journal-gateway:x:73:
systemd-journal-remote:x:74:
systemd-journal-upload:x:75:
systemd-network:x:76:
systemd-resolve:x:77:
systemd-timesync:x:78:
systemd-coredump:x:79:
wheel:x:97:
nogroup:x:99:
users:x:999:
EOF
 
exec /tools/bin/bash --login +h
 
touch /var/log/{btmp,lastlog,faillog,wtmp}
chgrp -v utmp /var/log/lastlog
chmod -v 664  /var/log/lastlog
chmod -v 600  /var/log/btmp
cd /sources/linux-5.5.3
make mrproper
make headers
find usr/include -name '.*' -delete
rm usr/include/Makefile
cp -rv usr/include/* /usr/include
cd /sources/
tar xfv man-pages-5.05.tar.xz
cd man-pages-5.05
make install
cd /sources/glibc-2.31/
patch -Np1 -i ../glibc-2.31-fhs-1.patch
 
ln -sfv ../lib/ld-linux-x86-64.so.2 /lib64
ln -sfv ../lib/ld-linux-x86-64.so.2 /lib64/ld-lsb-x86-64.so.3
 
cd build
rm -rf *
 
CC="gcc -ffile-prefix-map=/tools=/usr" \
../configure --prefix=/usr                          \
             --disable-werror                       \
             --enable-kernel=3.2                    \
             --enable-stack-protector=strong        \
             --with-headers=/usr/include            \
             libc_cv_slibdir=/lib
 
make
 
ln -sfnv $PWD/elf/ld-linux-x86-64.so.2 /lib
 
make check
 
touch /etc/ld.so.conf
 
sed '/test-installation/s@$(PERL)@echo not running@' -i ../Makefile
 
make install
 
cp -v ../nscd/nscd.conf /etc/nscd.conf
mkdir -pv /var/cache/nscd
 
install -v -Dm644 ../nscd/nscd.tmpfiles /usr/lib/tmpfiles.d/nscd.conf
install -v -Dm644 ../nscd/nscd.service /lib/systemd/system/nscd.service
 
mkdir -pv /usr/lib/locale
localedef -i POSIX -f UTF-8 C.UTF-8 2> /dev/null || true
localedef -i cs_CZ -f UTF-8 cs_CZ.UTF-8
localedef -i de_DE -f ISO-8859-1 de_DE
localedef -i de_DE@euro -f ISO-8859-15 de_DE@euro
localedef -i de_DE -f UTF-8 de_DE.UTF-8
localedef -i el_GR -f ISO-8859-7 el_GR
localedef -i en_GB -f UTF-8 en_GB.UTF-8
localedef -i en_HK -f ISO-8859-1 en_HK
localedef -i en_PH -f ISO-8859-1 en_PH
localedef -i en_US -f ISO-8859-1 en_US
localedef -i en_US -f UTF-8 en_US.UTF-8
localedef -i es_MX -f ISO-8859-1 es_MX
localedef -i fa_IR -f UTF-8 fa_IR
localedef -i fr_FR -f ISO-8859-1 fr_FR
localedef -i fr_FR@euro -f ISO-8859-15 fr_FR@euro
localedef -i fr_FR -f UTF-8 fr_FR.UTF-8
localedef -i it_IT -f ISO-8859-1 it_IT
localedef -i it_IT -f UTF-8 it_IT.UTF-8
localedef -i ja_JP -f EUC-JP ja_JP
localedef -i ja_JP -f SHIFT_JIS ja_JP.SIJS 2> /dev/null || true
localedef -i ja_JP -f UTF-8 ja_JP.UTF-8
localedef -i ru_RU -f KOI8-R ru_RU.KOI8-R
localedef -i ru_RU -f UTF-8 ru_RU.UTF-8
localedef -i tr_TR -f UTF-8 tr_TR.UTF-8
localedef -i zh_CN -f GB18030 zh_CN.GB18030
localedef -i zh_HK -f BIG5-HKSCS zh_HK.BIG5-HKSCS
 
cat > /etc/nsswitch.conf << "EOF"
# Begin /etc/nsswitch.conf
 
passwd: files
group: files
shadow: files
 
hosts: files dns
networks: files
 
protocols: files
services: files
ethers: files
rpc: files
 
# End /etc/nsswitch.conf
EOF
 
tar -xf ../../tzdata2019c.tar.gz
ZONEINFO=/usr/share/zoneinfo
mkdir -pv $ZONEINFO/{posix,right}
for tz in etcetera southamerica northamerica europe africa antarctica  \
          asia australasia backward pacificnew systemv; do
    zic -L /dev/null   -d $ZONEINFO       ${tz}
    zic -L /dev/null   -d $ZONEINFO/posix ${tz}
    zic -L leapseconds -d $ZONEINFO/right ${tz}
done
cp -v zone.tab zone1970.tab iso3166.tab $ZONEINFO
zic -d $ZONEINFO -p America/New_York
unset ZONEINFO
tzselect
ln -sfv /usr/share/zoneinfo/Europe/Paris /etc/localtime
 
cat > /etc/ld.so.conf << "EOF"
# Début de /etc/ld.so.conf
/usr/local/lib
/opt/lib
 
EOF
cat >> /etc/ld.so.conf << "EOF"
# Ajout d'un répertoire include
include /etc/ld.so.conf.d/*.conf
 
EOF
mkdir -pv /etc/ld.so.conf.d
mv -v /tools/bin/{ld,ld-old}
mv -v /tools/$(uname -m)-pc-linux-gnu/bin/{ld,ld-old}
mv -v /tools/bin/{ld-new,ld}
ln -sv /tools/bin/ld /tools/$(uname -m)-pc-linux-gnu/bin/ld
 
gcc -dumpspecs | sed -e 's@/tools@@g'                   \
    -e '/\*startfile_prefix_spec:/{n;s@.*@/usr/lib/ @}' \
    -e '/\*cpp:/{n;s@$@ -isystem /usr/include@}' >      \
    `dirname $(gcc --print-libgcc-file-name)`/specs

Faire certaines vérifications, cf le manuel.

cd /sources/
tar xfv zlib-1.2.11.tar.xz
cd zlib-1.2.11
./configure --prefix=/usr
make
make install
mv -v /usr/lib/libz.so.* /lib
ln -sfv ../../lib/$(readlink /usr/lib/libz.so) /usr/lib/libz.so
  • linux/lfs.1600602089.txt.gz
  • Dernière modification : 2021/04/04 17:01
  • (modification externe)