LFS?从零开始构建LFS系统---1

LFS介绍

LFS—Linux from Scratch,是一种从网上直接下载源码,从头编译LINUX的安装方式。
本篇内容宿主机环境选择为Centos 7,LFS系统选择的 Linux 内核版本为:Linux5.1.6. Linux内核版本下载方式如下:

https://mirrors.edge.kernel.org/pub/linux/kernel/

同时构建的 LFS 系统,选择官方版本为:8.4. 其所需软件包下载方式为:

http://mirror.jaleco.com/lfs/pub/lfs/lfs-packages/

其他版本可自行下载

准备工作

  • 宿主机采用的是 Centos 7,虚拟机采用的是 VMware,其安装方式可通过网上的任意教程进行安装,但是内存分配需要至少分配 4G (之前分配的 2G 的内存,发现在进行软件包编译安装过程中,会报内存不足的问题,如下:)
    在这里插入图片描述
    并通过以下脚本检查宿主机环境:
#!/bin/bash
# Simple script to list version numbers of critical development tools
export LC_ALL=C
bash --version | head -n1 | cut -d" " -f2-4
MYSH=$(readlink -f /bin/sh)
echo "/bin/sh -> $MYSH"
echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash"
unset MYSH
echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
bison --version | head -n1
if [ -h /usr/bin/yacc ]; then
 echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
elif [ -x /usr/bin/yacc ]; then
 echo yacc is `/usr/bin/yacc -V | head -n1`
else
 echo "yacc not found"
fi
bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
diff --version | head -n1
find --version | head -n1
gawk --version | head -n1
if [ -h /usr/bin/awk ]; then
 echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
elif [ -x /usr/bin/awk ]; then
 echo awk is `/usr/bin/awk --version | head -n1`
else
 echo "awk not found"
fi

gcc --version | head -n1
g++ --version | head -n1
ldd --version | head -n1 | cut -d" " -f2- # glibc version
grep --version | head -n1
gzip --version | head -n1
cat /proc/version
m4 --version | head -n1
make --version | head -n1
patch --version | head -n1
echo Perl `perl -V:version`
python3 --version
sed --version | head -n1
tar --version | head -n1
makeinfo --version | head -n1 # texinfo version
xz --version | head -n1
echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c
if [ -x dummy ]
 then echo "g++ compilation OK";
 else echo "g++ compilation failed"; fi
rm -f dummy.c dummy

  • 在 Centos 7 安装完成之后,在VMware 中重新挂载一块虚拟硬盘, 作为 LFS 系统的构建位置,添加硬盘方式如下:在这里插入图片描述
  • 随后,重新启动 Centos 7 系统,通过 lsblk 命令可以查看新挂载的硬盘,本人的是默认的命令方式: /dev/sdb 。
  • 分区并格式化新硬盘(sdb):通过以下命令:
    分区与格式化
fdisk /dev/sdb
mkfs -v -t ext4 /dev/sdb
  • 通过以下脚本设置 $LFS 变量并挂载新分区,进入 chroot 环境并拷贝 Linux 内核源码和软件包源码到 LFS 挂载的分区中,然后创建目录 $LFS/tools 与添加LFS用户、设置环境等
#!/bin/bash
export LFS=/home/lfs/LFS_FS
export MAKEFLAGS='-j 3'
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/CentOS-* /etc/yum.repos.d/bak
cp -f /etc/yum.repos.d/bak/CentOS-Media.repo /etc/yum.repos.d/
sed -i -e 's/^enabled=0/enabled=1/' \
    -e 's/^gpgcheck=1/gpgcheck=0/' \
	/etc/yum.repos.d/CentOS-Media.repo
	
	
mkdir /media/cdrom/
mount /dev/sr0 /media/cdrom

yum install -y gcc gcc-c++.x86_64 m4\
       bison byacc patch \
	   perl texinfo bzip2 \
	   zlib-devel libffi-devel \
	   bash-completion nano vim

mv /usr/bin/yacc /usr/bin/yacc.bak
ln -s bison /usr/bin/yacc

mkdir -pv $LFS
mount  -t ext4 /dev/sdb1 $LFS
mkdir $LFS/sources
mkdir $LFS/build
chmod a+wt $LFS/sources
mkdir $LFS/tools
ln -s $LFS/tools /
cp /root/sources/* $LFS/sources

#-----------
cp -rf /root/script $LFS/
#----------

touch $LFS/error
touch $LFS/message 
#mkfifo $LFS/message
chown lfs.lfs $LFS/message
chown lfs.lfs $LFS/error

groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
echo "lfs" | passwd --stdin lfs
chown  lfs:lfs $LFS/tools
chown  -R lfs.lfs $LFS/sources
chown  lfs $LFS/build
chown lfs:lfs ~lfs -R

make -v | head -n1 | grep "4.2.1"
if [ $? != 0 ] ;then
echo install make python3 ..............;
tar -xf /root/sources/lfs-packages-8.4.tar -C /root
cd /root/8.4
tar -xf make-4.2.1.tar.bz2
cd make-4.2.1
cp /usr/bin/make /usr/bin/make.bak
./configure --prefix=/usr >/dev/null 2>&1 ||exit 1;
make > /dev/null 2>&1 ||exit 1;
make install > /dev/null 2>&1 || exit 1;

cd /root/8.4
tar -xf Python-3.7.2.tar.xz
cd Python-3.7.2
./configure --prefix=/home/lfs/THsoft >/dev/null 2>&1 ||exit 1;
make >/dev/null 2>&1 ||exit 1;
make install >/dev/null 2>&1 || exit 1;
cd /root
rm -rf /root/8.4
echo "install ok"
fi

cat > ~lfs/.bash_profile << "EOF"
exec env -i HOME=~lfs TERM=$TERM PS1='\u:\w\> ' /bin/bash
EOF

cat > ~lfs/.bashrc << "EOF"
set +h 
umask 022
LFS=/home/lfs/LFS_FS
LC_ALL=POSIX
LFS_TGT=$(uname -m)-lfs-linux-gnu
PATH=~lfs/THsoft/bin:/tools/bin:/bin:/usr/bin:
export MAKEFLAGS='-j 3'
export LFS LC_ALL LFS_TGT PATH MAKEFLAGS
alias ls="ls --color"
EOF

su - lfs

构建临时系统

  • Binutils 第一遍:
    Binutils 软件包包含一个链接器、一个汇编器、以及其它处理目标文件的工具
    其具体的 configure 及安装方式如下脚本:
cd $LFS/build/8.4
tar -xvf  binutils-2.32.tar.xz 
cd  binutils-2.32
mkdir -v build
cd build
../configure --prefix=/tools \
 --with-sysroot=$LFS \
 --with-lib-path=/tools/lib \
 --target=$LFS_TGT \
 --disable-nls \
 --disable-werror  

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make  
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install  
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

  • GCC 第一遍
    GCC 软件包包括 GNU 编译器集,其中有 C 和 C++ 的编译器
    其具体的 configure 及安装方式如下脚本:
cd $LFS/build/8.4
tar -xf  gcc-8.2.0.tar.xz
cd  gcc-8.2.0


tar -xf ../mpfr-4.0.2.tar.xz
mv -v mpfr-4.0.2 mpfr
tar -xf ../gmp-6.1.2.tar.xz
mv -v gmp-6.1.2 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

case $(uname -m) in
 x86_64)
 sed -e '/m64=/s/lib64/lib/' \
 -i.orig gcc/config/i386/t-linux64
 ;;
esac

mkdir -v 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-libmpx \
 --disable-libquadmath \
 --disable-libssp \
 --disable-libvtv \
 --disable-libstdcxx \
 --enable-languages=c,c++ 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

  • Linux-5.1.6 API 头文件
    Linux API 头文件(在 llinux-5.1.6.tar.xz 里)会将内核 API 导出给 Glibc 使用.
    Linux 内核需要展示供系统 C 库(在 LFS 中是 Glibc)使用的应用程序编程接口(API)。这通过在 Linux 内核源代码 tar 包中包括一些 C 头文件来完成。
    其具体的 configure 及安装方式如下脚本
cd $LFS/build/linux-5.1.6
make mrproper


make INSTALL_HDR_PATH=dest headers_install
if [ $? != 0 ] ;then
echo "make kernel-headers error!"
exit 1;
else
cp -rv dest/include/* /tools/include 
fi
  • Glibc
    Glibc 软件包包含了主要的 C 函数库。这个库提供了分配内存、搜索目录、打开关闭文件、读写文件、操作字符串、模式匹配、基础算法等基本程序.
    其具体的 configure 及安装方式如下脚本:
cd $LFS/build/8.4
tar -xf glibc-2.29.tar.xz
cd glibc-2.29
mkdir build
cd build
../configure \
 --prefix=/tools \
 --host=$LFS_TGT \
 --build=$(../scripts/config.guess) \
 --enable-kernel=3.2 \
 --with-headers=/tools/include 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

gilbc 是最容易出现错误的地方,如果出现 python 环境太老,记得通过,yum install python3 安装最新的 python3.

  • 检查确认新工具链的基本功能
    检查脚本:
echo 'int main(){}' > dummy.c
$LFS_TGT-gcc dummy.c
readelf -l a.out | grep ': /tools' | grep /tools/lib
rm  dummy.c a.out

if [ $? != 0 ] ;then
echo "check-1 error!" 
exit 1;
fi

echo "check-1 ok!" 

如果一切正常的话,最后一个命令从输出形式为:

[Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]
  • GCC 中的 Libstdc++
    Libstdc++ 是标准的 C++ 库。需要用它来编译 C++ 代码(GCC 的一部分是用 C++ 写的),但是在构建 gcc第 1 遍 时,我们需要推迟它的安装进程,因为依赖的 glibc,还未部署在 /tools 目录中。
    执行脚本如下:
cd $LFS/build/8.4/gcc-8.2.0/libstdc++-v3

mkdir -v build
cd build
pwd
../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++/8.2.0 \
 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi
  • Binutils 第二遍
    脚本如下:
cd $LFS/build/8.4
cd  binutils-2.32
mkdir -v build-2
cd build-2
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  

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make clean;
make  
fi



if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install  
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make -C ld clean  
make -C ld LIB_PATH=/usr/lib:/lib 

if [ $? != 0 ] ;then
echo "make -C ld LIB_PATH=/usr/lib:/lib error!"
exit 1;
fi

cp  ld/ld-new /tools/bin
  • GCC第二遍
    脚本如下:
cd $LFS/build/8.4/gcc-8.2.0

cat gcc/limitx.h gcc/glimits.h gcc/limity.h > \
 `dirname $($LFS_TGT-gcc -print-libgcc-file-name)`/include-fixed/limits.h

if [ $? != 0 ] ;then
echo "create limits.h failed"
exit 1;
fi

#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

#case $(uname -m) in
# x86_64)
# sed -e '/m64=/s/lib64/lib/' \
# -i.orig gcc/config/i386/t-linux64
# ;;
#esac

mkdir -v build-2
cd build-2

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 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make clean
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

ln -sv gcc /tools/bin/cc
  • 第二遍检查:
echo 'int main(){}' > dummy.c
ln -sv gcc /tools/bin/cc


cc dummy.c
readelf -l a.out | grep ': /tools' | grep /tools/lib
rm  dummy.c a.out

if [ $? != 0 ] ;then
echo "check-2 error!" 
exit 1;
fi

echo "check-2 ok!" 

同样,如果一切工作正常的话,这里应该没有错误,最后一个命令的输出形式会是:

[Requesting program interpreter: /tools/lib64/ld-linux-x86-64.so.2]
  • Tcl
    Tcl 软件包包含工具命令语言(Tool Command Language)相关程序。
    脚本:
cd $LFS/build/8.4
tar -xf tcl8.6.9-src.tar.gz
cd tcl8.6.9/unix
./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi


if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
TZ=UTC make test 
fi

make install
if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

chmod -v u+w /tools/lib/libtcl8.6.so
make install-private-headers  ||exit 1; 
cd /tools/bin
ln -s tclsh8.6 /tools/bin/tclsh
  • Expect
    Expect 软件包包含一个实现用脚本和其他交互式程序进行对话的程序。
    脚本:
cd $LFS/build/8.4
tar -xf 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 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make SCRIPTS="" install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

这里也是容易出现错误的地方,如果出现 类似 “ pthread @G…” 之类的错误,最好重头进行编译 Glic 和 GCC,我第一错的时候,通过自行修改 expect软件包中的 Makefile ,在 GCC编译时加入了 -lpthread 选项,虽然成功安装 expect,但是在后续的LFS系统正式编译安装的过程中还是出现错误,不得已又重头再来,这样很耗时。

  • DejaGNU
    DejaGNU 软件包包含了测试其他程序的框架,脚本如下:
cd $LFS/build/8.4
tar -xf dejagnu-1.6.2.tar.gz
cd  dejagnu-1.6.2

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check  || echo "check error"  
  • M4,M4软件包包含一个宏处理器。安装脚本如下:
cd $LFS/build/8.4
tar -xf 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  

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check    || echo "m4 check failed!"
  • Ncurses
    Ncurses 软件包包含用于不依赖于特定终端的字符屏幕处理的库,脚本如下:
cd $LFS/build/8.4
tar -xf ncurses-6.1.tar.gz
cd ncurses-6.1

sed -i s/mawk// configure

./configure --prefix=/tools \
 --with-shared \
 --without-debug \
 --without-ada \
 --enable-widec \
 --enable-overwrite 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

cd $LFS/tools/lib
ln -s libncursesw.so /tools/lib/libncurses.so
  • Bash
    脚本如下:
cd $LFS/build/8.4
tar -xf bash-5.0.tar.gz
cd bash-5.0
./configure --prefix=/tools --without-bash-malloc 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

cd $LFS/tools/bin
ln -sv bash /tools/bin/sh
  • Bison,Bison 软件包包含一个语法生成器
    执行脚本如下:
cd $LFS/build/8.4
tar -xf bison-3.3.2.tar.xz
cd bison-3.3.2

./configure --prefix=/tools 
if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Bzip2,Bzip2 软件包包含压缩和解压缩的程序。用 bzip2 压缩文本文件能获得比传统的 gzip 更好的压缩比。
    脚本如下:
cd $LFS/build/8.4

tar -xf  bzip2-1.0.6.tar.gz
cd  bzip2-1.0.6


make 

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make PREFIX=/tools install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi
  • Coreutils,Coreutils 软件包包含用于显示和设置基本系统特性的工具
    脚本如下:
cd $LFS/build/8.4
tar -xf  coreutils-8.30.tar.xz
cd coreutils-8.30
./configure --prefix=/tools --enable-install-program=hostname 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make RUN_EXPENSIVE_TESTS=yes check  || echo "check error"
  • Diffutils,Diffutils 软件包包含显示文件和目录差异的程序
    执行脚本如下:
cd $LFS/build/8.4
tar -xf diffutils-3.7.tar.xz
cd diffutils-3.7

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • File,File 软件包包括一个判断给定的某个或某些文件文件类型的工具。
    执行脚本:
cd $LFS/build/8.4
tar -xf file-5.36.tar.gz
cd file-5.36

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Findutils,Findutils 软件包包含查找文件的程序。这些程序提供递归搜索目录树、创建、管理以及搜索数据库(通常比递归式的 find 要快,但如果数据库最近没有更新的话结果不可靠)。
    脚本如下:
cd $LFS/build/8.4
tar -xf findutils-4.6.0.tar.gz
cd findutils-4.6.0

sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' gl/lib/*.c
sed -i '/unistd/a #include <sys/sysmacros.h>' gl/lib/mountlist.c
echo "#define _IO_IN_BACKUP 0x100" >> gl/lib/stdio-impl.h

./configure --prefix=/tools 
if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Gawk,Gawk 软件包包含用于操作文本文件的程序。
    执行脚本如下:
cd $LFS/build/8.4
tar -xf gawk-4.2.1.tar.xz
cd gawk-4.2.1

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Gettext,Gettext 软件包包含用于国际化和本土化的工具。这允许用 NLS(Native Language Support,本地语言支持)编译程序,使得能以用户的本地语言输出信息。
    脚本:
cd $LFS/build/8.4
tar -xf gettext-0.19.8.1.tar.xz
cd gettext-0.19.8.1


cd gettext-tools
EMACS="no" ./configure --prefix=/tools --disable-shared 

make -C gnulib-lib  || exit 1;
make -C intl pluralx.c  || exit 1
make -C src msgfmt  || exit 1
make -C src msgmerge  || exit 1
make -C src xgettext  || exit 1

cp -v src/{msgfmt,msgmerge,xgettext} /tools/bin
  • Grep,Grep 软件包包含用于在文件中搜索的程序。
cd $LFS/build/8.4
tar -xf grep-3.3.tar.xz
cd grep-3.3

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Gzip,Gzip 软件包包含用于压缩和解压文件的程序。
    执行脚本:
cd $LFS/build/8.4
tar -xf gzip-1.10.tar.xz
cd gzip-1.10

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Make,Make 软件包包含一个用于编译软件的程序
    执行脚本:
cd $LFS/build/8.4
tar -xf make-4.2.1.tar.bz2
cd make-4.2.1

sed -i '211,217 d; 219,229 d; 232 d' glob/glob.c

./configure --prefix=/tools  --without-guile 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Patch,Patch 软件包包含一个通过打「补丁」创建或修改文件的程序,补丁文件通常由 diff 程序生成。
    脚本:
cd $LFS/build/8.4
tar -xf patch-2.7.6.tar.xz
cd patch-2.7.6

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Perl,Perl 软件包包含实用信息抽取与报告语言。
    脚本:
cd $LFS/build/8.4
tar -xf perl-5.28.1.tar.xz
cd perl-5.28.1


sh Configure -des -Dprefix=/tools -Dlibs=-lm -Uloclibpth -Ulocincpth 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

cp  perl cpan/podlators/scripts/pod2man /tools/bin
mkdir -pv /tools/lib/perl5/5.28.1
cp -R lib/* /tools/lib/perl5/5.28.1
  • Python-3.7.2
    脚本:
cd $LFS/build/8.4

#wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
tar -xf libffi-3.2.1.tar.gz
tar -xf Python-3.7.2.tar.xz

cd libffi-3.2.1
./configure --prefix=/tools --host=$LFS_TGT 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

cd $LFS/build/8.4/Python-3.7.2

./configure --prefix=/tools --without-ensurepip 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi
  • Sed,Sed 软件包包含一个流编辑器。
    脚本:
cd $LFS/build/8.4
tar -xf sed-4.7.tar.xz
cd sed-4.7

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Tar,Tar 软件包包含一个归档程序。
    脚本:
cd $LFS/build/8.4
tar -xf tar-1.31.tar.xz
cd tar-1.31

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"
  • Texinfo,Texinfo 软件包包含用于读、写以及转换信息页的程序。
    脚本:
cd $LFS/build/8.4
tar -xf texinfo-6.5.tar.xz
cd texinfo-6.5

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"

以上软件包一般不会出现编译错误,但是会有一些check错误,不过不影响后续的安装。

  • Util-linux,Util-linux 软件包包含了各种各样的小工具。
    脚本:
cd $LFS/build/8.4
tar -xf util-linux-2.33.1.tar.xz
cd util-linux-2.33.1

./configure --prefix=/tools \
 --without-python \
 --disable-makeinstall-chown \
 --without-systemdsystemunitdir \
 --without-ncurses \
 PKG_CONFIG="" 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

此软件包可能会出现,sys-utils/prlimit.c:146:12: error: conflicting types for ‘prlimit’ 此类错误,如果出现,记得重头编译 glic 。

  • Xz,Xz 软件包包含用于压缩和解压文件的程序。它提供 lzma 和更新的 xz 压缩格式功能。和传统的 gzip 或 bzip2命令相比,用 xz 压缩文本文件能获得更好的压缩率。
    脚本:
cd $LFS/build/8.4
tar -xf xz-5.2.4.tar.xz
cd xz-5.2.4

./configure --prefix=/tools 

if [ $? != 0 ] ;then
echo "configure error"
exit 1;
else
make 
fi

if [ $? != 0 ] ;then
echo "make error!"
exit 1;
else
make install 
fi

if [ $? != 0 ] ;then
echo "make install error!"
exit 1;
fi

make check   || echo "check error"

清理无用内容

如果你的 LFS 分区容量比较小,知道有些不必要的内容可以被删除也是挺好
的。目前编译好的可执行文件和库大概会有 70MB 左右不需要的调试符号。可以通过下面的脚本移除这些符号:

strip --strip-debug /tools/lib/*
/usr/bin/strip --strip-unneeded /tools/{,s}bin/*
rm -rf /tools/{,share}/{info,man,doc}
find /tools/{lib,libexec} -name \*.la -delete
echo "finshed"

改变属主

当前,$LFS/tools 目录属于 lfs 用户,这是一个只存在于宿主系统上的帐号。如果继续保持 $LFS/tools目录的现状,其中的文件将属于一个没有相关联帐号的用户 ID。这很危险,因为随后创建的用户有可能会分配到相同的用户 ID,从而变成 $LFS/tools 目录及其中所有文件的属主,以致留下恶意操作这些文件的可
能。
为了解决这个问题,你可以在随后新的 lfs 系统里创建 /etc/passwd 文件时增加一个 lfs 用户,并注意给它分配和宿主系统里相同的用户和组 ID。不过更好的方式是,通过下面的命令将 $LFS/tools 目录的属主改为 root 用户:

chown -R root:root $LFS/tools

直到这里,临时的 LFS 系统算是构建完成,后续正式构建 LFS 系统将在下一篇文章中进行介绍。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值