目录
  1. 1. LFS系统构建01-宿主机环境搭建
    1. 1.1. 环境检查
    2. 1.2. 运行环境配置
LFS系统构建01-宿主机环境搭建

LFS系统构建01-宿主机环境搭建

环境检查

  • 运行shell脚本version_check.sh,具体代码由官方手册提供
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/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 --version | 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-
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`
sed --version | head -n1
tar --version | head -n1
makeinfo --version | head -n1
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
  • 检查结果
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
bash, version 4.2.46(2)-release
/bin/sh -> /usr/bin/bash
Binutils: version 2.27-34.base.el7
./version_check.sh: line 10: bison: command not found
yacc not found
bzip2, Version 1.0.6, 6-Sept-2010.
Coreutils: 8.22
diff (GNU diffutils) 3.3
find (GNU findutils) 4.5.11
GNU Awk 4.0.2
/usr/bin/awk -> /usr/bin/gawk
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36)
./version_check.sh: line 32: g++: command not found
(GNU libc) 2.17
grep (GNU grep) 2.20
gzip 1.5
Linux version 3.10.0-957.12.2.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) ) #1 SMP Tue May 14 21:24:32 UTC 2019
m4 (GNU M4) 1.4.16
GNU Make 3.82
./version_check.sh: line 39: patch: command not found
Perl version='5.16.3';
sed (GNU sed) 4.2.2
tar (GNU tar) 1.26
./version_check.sh: line 43: makeinfo: command not found
xz (XZ Utils) 5.2.2
./version_check.sh: line 46: g++: command not found
g++ compilation failed
  • 按照检查结果安装缺失软件
1
yum install bison byacc.x86_64 gcc-c++ patch texinfo.x86_64 epel-release.noarch

运行环境配置

  1. 设置变量LFS
1
export LFS=/mnt/lfs
  1. 挂载文件系统
1
2
3
mkfs.ext4 /dev/sdb
mkdir -pv $LFS
mount -v -t ext4 /dev/sdb $LFS
  1. 创建sources目录放置源码
1
2
mkdir -v $LFS/sources
chmod -v a+wt $LFS/sources
  1. 下载软件包
1
2
wget mirrors.ustc.edu.cn/lfs/lfs-packages/lfs-packages-8.4.tar
tar -xvf lfs-packages-8.4.tar -C $LFS/sources/
  1. 检查软件包完整性
1
2
3
pushd $LFS/sources
md5sum -c sources/md5sums
popd
  1. 创建tools目录,用于存储工具
1
2
mkdir -v $LFS/tools 
ln -sv $LFS/tools /
  1. 创建lfs用户和组
1
2
3
groupadd lfs
useradd -s /bin/bash -g lfs -m -k /dev/null lfs
echo "" | passwd --stdin lfs
  1. 设置目录权限
1
2
chown -v lfs $LFS/sources
chown -v lfs $LFS/tools
  1. 配置lfs用户
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cat > ~/.bash_profile << "EOF"
exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
EOF
source ~/.bash_profile
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 ~/.bashrc
文章作者: rack-leen
文章链接: http://yoursite.com/2019/06/03/LFS/LFS%E7%B3%BB%E7%BB%9F%E6%9E%84%E5%BB%BA01-%E5%AE%BF%E4%B8%BB%E6%9C%BA%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 rack-leen's blog
打赏
  • 微信
  • 支付宝

评论