转载请标明出处:https://www.cnblogs.com/kelamoyujuzhen/articles/9161515.html

实验环境:

Host:Windows10 + WMWare Workstation14.1.1 build-7528167

LSB Version: :core-4.1-amd64:core-4.1-noarch

Distributor ID: CentOS

Description: CentOS Linux release 7.5.1804 (Core)

Release: 7.5.1804

Codename: Core

LFS:7.10

准备host系统

依赖工具、库

要想构建LFS系统,首先需要一个Linux发行版本事先安装好,可以选择最小化安装。这个事先安装好的Linux(称为 host)提供必要的工具:

eg:编译器(compiler,)、链接器(linker,)、shell等等

借助这些工具构建我们的LFS系统。

为了构建LFS,host需要安装必要的工具。对于LFS 7.10来说,不建议使用小于下面列出版本号的tarball。

Bash-3.2(/bin/sh应该是bash的符号链接 或 硬链接)

  1. This package satisfies an LSB core requirement to provide a Bourne Shell interface to the system.It was chosenover other shell packages because of its common usage and extensive capabilities beyond basic shell functions.

Binutils-2.17 (不建议使用版本号小于2.30的包,因为未被测试)

  1. This package contains a linker, an assembler, and other tools for handling object files. The programs in this package are needed to compile most of the packages in an LFS system and beyond.

Bison-2.3 (/usr/bin/yacc应该是bison的一个链接;也可以链接到一个脚本,这个脚本会执行bison)

  1. This package contains the GNU version of yacc(Yet Another Compiler Compiler) needed to build several other LFS programs.

Bzip2-1.0.4

  1. This package contains programs for compressing and decompressing files.It is required to decompress many LFS packages.

Coreutils-6.9

  1. This package contains a number of essential programs for viewing and manipulating files and directories. These programs are needed for command line file management, and are necessary for the installation procedures of every package in LFS.

Diffutils-2.8.1

  1. This package contains programs that show the differences between files or directories. These programs can be used to create patches, and are also used in many packages' build procedures.

Findutils-4.2.31

  1. This package contains programs to find files in a file system. It is used in many packages' build scripts.

Gawk-4.0.1(/usr/bin/awk应该是gawk的一个链接)

  1. This package contains programs for manipulating text files. It is the GNU version of awk(Aho-Weinberg-
  2. Kernighan). It is used in many other packages' build scripts.

GCC-4.7包括C++编译器(不建议使用版本号大于7.3.0,因为未被测试)

  1. This package is the Gnu Compiler Collection.It contains the C and C++ compilers as well as several others not built by LFS.

Glibc-2.11(不建议使用版本号大于2.27,因为未被测试)

  1. This package contains the main Clibrary.Linux programs would not run without it.

Grep-2.5.1a

  1. This package contains programs for searching through files. These programs are used by most packages' build
  2. scripts.

Gzip-1.3.12

  1. This package contains programs for compressing and decompressing files. It is needed to decompress many
  2. packages in LFS and beyond.

Linux Kernel-2.6.32(编译glibc、udev会用到)

  1. This package is the Operating System. It is the Linux in the GNU/Linux environment

M4-1.4.10

  1. This package contains a general text macro processor useful as a build tool for other programs

Make-3.81

  1. This package contains a program for directing the building of packages. It is required by almost every package in
  2. LFS.

Patch-2.5.4

  1. This package contains a program for modifying or creating files by applying a patch file typically created by the
  2. diff program. It is needed by the build procedure for several LFS packages.

Perl-5.8.8

  1. This package is an interpreter for the runtime language PERL. It is needed for the installation and test suites of
  2. several LFS packages.

Sed-4.1.5

  1. This package allows editing of text without opening it in a text editor. It is also needed by most LFS packages'
  2. configure scripts.

Tar-1.22

  1. This package provides archiving and extraction capabilities of virtually all packages used in LFS.

Texinfo-4.7

  1. This package contains programs for reading, writing, and converting info pages. It is used in the installation
  2. procedures of many LFS packages.

Xz-5.0.0

  1. This package contains programs for compressing and decompressing files. It provides the highest compression
  2. generally available and is useful for decompressing packages in XZ or LZMA format.

执行如下命令,然后运行脚本version-check.sh,根据输出安装必要工具。安装的工具版本号 ≥ 上面最低版本号。

  1. #!/bin/bash
  2. # Simple script to list version numbers of critical development tools
  3. export LC_ALL=C
  4. #deal with bash
  5. bash --version | head -n1 | cut -d" " -f2-
  6. MYSH=$(readlink -f /bin/sh)
  7. echo "/bin/sh -> $MYSH"
  8. echo $MYSH | grep -q bash || echo "ERROR: /bin/sh does not point to bash"
  9. unset MYSH
  10.  
  11. #deal with binutils
  12. echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
  13.  
  14. #deal with bison
  15. bison --version | head -n1
  16.  
  17. #deal with yacc
  18. if [ -h /usr/bin/yacc ]; then
  19. echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
  20. elif [ -x /usr/bin/yacc ]; then
  21. echo yacc is `/usr/bin/yacc --version | head -n1`
  22. else
  23. echo "yacc not found"
  24. fi
  25.  
  26. #deal with bzip2
  27. bzip2 --version >& < /dev/null | head -n1 | cut -d" " -f1,-
  28.  
  29. #deal with coreutils
  30. echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
  31.  
  32. #deal with diff
  33. diff --version | head -n1
  34.  
  35. #deal with find
  36. find --version | head -n1
  37.  
  38. #deal with gawk
  39. gawk --version | head -n1
  40.  
  41. #deal with awk
  42. if [ -h /usr/bin/awk ]; then
  43. echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
  44. elif [ -x /usr/bin/awk ]; then
  45. echo awk is `/usr/bin/awk --version | head -n1`
  46. else
  47. echo "awk not found"
  48. fi
  49.  
  50. #deal with gcc
  51. gcc --version | head -n1
  52.  
  53. #deal with g++
  54. g++ --version | head -n1
  55.  
  56. #deal with lss
  57. ldd --version | head -n1 | cut -d" " -f2- # glibc version
  58.  
  59. #deal with grep
  60. grep --version | head -n1
  61.  
  62. #deal with gzip
  63. gzip --version | head -n1
  64. cat /proc/version
  65.  
  66. #deal with m4
  67. m4 --version | head -n1
  68.  
  69. #deal with make
  70. make --version | head -n1
  71.  
  72. #deal with patch
  73. patch --version | head -n1
  74.  
  75. #deal with perl
  76. echo Perl `perl -V:version`
  77.  
  78. #deal with sed
  79. sed --version | head -n1
  80.  
  81. #deal with tar
  82. tar --version | head -n1
  83.  
  84. #deal with makeinfo
  85. makeinfo --version | head -n1
  86.  
  87. #deal with xz
  88. xz --version | head -n1
  89.  
  90. #test whether gcc is OK
  91. echo 'int main(){}' > dummy.c && g++ -o dummy dummy.c
  92. if [ -x dummy ]
  93. then echo "g++ compilation OK";
  94. else echo "g++ compilation failed"; fi
  95. rm -f dummy.c dummy

我的实验环境下,我是根据脚本提示依次安装所需要的包。当然你也可以使用一条yum命令搞定,如下

  1. yum -y install bash binutils bison bzip2 coreutils diffutils findutils gawk gcc glibc grep gzip kernel m4 make patch perl sed tar texinfo xz gcc-c++ flex

有几个包需要单独说下:

没有g++这个包,需要安装gcc-c++

makeinfo这个包在texinfo包里面。

安装完bison后还要将yacc链接到bison

  1. ln -sv /usr/bin/bison /usr/bin/yacc

安装完以后再次执行包检查脚本输出如下

  1. bash, version 4.2.()-release
  2. /bin/sh -> /usr/bin/bash
  3. Binutils: version 2.25.-.base.el7
  4. bison (GNU Bison) 3.0.
  5. /usr/bin/yacc -> /usr/bin/bison
  6. bzip2, Version 1.0., -Sept-.
  7. Coreutils: 8.22
  8. diff (GNU diffutils) 3.3
  9. find (GNU findutils) 4.5.
  10. GNU Awk 4.0.
  11. /usr/bin/awk -> /usr/bin/gawk
  12. gcc (GCC) 4.8. (Red Hat 4.8.-)
  13. g++ (GCC) 4.8. (Red Hat 4.8.-)
  14. (GNU libc) 2.17
  15. grep (GNU grep) 2.20
  16. gzip 1.5
  17. Linux version 3.10.-.el7.x86_64 (builder@kbuilder.dev.centos.org) (gcc version 4.8. (Red Hat 4.8.-) (GCC) ) # SMP Tue Nov :: UTC
  18. m4 (GNU M4) 1.4.
  19. GNU Make 3.82
  20. GNU patch 2.7.
  21. Perl version='5.16.3';
  22. sed (GNU sed) 4.2.
  23. tar (GNU tar) 1.26
  24. makeinfo (GNU texinfo) 5.1
  25. xz (XZ Utils) 5.2.
  26. g++ compilation OK

在检查依赖库

  1. #!/bin/bash
  2. for lib in lib{gmp,mpfr,mpc}.la; do
  3. echo $lib: $(if find /usr/lib* -name $lib|
  4. grep -q $lib;then :;else echo not;fi) found
  5. done
  6. unset lib

我的环境上输出

  1. [root@localhost LFS]# sh library-check.sh
  2. libgmp.la: not found
  3. libmpfr.la: not found
  4. libmpc.la: not found

注:这三个库,要么全都有,要么全都没有。不可以有的有有的没有

创建分区

准备用于安装 LFS 的分区。包括建立分区、为分区设置文件系统,挂载分区。

我单独给LFS一块20G的磁盘,分区安排如下

  1. [root@localhost ~]# fdisk /dev/sdb
  2. Welcome to fdisk (util-linux 2.23.).
  3.  
  4. Changes will remain in memory only, until you decide to write them.
  5. Be careful before using the write command.
  6.  
  7. Command (m for help): p
  8.  
  9. Disk /dev/sdb: 21.5 GB, bytes, sectors
  10. Units = sectors of * = bytes
  11. Sector size (logical/physical): bytes / bytes
  12. I/O size (minimum/optimal): bytes / bytes
  13. Disk label type: dos
  14. Disk identifier: 0xf1aba154
  15.  
  16. Device Boot Start End Blocks Id System
  17. /dev/sdb1 Linux
  18. /dev/sdb2 Linux swap / Solaris
  19. /dev/sdb3 Linux
  1. [root@localhost ~]# lsblk /dev/sdb
  2. NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
  3. sdb : 20G disk
  4. ├─sdb1 : 100M part #用于boot分区
  5. ├─sdb2 : 4G part #用于swap分区
  6. └─sdb3 : .9G part #用于root分区

分区格式化

将sdb1和sdb3格式化为ext4文件系统。

  1. mkfs -v -t ext4 /dev/sdb1;mkfs -v -t ext4 /dev/sdb3

设置swap分区,格式化/dev/sdb2为swap格式

  1. [root@localhost ~]# mkswap /dev/sdb2
  2. Setting up swapspace version , size = KiB
  3. no label, UUID=bb9ea40d--4f0c-be3f-dde08974637d

启动swap分区

  1. swapon /dev/sdb2
  1. [root@localhost ~]# swapon -s
  2. Filename Type Size Used Priority
  3. /dev/dm- partition -
  4. /dev/sdb2 partition -

创建环境变量

在构建LFS的过程中,$LFS作为根分区挂载点会多次用到,应该确保在整个构建过程中$LFS都是可用的。

  1. [root@localhost ~]# export LFS=/mnt/lfs
  2. [root@localhost ~]# echo $LFS
  3. /mnt/lfs
  4. [root@localhost ~]# mkdir -pv $LFS
  5. mkdir: created directory ‘/mnt/lfs

在/root/.bash_profile文家最后添加export LFS=/mnt/lfs,使LFS这个环境变量永久化。最终结果如下

  1. [root@localhost ~]# cat .bash_profile
  2. # .bash_profile
  3.  
  4. # Get the aliases and functions
  5. if [ -f ~/.bashrc ]; then
  6. . ~/.bashrc
  7. fi
  8.  
  9. # User specific environment and startup programs
  10.  
  11. PATH=$PATH:$HOME/bin
  12.  
  13. export PATH
  14. export LFS=/mnt/lfs

检查环境变量

  1. [root@localhost ~]# env | grep LFS
  2. LFS=/mnt/lfs

挂载新分区

分区创建好了,文件系统也指定好了。通过为分区指定一个挂载点,来使这个指定文件系统的分区变得可访问。

将sdb3挂载到$LFS变量下,sdb1挂载到$LFS/boot

  1. [root@localhost ~]# mount -v -t ext4 /dev/sdb3 $LFS
  2. mount: /mnt/lfs does not contain SELinux labels.
  3. You just mounted an file system that supports labels which does not
  4. contain labels, onto an SELinux box. It is likely that confined
  5. applications will generate AVC messages and not be allowed access to
  6. this file system. For more details see restorecon() and mount().
  7. mount: /dev/sdb3 mounted on /mnt/lfs.
  8. [root@localhost ~]# mkdir -pv $LFS/boot
  9. mkdir: created directory ‘/mnt/lfs/boot
  10. [root@localhost ~]# mount -v -t ext4 /dev/sdb1 $LFS/boot
  11. mount: /mnt/lfs/boot does not contain SELinux labels.
  12. You just mounted an file system that supports labels which does not
  13. contain labels, onto an SELinux box. It is likely that confined
  14. applications will generate AVC messages and not be allowed access to
  15. this file system. For more details see restorecon() and mount().
  16. mount: /dev/sdb1 mounted on /mnt/lfs/boot.
  1. [root@localhost ~]# lsblk /dev/sdb -f
  2. NAME FSTYPE LABEL UUID MOUNTPOINT
  3. sdb
  4. ├─sdb1 ext4 1bd2b5b6-a818-42f5-bc54-145327b832ab /mnt/lfs/boot
  5. ├─sdb2 swap bb9ea40d--4f0c-be3f-dde08974637d [SWAP]
  6. └─sdb3 ext4 7f28d393-1ede-4f33-b97d-f8defe148c2e /mnt/lfs

为确保下次重启后挂载点仍可用,需要编辑/etc/fstab。swap分区不用修改fstab,他连挂载点都没有,怎么修改呢??

  1. [root@localhost ~]# cat /etc/fstab
  2.  
  3. #
  4. # /etc/fstab
  5. # Created by anaconda on Fri Oct ::
  6. #
  7. # Accessible filesystems, by reference, are maintained under '/dev/disk'
  8. # See man pages fstab(), findfs(), mount() and/or blkid() for more info
  9. #
  10. /dev/mapper/centos-root / xfs defaults
  11. UUID=783b3030-8ead-4ad3-99d9-5ee1403779f0 /boot xfs defaults
  12. /dev/mapper/centos-home /home xfs defaults
  13. /dev/mapper/centos-swap swap swap defaults
  14. /dev/sdb1 /mnt/lfs/boot ext4 defaults
  15. /dev/sdb2 swap swap defaults
  16. /dev/sdb3 /mnt/lfs ext4 defaults

重启检查配置好的Host

  1. [root@localhost ~]# swapon -s
  2. Filename Type Size Used Priority
  3. /dev/sdb2 partition -
  4. /dev/dm- partition -
  5. [root@localhost ~]# mount | grep sdb -i | column -t
  6. /dev/sdb3 on /mnt/lfs type ext4 (rw,relatime,seclabel,data=ordered)
  7. /dev/sdb1 on /mnt/lfs/boot type ext4 (rw,relatime,seclabel,data=ordered)
  8. [root@localhost ~]# env | grep lfs -i
  9. LFS=/mnt/lfs

由于swap分区没有挂载点,因此在mount下看不着。

下载包和补丁

包和补丁存放在$LFS/sources目录下

创建sources目录

  1. mkdir -v $LFS/sources

修改权限(使sources目录仅能被owner和root删除)

  1. [root@localhost ~]# ll $LFS
  2. total
  3. drwxr-xr-x. root root Dec : boot
  4. drwx------. root root Dec : lost+found
  5. drwxr-xr-x. root root Dec : sources
  6. [root@localhost ~]# chmod -v a+wt $LFS/sources
  7. mode of ‘/mnt/lfs/sources changed from (rwxr-xr-x) to (rwxrwxrwt)
  8. [root@localhost ~]# ll $LFS
  9. total
  10. drwxr-xr-x. root root Dec : boot
  11. drwx------. root root Dec : lost+found
  12. drwxrwxrwt. root root Dec : sources

下载wget-list文件,这里面包含各种包的链接。千万注意你的LFS版本,http://www.linuxfromscratch.org/lfs/view下面找你对应版本的wget-list文件。由于官方的wget-list部分链接失效,我修改了部分连接

  1. https://download-mirror.savannah.gnu.org/releases/acl/acl-2.2.52.src.tar.gz
  2. https://download-mirror.savannah.gnu.org/releases/attr/attr-2.4.47.src.tar.gz
  3. http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.xz
  4. http://ftp.gnu.org/gnu/automake/automake-1.15.tar.xz
  5. http://ftp.gnu.org/gnu/bash/bash-4.3.30.tar.gz
  6. http://alpha.gnu.org/gnu/bc/bc-1.06.95.tar.bz2
  7. http://ftp.gnu.org/gnu/binutils/binutils-2.27.tar.bz2
  8. http://ftp.gnu.org/gnu/bison/bison-3.0.4.tar.xz
  9. http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
  10. http://sourceforge.net/projects/check/files/check/0.10.0/check-0.10.0.tar.gz
  11. http://ftp.gnu.org/gnu/coreutils/coreutils-8.25.tar.xz
  12. http://dbus.freedesktop.org/releases/dbus/dbus-1.10.10.tar.gz
  13. http://ftp.gnu.org/gnu/dejagnu/dejagnu-1.6.tar.gz
  14. http://ftp.gnu.org/gnu/diffutils/diffutils-3.5.tar.xz
  15. http://dev.gentoo.org/~blueness/eudev/eudev-3.2.tar.gz
  16. http://downloads.sourceforge.net/project/e2fsprogs/e2fsprogs/v1.43.1/e2fsprogs-1.43.1.tar.gz
  17. http://prdownloads.sourceforge.net/expat/expat-2.2.0.tar.bz2
  18. http://prdownloads.sourceforge.net/expect/expect5.45.tar.gz
  19. ftp://ftp.astron.com/pub/file/file-5.28.tar.gz
  20. http://ftp.gnu.org/gnu/findutils/findutils-4.6.0.tar.gz
  21. https://src.fedoraproject.org/lookaside/pkgs/flex/flex-2.6.1.tar.xz/cd3c86290fc2676a641aefafeb10848a/flex-2.6.1.tar.xz
  22. http://ftp.gnu.org/gnu/gawk/gawk-4.1.3.tar.xz
  23. http://ftp.gnu.org/gnu/gcc/gcc-6.2.0/gcc-6.2.0.tar.bz2
  24. http://ftp.gnu.org/gnu/gdbm/gdbm-1.12.tar.gz
  25. http://ftp.gnu.org/gnu/gettext/gettext-0.19.8.1.tar.xz
  26. http://ftp.gnu.org/gnu/glibc/glibc-2.24.tar.xz
  27. http://ftp.gnu.org/gnu/gmp/gmp-6.1.1.tar.xz
  28. http://ftp.gnu.org/gnu/gperf/gperf-3.0.4.tar.gz
  29. http://ftp.gnu.org/gnu/grep/grep-2.25.tar.xz
  30. http://ftp.gnu.org/gnu/groff/groff-1.22.3.tar.gz
  31. http://alpha.gnu.org/gnu/grub/grub-2.02~beta3.tar.xz
  32. http://ftp.gnu.org/gnu/gzip/gzip-1.8.tar.xz
  33. http://anduin.linuxfromscratch.org/LFS/iana-etc-2.30.tar.bz2
  34. http://ftp.gnu.org/gnu/inetutils/inetutils-1.9.4.tar.xz
  35. http://launchpad.net/intltool/trunk/0.51.0/+download/intltool-0.51.0.tar.gz
  36. https://www.kernel.org/pub/linux/utils/net/iproute2/iproute2-4.7.0.tar.xz
  37. https://www.kernel.org/pub/linux/utils/kbd/kbd-2.0.3.tar.xz
  38. https://www.kernel.org/pub/linux/utils/kernel/kmod/kmod-23.tar.xz
  39. http://www.greenwoodsoftware.com/less/less-481.tar.gz
  40. http://www.linuxfromscratch.org/lfs/downloads/7.10/lfs-bootscripts-20150222.tar.bz2
  41. https://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/libcap-2.25.tar.xz
  42. https://download-mirror.savannah.gnu.org/releases/libpipeline/libpipeline-1.4.1.tar.gz
  43. http://ftp.gnu.org/gnu/libtool/libtool-2.4.6.tar.xz
  44. https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.7.2.tar.xz
  45. http://ftp.gnu.org/gnu/m4/m4-1.4.17.tar.xz
  46. http://ftp.gnu.org/gnu/make/make-4.2.1.tar.bz2
  47. https://download-mirror.savannah.gnu.org/releases/man-db/man-db-2.7.5.tar.xz
  48. https://www.kernel.org/pub/linux/docs/man-pages/man-pages-4.07.tar.xz
  49. https://ftp.gnu.org/gnu/mpc/mpc-1.0.3.tar.gz
  50. http://www.mpfr.org/mpfr-3.1.4/mpfr-3.1.4.tar.xz
  51. http://ftp.gnu.org/gnu//ncurses/ncurses-6.0.tar.gz
  52. http://ftp.gnu.org/gnu/patch/patch-2.7.5.tar.xz
  53. http://www.cpan.org/src/5.0/perl-5.24.0.tar.bz2
  54. https://pkg-config.freedesktop.org/releases/pkg-config-0.29.1.tar.gz
  55. http://sourceforge.net/projects/procps-ng/files/Production/procps-ng-3.3.12.tar.xz
  56. http://downloads.sourceforge.net/project/psmisc/psmisc/psmisc-22.21.tar.gz
  57. http://ftp.gnu.org/gnu/readline/readline-6.3.tar.gz
  58. http://ftp.gnu.org/gnu/sed/sed-4.2.2.tar.bz2
  59. http://ftp.lfs-matrix.net/pub/blfs/conglomeration/shadow/shadow-4.2.1.tar.xz
  60. http://www.infodrom.org/projects/sysklogd/download/sysklogd-1.5.1.tar.gz
  61. http://anduin.linuxfromscratch.org/sources/other/systemd/systemd-231.tar.xz
  62. https://download-mirror.savannah.gnu.org/releases/sysvinit/sysvinit-2.88dsf.tar.bz2
  63. http://ftp.gnu.org/gnu/tar/tar-1.29.tar.xz
  64. http://sourceforge.net/projects/tcl/files/Tcl/8.6.6/tcl-core8.6.6-src.tar.gz
  65. http://ftp.gnu.org/gnu/texinfo/texinfo-6.1.tar.xz
  66. http://www.iana.org/time-zones/repository/releases/tzdata2016f.tar.gz
  67. http://anduin.linuxfromscratch.org/LFS/udev-lfs-20140408.tar.bz2
  68. https://www.kernel.org/pub/linux/utils/util-linux/v2.28/util-linux-2.28.1.tar.xz
  69. ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
  70. http://cpan.metacpan.org/authors/id/T/TO/TODDR/XML-Parser-2.44.tar.gz
  71. http://tukaani.org/xz/xz-5.2.2.tar.xz
  72. https://zlib.net/fossils/zlib-1.2.8.tar.gz
  73. http://www.linuxfromscratch.org/patches/lfs/7.10/bash-4.3.30-upstream_fixes-3.patch
  74. http://www.linuxfromscratch.org/patches/lfs/7.10/bc-1.06.95-memory_leak-1.patch
  75. http://www.linuxfromscratch.org/patches/lfs/7.10/bzip2-1.0.6-install_docs-1.patch
  76. http://www.linuxfromscratch.org/patches/lfs/7.10/coreutils-8.25-i18n-2.patch
  77. http://www.linuxfromscratch.org/patches/lfs/7.10/glibc-2.24-fhs-1.patch
  78. http://www.linuxfromscratch.org/patches/lfs/7.10/kbd-2.0.3-backspace-1.patch
  79. http://www.linuxfromscratch.org/patches/lfs/7.10/readline-6.3-upstream_fixes-3.patch
  80. http://www.linuxfromscratch.org/patches/lfs/7.10/sysvinit-2.88dsf-consolidated-1.patch

下载包和补丁,比较耗时,有的包可能超时下载不了。下载完毕后共80个包(算上补丁)

  1. wget --input-file=wget-list --continue --directory-prefix=$LFS/sources

准备临时系统环境

创建临时目录

编译LFS过程中会生成很多临时工具,这些工具不会最终成为LFS系统的一部分。为临时工具指定目录$LFS/tools,一方面用完之后可以直接删掉而不会影响系统,另一方面防止临时根据影响系统其他目录。

  1. mkdir -v $LFS/tools

为tools目录创建符号链接

  1. [root@localhost lfs]# ln -sv $LFS/tools /
  2. ‘/tools -> ‘/mnt/lfs/tools

添加lfs用户

root用户随便犯个小错误都有可能破坏或摧毁整个系统,因此在编译上文提到的包和补丁时最好使用lfs用户。同时为lfs用户环境做些限制,尽量避免host对其影响。

  1. groupadd lfs
  2. useradd -s /bin/bash -g lfs -m -k /dev/null lfs
  3. 命令行选项的意思:
  4. -s /bin/bash bash 设置为 lfs 用户的默认 shell
  5. -g lfs 这个选项将用户lfs 添加到组 lfs 中。
  6. -m lfs 用户创建主目录。
  7. -k /dev/null 这个参数通过令输入位置为null设备,防止可能从一个skeleton目录中(默认是/etc/skel )复制文件。
  8. lfs 这是创建的组和用户的实际名称。

为lfs设置密码

  1. passwd lfs

更改sources、tools的属主

  1. chown -v lfs $LFS/tools
  2. chown -v lfs $LFS/sources

如果想要切换到lfs用户可使用命令。su -除了切换用户身份外,shell也会切换为登陆shell。参考:Linux命令——su 、su -、sudo

  1. su - lfs

修改lfs用户shell环境

当以lfs用户登陆时,通常是个登陆shell。这个登陆shell需要先读取2个配置文件的配置信息:host的/etc/profile 和 lfs用户.bash_profile

修改.bash_profile,表明除HOME 、TERM 和 PS1 变量环境变量按设置保留外,其他环境变量全部清空。为啥这么做?因为host的/etc/profile可能之前被写入了部分环境变量,这些环境变量可能会加载到lfs用户这里进而污染lfs的shell环境。

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

对于一个shell instance,通常是non-login shell,这种shell不读取/etc/profile 或 .bash_profile文件,而是读取.bashrc文件。创建或修改.bashrc文件如下

  1. cat > ~/.bashrc << "EOF"
  2. set +h
  3. umask
  4. LFS=/mnt/lfs
  5. LC_ALL=POSIX
  6. LFS_TGT=$(uname -m)-lfs-linux-gnu
  7. PATH=/tools/bin:/bin:/usr/bin
  8. export LFS LC_ALL LFS_TGT PATH
  9. EOF

set +h 命令关闭了 bash 的哈希功能。hash可以加快命令查找速度,但是这对于编译LFS不是啥好事。由于我们前面对tools做过软连接,取消hash可以强制每次查找命令时都从$PATH查找,这样tools下面一旦某些根据可用就能马上被系统用上。

LFS用于设置挂载点

source命令加载下配置文件,使修改生效

  1. source ~/.bash_profile

说明

SBU

Standard Build Unit(标准编译单位)指代具体的编译时间。这里以编译Binutils所用时间作为一个标准编译单位(SBU),其它软件的生成时间都以其为标准进行比较。

Test Suites

测试套件由于帮助我们“检查”软件编译是否正确,出软件包的功能是否都如开发人员预想的那样正常。但是,它并不能总是保证所测试的软件包就一定没有问题。在编译临时工具的时候不建议使用测试套件

LFS7.10——准备Host系统的更多相关文章

  1. LFS7.10——构建LFS系统

    参考:LFS7.10——准备Host系统 LFS7.10——构造临时Linux系统 本文正式开始构建LFS系统,后面所有命令的执行都是在root用户下完成的. 这时开始构建LFS前准备工作 更改$LF ...

  2. LFS7.10——构造临时Linux系统

    参考:LFS编译——准备Host系统 前言 在准备好Host环境后,接下来构造一个临时Linux系统.该系统包含****构建所需要的工具.构造临时Linux系统分两步: 构建一个宿主系统无关的新工具链 ...

  3. Windows 10 安装双系统 CentOS 7

    系统环境:Windows 10 && CentOS 7 准备工具: ●CentOS7 官网下载地址:https://wiki.centos.org/Download (注意: i386 ...

  4. windows10 下访问 virtualbox 虚拟机的linux15.10/16.04 系统 及 用 putty 访问虚拟机的配置

    参考: http://www.doc88.com/p-915707596190.html --- 安装samba http://my.oschina.net/u/2260265/blog/405598 ...

  5. Ubuntu 14.10 下查看系统硬件信息(实例详解)

    linux查看系统的硬件信息,并不像windows那么直观,这里我罗列了查看系统信息的实用命令,并做了分类,实例解说. cpu lscpu命令,查看的是cpu的统计信息. blue@blue-pc:~ ...

  6. VMWare 14.1 15 Pro 安装 macOS Mojave 10.14.1系统 遇到的问题解决方案

    安装环境 WIN10VMware Workstation Pro 15.0.0 Build 10134415工具准备1.VMware Workstation Pro 15.0.0 Build 1013 ...

  7. Linux笔记(二): WIN 10 Ubuntu 双系统

    (一)  说明 记录一次ubuntu安装过程及遇到的问题. 环境:WIN 10 单硬盘 (二)  ubuntu ISO文件下载 ubuntu 18.04 https://www.ubuntu.com/ ...

  8. 在windows 10 64位系统下安装TensorFlow

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/mao_hui_fei/article/de ...

  9. Mac 10.14.5系统偏好设置安全性与隐私不展示任何来源解决办法

    Mac新系统升级(10.14.5)后未从appstore下载的软件在安装时会提示安装包已损坏之类的东东,这是因为没有打开“设置”—“安全与隐私”中的“任何来源”造成的,可是升级后的10.14.5却没有 ...

随机推荐

  1. 系统重装之认识UEFI

    UEFI是一种新型的引导方式?他与传统的BIOS引导不同,传统BIOS引导需要经过(开机→BIOS初始化→BIOS自检→引导系统→进入系统)五个步骤来完成引导操作,UEFI只需要(开机→UEFI初始化 ...

  2. 解决端口被占用问题(端口timewait)

    当jmeter做千级并发时,有报错的接口,查看是不是本地端口被占用完了 netstat -an   查看是否有端口在 timewait timewait是知道用那个端口,但是端口被别人占用着 见tcp ...

  3. 关于PLSQL配置了正确的Oracle客户端但是不能识别tnsnames.ora问题

    场景描述: 在通过安装Oracle客户端使用PLSQL的时候发现PLSQL在已经正常配置了Oracle Home和Ocdi library的情况下不能识别tnsnames.ora中的有效配置. 正常安 ...

  4. [LeetCode] 240. Search a 2D Matrix II 搜索一个二维矩阵 II

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  5. [LeetCode] 655. Print Binary Tree 打印二叉树

    Print a binary tree in an m*n 2D string array following these rules: The row number m should be equa ...

  6. GenericObjectPool

    commons-pool2源码走读(四) 对象池实现GenericObjectPool 2018年05月27日 18:24:56 蓝墨49 阅读数 1787   版权声明:本文为博主原创文章,遵循CC ...

  7. sonar:默认的扫描规则

    https://blog.csdn.net/liumiaocn/article/details/83550309 https://note.youdao.com/ynoteshare1/index.h ...

  8. 【机器学习之二】python开发spark案例

    环境 spark-1.6 python3.5 一.wordcount # -*- coding:utf-8 -*- ''' Created on 2019年5月13日 @author: Adminis ...

  9. Django文档阅读之模型

    模型 模型是您的数据唯一而且准确的信息来源.它包含您正在储存的数据的重要字段和行为.一般来说,每一个模型都映射一个数据库表. 基础: 每个模型都是一个 Python 的类,这些类继承 django.d ...

  10. POJ 1014 Dividing(入门例题一)

    Time Limit: 1000MS Memory Limit: 10000K Total Submissions: Accepted: Description Marsha and Bill own ...