一目了然系列之 Centos7 ALFS 自动化构建 LFS 8.0

0x00 介绍

相信大家做了那么半天的 LFS 都很累了是吧?今天新开一期 关于 LFS 的系列,这次用 ALFS 来做,这是一个自动话脚本,编译工具链和基础软件的编译这些部分的工作都由 ALFS 这个工具自动去,但是这个工具好在于自动化去做,坏也在于此。如果没做过 LFS 那这个没啥实际的意义,能够收获的只有引导部分的内容,能够了解 linux 的一个基本的组成。下面我就来说说具体该怎么做。这里我有参考到陈涛老师发布过的这方面的视频,原版的视频有 4 个,但是实际上现在还能看只有 3 个,所以参考意义对于初学者来说意义不大了。这里我修正了几个参考的文档中间的错误,让实验能够一次性的成功。下面我们开始动手做。ALFS 是 LFS 官方推出的一个项目,与 LFS 项目平行。官方地址 http://www.linuxfromscratch.org/alfs/

0x01 准备工作

任何事情都是一样先要把准备的工作做好,有了基本的条件了在做一些东西就方便的多了说说需要准备的东西。这里说一下,一直有人问我 linux 的命令的问题,这次我直接贴出来敲的命令还有返回的结果。这样一目了然,这里拿个例子来说一下,容易看,初学者好些时候不成功就是因为不知是在 root 下做,还是在普通的用户下面做。我写的#开头的带文字的内容都是注释。在 shell 里面 # 开头就是注释。

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 
# [root@localhost ~]# cat /etc/redhat-release 
# [root@localhost ~]
# root 是 用户名,这里用的是root
# localhost 是本地
# ~ 代表的目录是哪里,~ 代表当前用户的 home 目录
# # 代表是用的 root 账户,普通用户是 ~
# cat /etc/redhat-release  这是执行的命令
# CentOS Linux release 7.6.1810 (Core)  这是返回的结果

操作系统

这里我采用了 Centos 7 mini 安装,安装centos 7 的时候要空一部分空间出来不用留着给 ALFS 使用,安装的时候采用 ext4 不采用 LVM。

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

内核默认的

[root@localhost ~]# uname -a
Linux localhost.localdomain 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

默认安装的软件 可以看我的 LFS 这篇帖子 基础环境是一样的我就不复制粘贴了,这样没什么意义,我给大家说说不一样的东西就好了,其他的参考之前这个帖子就好了,Centos 7 安装 LFS 系统基础软件。我是按 LFS 8.4 准备的基础软件,亲测没有任何问题,可以用 ALFS 正常编译出来 LFS 8.0 .

安装几个 ALFS 必备的软件

yum -y install libxslt subversion ncurses-devel 

分区准备

我的分区依旧是用的一块硬盘 /dev/sda1 是 centos7 的根目录,/dev/sda2 是 swap。/dev/sda3 作为 ALFS 的根目录, /dev/sda4 作为 ALFS 的 swap。这样一个规划,sda3 用的 ext4 分区 30 G 大小,sda4 swap 4G 大小。

处理硬盘分区

[root@localhost ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n

# n 创建新分区

Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p

# 创建一个主分区

Partition number (3,4, default 3): 
First sector (2048-250069679, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104859647, default 104859647): +30G

# 做一个 30G 空间的分区

Partition 3 of type Linux and of size 30 GiB is set

Command (m for help): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): p

# 主分区做多只能有 4 个,再多就得使用扩展分区,在里面分出来逻辑分区

Selected partition 4
First sector (62916608-250069679, default 62916608): 
Using default value 62916608
Last sector, +sectors or +size{K,M,G} (62916608-104859647, default 104859647): +4G
Partition 4 of type Linux and of size 4 GiB is set

Command (m for help): w

# 写操作,把前面的操作写入分区表

The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.

[root@localhost ~]# partprobe 
# 更新分区表

做完分区以后,要 partprobe 来更新分区表,这样才能看见新分出来的 sda3 sda4分区。

格式化分区 sda3 和 swap

[root@localhost ~]# mkfs.ext4 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1966080 inodes, 7864320 blocks
393216 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2155872256
240 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   



[root@localhost ~]# mkswap /dev/sda4
mkswap: /dev/sda4: warning: don't erase bootbits sectors
        (dos partition table detected). Use -f to force.
Setting up swapspace version 1, size = 4194300 KiB
no label, UUID=6db3d3fb-eb2d-41e3-97b0-84e9e82a0d9c

分区挂载

创建文件夹 ALFS 下默认是 /mnt/build_dir

[root@localhost ~]# mkdir -pv /mnt/build_dir
mkdir: created directory ‘/mnt/build_dir’

更改宿主的 fstab 挂载 sda3 分区

vim /etc/fstab 
# 在最下面写上一行
/dev/sda3                                 /mnt/build_dir                ext4    defaults        0 0

然后测试一下

[root@localhost ~]# mount -a
# lsblk 可以查看挂载的情况
[root@localhost ~]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 119.2G  0 disk 
├─sda1   8:1    0    50G  0 part /
├─sda2   8:2    0     4G  0 part [SWAP]
├─sda3   8:3    0    30G  0 part /mnt/build_dir
└─sda4   8:4    0     4G  0 part 
[root@localhost ~]# 

设置环境变量

编辑 root 用户的环境变量

[root@localhost ~]# vim .bash_profile
# 在最后写入
export LFS=/mnt/build_dir

创建账户并配置

因为 ALFS 在编译的时候不能用 root 用户来做需要使用一个普通的账户来实现编译,但是在过程中会用到 sudo 来临时提取 root 权限,这里我们新建一个账户,改变一下配置文件,让它不需要输入密码来自动化(这个操作是官方的 ALFS 文档里面没有的)。这里我建一个 test 用户

[root@localhost ~]#  useradd test
# 创建用户 test
[root@localhost ~]# passwd test
# 给 test 加密码,我加的是一个一位数的弱密码,所以会有下面 BAD PASSWORD 的提示
Changing password for user test.
New password: 
BAD PASSWORD: The password is a palindrome
Retype new password: 
passwd: all authentication tokens updated successfully.

test用户 sudo 无密码。

[root@localhost ~]# echo "test ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

切换到 test

[root@localhost ~]# su - test
[test@localhost ~]$ 
# 此时用户已经变成了 test

添加环境变量

[test@localhost ~]$ echo "export LFS=/mnt/build_dir" >> .bash_profile 

[test@localhost ~]$ source .bash_profile 
# 加载新写入的环境变量

# 验证一下
[test@localhost ~]$ echo $LFS
/mnt/build_dir


准备内核

这里我们让 ALFS 自动帮我们把内核编译好,这里就需要先做好了 内核的 config 文件,在 LFS 的文章里面说了,我们先不具体说内核的配置方法,后面会有一片详解。这里先采用默认的配置,让内核能够跑起来就可以。

下载内核文件

[test@localhost ~]$ wget https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.9.9.tar.xz

默认配置内核

[test@localhost linux-4.9.9]$ make defconfig

[test@localhost linux-4.9.9]$ make menuconfig
# 确保这项添加好
Device Drivers  --->
  Generic Driver Options  --->
   [ ] Support for uevent helper [CONFIG_UEVENT_HELPER]
   [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS]

[test@localhost linux-4.9.9]$ cp .config  ~/config-x86_64-4.9.9
# 导出配置文件

编辑 fstab 切记这个 fstab 与 LFS 8.4 的不一样

[test@localhost ~]$ sudo vim fstablfs
# 写入下面的内容保存

# Begin /etc/fstab

# file system  mount-point  type     options             dump  fsck
#                                                              order
/dev/sda3     /             ext4    defaults            1     1

/dev/sda4     swap         swap     pri=1               0     0
proc           /proc        proc     nosuid,noexec,nodev 0     0
sysfs          /sys         sysfs    nosuid,noexec,nodev 0     0
devpts         /dev/pts     devpts   gid=5,mode=620      0     0
tmpfs          /run         tmpfs    defaults            0     0
devtmpfs       /dev         devtmpfs mode=0755,nosuid    0     0

# End /etc/fstab

下载 LFS 8.0 软件源代码

[test@localhost ~]$ wget http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/lfs-packages-8.0.tar

准备ALFS文件

[test@localhost ~]$ svn co svn://svn.linuxfromscratch.org/LFS/tags/8.0
# 下载 LFS Book
[test@localhost ~]$ mv 8.0/ lfsbook/
# 下载好的改名为 lfsbook
sed -i 's/7ee67b16b345b43cd34ed481792169ed/3cb3d36089f2d6ab19c7c0f3282de1c5/g' ~/lfsbook/packages.ent

# 进入 lfsbook 文件夹,修改packages.ent文件中lfs-bootscripts-20150222.tar.bz2的md5值
# 7ee67b16b345b43cd34ed481792169ed 是错误的 修改为:3cb3d36089f2d6ab19c7c0f3282de1c5
# 这个值在下载好的源码的 md5sums 这个文件里面有

[test@localhost ~]$ tar xf lfs-packages-8.0.tar 
# 解压所有程序的源码 这个解压完名字就是 8.0 的一个文件夹
[test@localhost ~]$ wget http://www.linuxfromscratch.org/alfs/downloads/jhalfs/stable/jhalfs-2.4.tar.xz

# 下载文件

[test@localhost ~]$ tar xf jhalfs-2.4.tar.xz 
[test@localhost ~]$ cd jhalfs-2.4
# 开始设置

[test@localhost jhalfs-2.4]$ sudo make

BOOK Settings  ---> Release (Working Copy)  ---> (X) Working Copy  
BOOK Settings  ---> Release (Working Copy)  ---> Loc of working copy (mandatory) (/home/test/lfsbook)
# lfs 书的位置,先删除再写入,那块有 edit me 的字样
General Settings  --->[*] Retrieve source files   Package Archive Directory (/home/test/8.0) 
# 下载好的解压完了的源码的位置
General Settings  --->[*] Rebuild files  
# 每次都会重新清理目录 /mnt/build_dir

Build Settings  --->    [ ] Run testsuites   
Build Settings  --->    [*] Create a log of installed files for each package 
Build Settings  --->    [*] Use a custom fstab file                                                 
Build Settings  --->    Fstab file (optional) (/home/test/fstablfs) 
# 之前
Build Settings  --->       [*] Build the kernel 
Build Settings  --->         Kernel config file (/home/test/config-x86_64-4.99) 
Build Settings  --->   [*] Install vim-lang package 
Build Settings  --->       TimeZone (Asia/Shanghai)  
Build Settings  --->   [*] Install the full set of locales



# using defaults found in configuration
#

*** End of JHALFS configuration.
Loading config params from <configuration>...OK
Loading common-functions module...
Loading <func_book_parser>...OK
Loading <func_download_pkgs>...OK
Loading <func_wrt_Makefile>...OK
    ...OK
Loading code module <LFS/master.sh>...OK
------------------------------------------------------------------------------

Loading function <func_check_version.sh>...OK
Loading function <func_validate_configs.sh>...OK
Loading function <func_custom_pkgs>...OK
------------------------------------------------------------------------------

Checking tools required for jhalfs
SUDO.............. <1.8.23>              OK (Min version: 1.7.0)
WGET.............. <1.14>                OK (Min version: 1.0.0)
LIBXML2........... <2.09.01>             OK (Min version: 2.06.20)
LIBXSLT........... <1.01.28>             OK (Min version: 1.01.14)
------------------------------------------------------------------------------

BOOK.............. </home/test/lfsbook>
CUSTOM_TOOLS...... <n>
INITSYS........... <sysv>
BLFS_TOOL......... <n>
LUSER............. <lfs>
LGROUP............ <lfs>
LHOME............. </home>
BUILDDIR.......... </mnt/build_dir>
CLEAN............. <y>
GETPKG............ <y>
SRC_ARCHIVE....... </home/test/8.0>
SERVER............ <http://ftp.osuosl.org>
RETRYSRCDOWNLOAD.. <>
RETRYDOWNLOADCNT.. <20>
DOWNLOADTIMEOUT... <30>
RUNMAKE........... <n>
TEST.............. <1>
BOMB_TEST......... <n>
STRIP............. <n>
VIMLANG........... <y>
FSTAB............. </home/test/fstablfs>
CONFIG............ </home/test/config-x86_64-4.9.9>
TIMEZONE.......... <Asia/Shanghai>
PAGE.............. <A4>
LANG.............. <en_US.UTF-8>
INSTALL_LOG....... <y>
PKGMNGT........... <n>
FULL_LOCALE....... <y>
COMPARE........... <n>
OPTIMIZE.......... <0>
REPORT............ <n>
REBUILD_MAKEFILE.. <n>

*** lfs config parameters look good ***

------------------------------------------------------------------------------

Are you happy with these settings? yes/no (no): yes

------------------------------------------------------------------------------

Using /home/test/lfsbook as book's sources ...
Extracting commands for <LFS> build... done
Creating <lfs> list of tarball names for /home/test/lfsbook... done
Creating chroot commands scripts from /home/test/lfsbook... done
Creating LFS specific URLs file ...OK
acl-2.2.52.src.tar.gz: -- copied from /home/test/8.0
attr-2.4.47.src.tar.gz: -- copied from /home/test/8.0
autoconf-2.69.tar.xz: -- copied from /home/test/8.0
automake-1.15.tar.xz: -- copied from /home/test/8.0
bash-4.4.tar.gz: -- copied from /home/test/8.0
bc-1.06.95.tar.bz2: -- copied from /home/test/8.0
binutils-2.27.tar.bz2: -- copied from /home/test/8.0
bison-3.0.4.tar.xz: -- copied from /home/test/8.0
bzip2-1.0.6.tar.gz: -- copied from /home/test/8.0
check-0.11.0.tar.gz: -- copied from /home/test/8.0
coreutils-8.26.tar.xz: -- copied from /home/test/8.0
dejagnu-1.6.tar.gz: -- copied from /home/test/8.0
diffutils-3.5.tar.xz: -- copied from /home/test/8.0
eudev-3.2.1.tar.gz: -- copied from /home/test/8.0
e2fsprogs-1.43.4.tar.gz: -- copied from /home/test/8.0
expat-2.2.0.tar.bz2: -- copied from /home/test/8.0
expect5.45.tar.gz: -- copied from /home/test/8.0
file-5.30.tar.gz: -- copied from /home/test/8.0
findutils-4.6.0.tar.gz: -- copied from /home/test/8.0
flex-2.6.3.tar.gz: -- copied from /home/test/8.0
gawk-4.1.4.tar.xz: -- copied from /home/test/8.0
gcc-6.3.0.tar.bz2: -- copied from /home/test/8.0
gdbm-1.12.tar.gz: -- copied from /home/test/8.0
gettext-0.19.8.1.tar.xz: -- copied from /home/test/8.0
glibc-2.25.tar.xz: -- copied from /home/test/8.0
gmp-6.1.2.tar.xz: -- copied from /home/test/8.0
gperf-3.0.4.tar.gz: -- copied from /home/test/8.0
grep-3.0.tar.xz: -- copied from /home/test/8.0
groff-1.22.3.tar.gz: -- copied from /home/test/8.0
grub-2.02~beta3.tar.xz: -- copied from /home/test/8.0
gzip-1.8.tar.xz: -- copied from /home/test/8.0
iana-etc-2.30.tar.bz2: -- copied from /home/test/8.0
inetutils-1.9.4.tar.xz: -- copied from /home/test/8.0
intltool-0.51.0.tar.gz: -- copied from /home/test/8.0
iproute2-4.9.0.tar.xz: -- copied from /home/test/8.0
kbd-2.0.4.tar.xz: -- copied from /home/test/8.0
kmod-23.tar.xz: -- copied from /home/test/8.0
less-481.tar.gz: -- copied from /home/test/8.0
lfs-bootscripts-20150222.tar.bz2: -- copied from /home/test/8.0
libcap-2.25.tar.xz: -- copied from /home/test/8.0
libpipeline-1.4.1.tar.gz: -- copied from /home/test/8.0
libtool-2.4.6.tar.xz: -- copied from /home/test/8.0
linux-4.9.9.tar.xz: -- copied from /home/test/8.0
m4-1.4.18.tar.xz: -- copied from /home/test/8.0
make-4.2.1.tar.bz2: -- copied from /home/test/8.0
man-db-2.7.6.1.tar.xz: -- copied from /home/test/8.0
man-pages-4.09.tar.xz: -- copied from /home/test/8.0
mpc-1.0.3.tar.gz: -- copied from /home/test/8.0
mpfr-3.1.5.tar.xz: -- copied from /home/test/8.0
ncurses-6.0.tar.gz: -- copied from /home/test/8.0
patch-2.7.5.tar.xz: -- copied from /home/test/8.0
perl-5.24.1.tar.bz2: -- copied from /home/test/8.0
pkg-config-0.29.1.tar.gz: -- copied from /home/test/8.0
procps-ng-3.3.12.tar.xz: -- copied from /home/test/8.0
psmisc-22.21.tar.gz: -- copied from /home/test/8.0
readline-7.0.tar.gz: -- copied from /home/test/8.0
sed-4.4.tar.xz: -- copied from /home/test/8.0
shadow-4.4.tar.xz: -- copied from /home/test/8.0
sysklogd-1.5.1.tar.gz: -- copied from /home/test/8.0
sysvinit-2.88dsf.tar.bz2: -- copied from /home/test/8.0
tar-1.29.tar.xz: -- copied from /home/test/8.0
tcl-core8.6.6-src.tar.gz: -- copied from /home/test/8.0
texinfo-6.3.tar.xz: -- copied from /home/test/8.0
tzdata2016j.tar.gz: -- copied from /home/test/8.0
udev-lfs-20140408.tar.bz2: -- copied from /home/test/8.0
util-linux-2.29.1.tar.xz: -- copied from /home/test/8.0
vim-8.0.069.tar.bz2: -- copied from /home/test/8.0
XML-Parser-2.44.tar.gz: -- copied from /home/test/8.0
xz-5.2.3.tar.xz: -- copied from /home/test/8.0
zlib-1.2.11.tar.xz: -- copied from /home/test/8.0
bash-4.4-upstream_fixes-1.patch: -- copied from /home/test/8.0
bc-1.06.95-memory_leak-1.patch: -- copied from /home/test/8.0
bzip2-1.0.6-install_docs-1.patch: -- copied from /home/test/8.0
coreutils-8.26-i18n-1.patch: -- copied from /home/test/8.0
glibc-2.25-fhs-1.patch: -- copied from /home/test/8.0
kbd-2.0.4-backspace-1.patch: -- copied from /home/test/8.0
sysvinit-2.88dsf-consolidated-1.patch: -- copied from /home/test/8.0
------------------------------------------------------------------------------

Creating Makefile... START
    Processing... <Chapter4     ( SETUP ) >
    Processing... <Chapter5     ( LUSER ) >
    Processing... <Chapter6     ( CHROOT ) >
    Processing... <Chapter7/8   ( BOOT ) >
Creating Makefile... DONE
------------------------------------------------------------------------------


KERNEL............ <3.10.0-957.21.3.el7.x86_64> OK (Min version: 2.6.32)
BASH.............. <4.2.46(2)-release>   OK (Min version: 3.2)
GCC............... <4.8.5>               OK (Min version: 4.7)
G++............... <4.8.5>               OK (Min version: 4.7)
GLIBC............. <2.17>                OK (Min version: 2.11)
BINUTILS.......... <2.27-34.base.el7>    OK (Min version: 2.17)
TAR............... <1.26>                OK (Min version: 1.22)
BZIP2............. <1.0.6>               OK (Min version: 1.0.4)
BISON............. <3.0.4>               OK (Min version: 2.3)
COREUTILS......... <8.22>                OK (Min version: 6.9)
DIFF.............. <3.3>                 OK (Min version: 2.8.1)
FIND.............. <4.5.11>              OK (Min version: 4.2.31)
GAWK.............. <4.0.2>               OK (Min version: 4.0.1)
GREP.............. <2.20>                OK (Min version: 2.5.1a)
GZIP.............. <1.5>                 OK (Min version: 1.3.12)
M4................ <1.4.16>              OK (Min version: 1.4.10)
MAKE.............. <4.0>                 OK (Min version: 3.81)
PATCH............. <2.7.1>               OK (Min version: 2.5.4)
PERL.............. <5.16.3>              OK (Min version: 5.8.8)
SED............... <4.2.2>               OK (Min version: 4.1.5)
TEXINFO........... <5.1>                 OK (Min version: 4.7)
XZ................ <5.2.2>               OK (Min version: 5.0.0)
------------------------------------------------------------------------------


<jhalfs> exit

开始安装

这时候会在 /mnt/build_dir 下面新出来一个文件夹,进去 make 就好了

[test@localhost jhalfs]$ cd /mnt/build_dir/jhalfs/
[test@localhost jhalfs]$ make
# 由于之前设置了sudo 的 nopasswd 所以后面不用输密码,很方便
--------------------------------------------------------------------------------
mk_SETUP
ROOT privilege is required to perform a number of commands
sudo will request a password in order to execute all high privilege commands
--------------------------------------------------------------------------------
 Building target 020-creatingtoolsdir

 Target 020-creatingtoolsdir OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 021-addinguser

 Target 021-addinguser OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 022-settingenvironment

 Target 022-settingenvironment OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
mk_LUSER
You are going to log into the user account lfs
sudo requires a password
make: Entering directory '/mnt/build_dir/jhalfs'
--------------------------------------------------------------------------------
 Building target 034-binutils-pass1
 [++++++++++++++++++++++++++++++++++++++|                     ] 1 min. 38 sec
 Target 034-binutils-pass1 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 035-gcc-pass1
 [++++++++++++++++++++++++++++++\                             ] 12 min. 30 sec
 Target 035-gcc-pass1 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 036-linux-headers
 [++++++++++++++++\                                           ] 0 min. 16 sec
 Target 036-linux-headers OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 037-glibc
 [+++++++++++++++++++++++++++++++++++/                        ] 7 min. 35 sec
 Target 037-glibc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 038-gcc-libstdc++
 [++-                                                         ] 1 min. 2 sec
 Target 038-gcc-libstdc++ OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 039-binutils-pass2
 [+++|                                                        ] 2 min. 3 sec
 Target 039-binutils-pass2 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 040-gcc-pass2
 [++++++++++++++++++++++++++++++++++++++\                     ] 18 min. 38 sec
 Target 040-gcc-pass2 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 041-tcl
 [+++++++++++++++++++++++++++++++++++++++++++                 ] 0 min. 42 sec
 Target 041-tcl OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 042-expect
 [++++++++/                                                   ] 0 min. 8 sec
 Target 042-expect OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 043-dejagnu
 [+/                                                          ] 0 min. 1 sec
 Target 043-dejagnu OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 044-check
 [++++++++++++\                                               ] 0 min. 12 sec
 Target 044-check OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 045-ncurses
 [++++++++++++++++++++++++++++++++++++++++++++++++++++++|     ] 0 min. 54 sec
 Target 045-ncurses OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 046-bash
 [++++++++++++++++++++++++++++++++++++++++++++                ] 0 min. 43 sec
 Target 046-bash OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 047-bison
 [++++++++++++++++++++++++++++++++/                           ] 0 min. 32 sec
 Target 047-bison OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 048-bzip2
 [++|                                                         ] 0 min. 2 sec
 Target 048-bzip2 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 049-coreutils
 [++++++++++++++|                                             ] 1 min. 14 sec
 Target 049-coreutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 050-diffutils
 [+++++++++++++++++++++++++++/                                ] 0 min. 27 sec
 Target 050-diffutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 051-file
 [++++++++/                                                   ] 0 min. 8 sec
 Target 051-file OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 052-findutils
 [+++++++++++++++++++++++++++++++++++++++-                    ] 0 min. 39 sec
 Target 052-findutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 053-gawk
 [++++++++++++++++++++++|                                     ] 0 min. 22 sec
 Target 053-gawk OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 054-gettext
 [+++++++++++++++++++++++++++++++++++++++++++|                ] 1 min. 43 sec
 Target 054-gettext OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 055-grep
 [++++++++++++++++++++++\                                     ] 0 min. 22 sec
 Target 055-grep OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 056-gzip
 [++++++++++++++-                                             ] 0 min. 14 sec
 Target 056-gzip OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 057-m4
 [++++++++++++++++++++++                                      ] 0 min. 21 sec
 Target 057-m4 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 058-make
 [+++++++++                                                   ] 0 min. 8 sec
 Target 058-make OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 059-patch
 [++++++++++++++++++++++/                                     ] 0 min. 22 sec
 Target 059-patch OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 060-perl
 [++++++++                                                    ] 2 min. 7 sec
 Target 060-perl OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 061-sed
 [+++++++++++++++++++|                                        ] 0 min. 19 sec
 Target 061-sed OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 062-tar
 [++++++++++++++++++++++++++++++++++++++|                     ] 0 min. 38 sec
 Target 062-tar OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 063-texinfo
 [++++++++++++++++++++|                                       ] 0 min. 20 sec
 Target 063-texinfo OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 064-util-linux
 [++++++++++++++++++++++++++++++++-                           ] 1 min. 32 sec
 Target 064-util-linux OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 065-xz
 [++++++++++++++++++++++++\                                   ] 0 min. 24 sec
 Target 065-xz OK
--------------------------------------------------------------------------------
make: Leaving directory '/mnt/build_dir/jhalfs'
--------------------------------------------------------------------------------
 Building target restore-luser-env

 Target restore-luser-env OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 067-changingowner
 [/                                                           ] 0 min. 0 sec
 Target 067-changingowner OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 069-kernfs
 [/                                                           ] 0 min. 0 sec
 Target 069-kernfs OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
mk_CHROOT
You are going to CHROOT into /mnt/build_dir lfs
a password is required
--------------------------------------------------------------------------------
 Building target 072-creatingdirs
 [/                                                           ] 0 min. 0 sec
 Target 072-creatingdirs OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 073-createfiles
 [/                                                           ] 0 min. 0 sec
 Target 073-createfiles OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 074-linux-headers
 [+++++++++++++++++\                                          ] 0 min. 17 sec
 Target 074-linux-headers OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 075-man-pages
 [++-                                                         ] 0 min. 2 sec
 Target 075-man-pages OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 076-glibc
 [+++++++++++++++++++++++++++++++++++++++++/                  ] 39 min. 41 sec
 Target 076-glibc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 077-adjusting
 [-                                                           ] 0 min. 0 sec
 Target 077-adjusting OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 078-zlib
 [+++++++                                                     ] 0 min. 6 sec
 Target 078-zlib OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 079-file
 [+++++++++/                                                  ] 0 min. 9 sec
 Target 079-file OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 080-binutils
 [  +++++++++++++++++++/                                      ] 10 min. 21 sec
 Target 080-binutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 081-gmp
 [++++++++++++/                                               ] 2 min. 12 sec
 Target 081-gmp OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 082-mpfr
 [++++++++++++++++++++++++|                                   ] 1 min. 24 sec
 Target 082-mpfr OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 083-mpc
 [+++++++++-                                                  ] 0 min. 9 sec
 Target 083-mpc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 084-gcc
 [++++++++++++++++++++++++++++++++++++++++++++++++++          ] 167 min. 49 sec
 Target 084-gcc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 085-bzip2
 [+++++\                                                      ] 0 min. 5 sec
 Target 085-bzip2 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 086-pkg-config
 [+++++++++++++++++++++++++++++++++++++++                     ] 0 min. 38 sec
 Target 086-pkg-config OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 087-ncurses
 [+++++++++++++++++++++++++++++++++++++++++                   ] 0 min. 40 sec
 Target 087-ncurses OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 088-attr
 [+++++\                                                      ] 0 min. 5 sec
 Target 088-attr OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 089-acl
 [++++++++|                                                   ] 0 min. 8 sec
 Target 089-acl OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 090-libcap
 [++\                                                         ] 0 min. 2 sec
 Target 090-libcap OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 091-sed
 [+++++++++++++++++++++++\                                    ] 0 min. 23 sec
 Target 091-sed OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 092-shadow
 [+++++++++++++++++++++++|                                    ] 0 min. 23 sec
 Target 092-shadow OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 093-psmisc
 [++++++|                                                     ] 0 min. 6 sec
 Target 093-psmisc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 094-iana-etc
 [++/                                                         ] 0 min. 2 sec
 Target 094-iana-etc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 095-m4
 [+++++++++++++++++++++++++                                   ] 0 min. 24 sec
 Target 095-m4 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 096-bison
 [+++++++++++++++++++++++++++++++++++-                        ] 0 min. 35 sec
 Target 096-bison OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 097-flex
 [+++++++++++++-                                              ] 0 min. 13 sec
 Target 097-flex OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 098-grep
 [++++++++++++++++++++++++++                                  ] 0 min. 25 sec
 Target 098-grep OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 099-readline
 [+++++++++/                                                  ] 0 min. 9 sec
 Target 099-readline OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 100-bash
 [+++++++++++++++++++++++++++++++++++++++++/                  ] 0 min. 41 sec
 Target 100-bash OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 101-bc
 [+++++++|                                                    ] 0 min. 7 sec
 Target 101-bc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 102-libtool
 [++++++++|                                                   ] 0 min. 8 sec
 Target 102-libtool OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 103-gdbm
 [++++++++++|                                                 ] 0 min. 10 sec
 Target 103-gdbm OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 104-gperf
 [+++++/                                                      ] 0 min. 5 sec
 Target 104-gperf OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 105-expat
 [++++++++|                                                   ] 0 min. 8 sec
 Target 105-expat OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 106-inetutils
 [++++++++++++++++++++++++++++++++++++++++++++\               ] 0 min. 44 sec
 Target 106-inetutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 107-perl
 [+++++++++++++++++++++++++++++++++++++++++/                  ] 2 min. 41 sec
 Target 107-perl OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 108-xml-parser
 [+++                                                         ] 0 min. 2 sec
 Target 108-xml-parser OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 109-intltool
 [++/                                                         ] 0 min. 2 sec
 Target 109-intltool OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 110-autoconf
 [+++|                                                        ] 0 min. 3 sec
 Target 110-autoconf OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 111-automake
 [++++                                                        ] 0 min. 3 sec
 Target 111-automake OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 112-xz
 [++++++++++++++++++++\                                       ] 0 min. 20 sec
 Target 112-xz OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 113-kmod
 [++++++++++                                                  ] 0 min. 9 sec
 Target 113-kmod OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 114-gettext
 [-                                                           ] 3 min. 0 sec
 Target 114-gettext OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 115-procps-ng
 [+++++++++++++++/                                            ] 0 min. 15 sec
 Target 115-procps-ng OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 116-e2fsprogs
 [+++++++++++++++++++++++++++++-                              ] 0 min. 29 sec
 Target 116-e2fsprogs OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 117-coreutils
 [++++                                                        ] 2 min. 3 sec
 Target 117-coreutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 118-diffutils
 [++++++++++++++++++++++++++++++++                            ] 0 min. 31 sec
 Target 118-diffutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 119-gawk
 [+++++++++++++++++++++++++|                                  ] 0 min. 25 sec
 Target 119-gawk OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 120-findutils
 [++++++++++++++++++++++++++++++++++++++++++++/               ] 0 min. 44 sec
 Target 120-findutils OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 121-groff
 [+++++++++++++++++++++++++++++++++++++++++++++++++\          ] 0 min. 49 sec
 Target 121-groff OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 122-grub
 [++++++++++++++++++++++++++++++++++|                         ] 1 min. 34 sec
 Target 122-grub OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 123-less
 [++++++++|                                                   ] 0 min. 8 sec
 Target 123-less OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 124-gzip
 [++++++++++++++++|                                           ] 0 min. 16 sec
 Target 124-gzip OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 125-iproute2
 [++++++++++++++++++-                                         ] 0 min. 18 sec
 Target 125-iproute2 OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 126-kbd
 [++++++++++++++++/                                           ] 0 min. 16 sec
 Target 126-kbd OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 127-libpipeline
 [+++++++++++++++++|                                          ] 0 min. 17 sec
 Target 127-libpipeline OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 128-make
 [+++++++++++/                                                ] 0 min. 11 sec
 Target 128-make OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 129-patch
 [++++++++++++++++++++++++++|                                 ] 0 min. 26 sec
 Target 129-patch OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 130-sysklogd
 [+++                                                         ] 0 min. 2 sec
 Target 130-sysklogd OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 131-sysvinit
 [++\                                                         ] 0 min. 2 sec
 Target 131-sysvinit OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 132-eudev
 [++++++++++++++++++++++++|                                   ] 0 min. 24 sec
 Target 132-eudev OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 133-util-linux
 [++++++++++++++++++/                                         ] 1 min. 18 sec
 Target 133-util-linux OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 134-man-db
 [+++++++++++++++++++++++++++++++++++++++++++++\              ] 0 min. 45 sec
 Target 134-man-db OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 135-tar
 [++++++++++++++++++++++++++++++++++++++++++++++/             ] 0 min. 46 sec
 Target 135-tar OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 136-texinfo
 [++++++++++++++++++++++++++++++++++\                         ] 0 min. 34 sec
 Target 136-texinfo OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 137-vim
 [+++++++++++++++++++++++++++++++++++++++++++++++++++++++|    ] 0 min. 55 sec
 Target 137-vim OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 140-revisedchroot
 [-                                                           ] 0 min. 0 sec
 Target 140-revisedchroot OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
mk_BOOT
You are going to CHROOT into /mnt/build_dir lfs
a password is required
--------------------------------------------------------------------------------
 Building target 142-bootscripts
 [+-                                                          ] 0 min. 1 sec
 Target 142-bootscripts OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 144-symlinks
 [\                                                           ] 0 min. 0 sec
 Target 144-symlinks OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 145-network
 [-                                                           ] 0 min. 0 sec
 Target 145-network OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 146-usage
 [-                                                           ] 0 min. 0 sec
 Target 146-usage OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 147-profile
 [-                                                           ] 0 min. 0 sec
 Target 147-profile OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 148-inputrc
 [\                                                           ] 0 min. 0 sec
 Target 148-inputrc OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 149-etcshells
 [-                                                           ] 0 min. 0 sec
 Target 149-etcshells OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 151-fstab
 [-                                                           ] 0 min. 0 sec
 Target 151-fstab OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target 152-kernel
 [++++++++++++++++++++++++++++++++++\                         ] 10 min. 34 sec
 Target 152-kernel OK
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
 Building target create-sbu_du-report

--------------------------------------------------------------------------------
 Finished the build of 8.0
--------------------------------------------------------------------------------
        W A R N I N G
--------------------------------------------------------------------------------

To be able to boot your new system you need to follow
the next steps:

    - Mount the virtual kernel file systems.

    - Enter to the chroot using the command found
    in the section -Entering the Chroot Environment-
    except if building CLFS with METHOD=boot.

    - Set a password for the root user.

    - Edit or create /etc/fstab,
                     /etc/hosts,
                     /etc/sysconfig/clock,
                     /etc/sysconfig/console,
                     /etc/sysconfig/network,
                     /etc/sysconfig/ifconfig.eth0,
                     /etc/resolv.conf
    and any other configuration file required to suit your needs.

    - Set-up the boot loader, except if building CLFS with METHOD=boot.

    You can set-up the new boot-loader installed on the new system
    or the host bootloader.

    If the last, it is better to exit first from the chroot.

    - Exit from the chroot and umount the filesystems.

If you are an experienced LFS user, several of those steps can be
skipped or done in a different way. But then, that is something
that you already know and there is no need to discuss it here.

--------------------------------------------------------------------------------
        Have a nice day :-)
--------------------------------------------------------------------------------
[test@localhost jhalfs]$

上面就编译完成了

0x02 最后的配置

先退出当前用户到 root

[test@localhost jhalfs]$ exit
logout
[root@localhost ~]# 

# 编辑 .bash_profile  在最下面加上一行 export LFS=/mnt/build_dir


[root@localhost ~]# vim .bash_profile 
[root@localhost ~]# cat .bash_profile 
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export LFS=/mnt/build_dir

[root@localhost ~]# 


[root@localhost ~]# source .bash_profile 
[root@localhost ~]# echo $LFS
/mnt/build_dir
#  确保环境变量的正确

[root@localhost ~]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 119.2G  0 disk 
├─sda1   8:1    0    50G  0 part /
├─sda2   8:2    0     4G  0 part [SWAP]
├─sda3   8:3    0    30G  0 part /mnt/build_dir
└─sda4   8:4    0     4G  0 part 
# 确保正确的挂载了硬盘,下面开始做。

按照提示去书里找对于的内容去做

To be able to boot your new system you need to follow
the next steps:

    - Mount the virtual kernel file systems.

    - Enter to the chroot using the command found
    in the section -Entering the Chroot Environment-
    except if building CLFS with METHOD=boot.

    - Set a password for the root user.

    - Edit or create /etc/fstab,
                     /etc/hosts,
                     /etc/sysconfig/clock,
                     /etc/sysconfig/console,
                     /etc/sysconfig/network,
                     /etc/sysconfig/ifconfig.eth0,
                     /etc/resolv.conf
    and any other configuration file required to suit your needs.

    - Set-up the boot loader, except if building CLFS with METHOD=boot.

    You can set-up the new boot-loader installed on the new system
    or the host bootloader.

    If the last, it is better to exit first from the chroot.

    - Exit from the chroot and umount the filesystems.

http://www.linuxfromscratch.org/lfs/downloads/8.0/LFS-BOOK-8.0-NOCHUNKS.html#ch-system-kernfs

《6.2. Preparing Virtual Kernel File Systems》


[root@localhost ~]# mkdir -pv $LFS/{dev,proc,sys,run}
[root@localhost ~]# mknod -m 600 $LFS/dev/console c 5 1
mknod: ‘/mnt/build_dir/dev/console’: File exists
[root@localhost ~]# mknod -m 666 $LFS/dev/null c 1 3
mknod: ‘/mnt/build_dir/dev/null’: File exists
[root@localhost ~]# mount -v --bind /dev $LFS/dev
mount: /dev bound on /mnt/build_dir/dev.
[root@localhost ~]# mount -vt devpts devpts $LFS/dev/pts -o gid=5,mode=620
mount: devpts mounted on /mnt/build_dir/dev/pts.
[root@localhost ~]# mount -vt proc proc $LFS/proc
mount: proc mounted on /mnt/build_dir/proc.
[root@localhost ~]# mount -vt sysfs sysfs $LFS/sys
mount: sysfs mounted on /mnt/build_dir/sys.
[root@localhost ~]# mount -vt tmpfs tmpfs $LFS/run
mount: tmpfs mounted on /mnt/build_dir/run.
[root@localhost ~]# if [ -h $LFS/dev/shm ]; then
>   mkdir -pv $LFS/$(readlink $LFS/dev/shm)
> fi
[root@localhost ~]# 

《6.4. Entering the Chroot Environment》
[root@localhost ~]# chroot "$LFS" /tools/bin/env -i \
>     HOME=/root                  \
>     TERM="$TERM"                \
>     PS1='\u:\w\$ '              \
>     PATH=/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin \
>     /tools/bin/bash --login +h
root:/# 
# 设置 root 密码

root:/# passwd
Changing password for root
Enter the new password (minimum of 5 characters)
Please use a combination of upper and lower case letters and numbers.
New password: 
Bad password: too short.  
Warning: weak password (enter it again to use it anyway).
New password: 
Re-enter new password: 
passwd: password changed.
root:/# 

编辑或创建文件

- Edit or create /etc/fstab,
                     /etc/hosts,
                     /etc/sysconfig/clock,
                     /etc/sysconfig/console,
                     /etc/sysconfig/network,
                     /etc/sysconfig/ifconfig.eth0,
                     /etc/resolv.conf

一项一项来,fstab是我们以前做好的。检查一下就好了

root:/# cat /etc/fstab
# Begin /etc/fstab

# file system  mount-point  type     options             dump  fsck
#                                                              order
/dev/sda3     /             ext4    defaults            1     1

/dev/sda4     swap         swap     pri=1               0     0

proc           /proc        proc     nosuid,noexec,nodev 0     0
sysfs          /sys         sysfs    nosuid,noexec,nodev 0     0
devpts         /dev/pts     devpts   gid=5,mode=620      0     0
tmpfs          /run         tmpfs    defaults            0     0
devtmpfs       /dev         devtmpfs mode=0755,nosuid    0     0


# End /etc/fstab
root:/# 

编辑 hosts 保留一行就行了

root:/# vim /etc/hosts
root:/# cat /etc/hosts
# Begin /etc/hosts (network card version)

127.0.0.1 localhost

# End /etc/hosts (network card version)

编辑 hostname 内容随便写

root:/# vim /etc/hostname 
root:/# cat /etc/hostname 
ivoivo

/etc/sysconfig/clock 文件,只对 hwclock 有效,硬件时间不影响启动,有需要的话可以编辑,这里我就不做了。

/etc/sysconfig/console 参考以前的 LFS 的文章,没必要必须做,默认不影响启动,有需要的话根据 LFS 的书籍去更改

/etc/sysconfig/network 在配置文件中配置或修改网关和DNS 修改网关,可以理解为是一个总的配置文件,负责配置通用的网络配置方面

编辑一下 /etc/resolv.conf

root:/# cat /etc/resolv.conf
# Begin /etc/resolv.conf

nameserver 8.8.8.8
nameserver 114.114.114.114

# End /etc/resolv.conf

编辑网卡的配置 /etc/sysconfig/ifconfig.eth0

root:/# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp2s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether 00:e0:4c:1b:a7:03 brd ff:ff:ff:ff:ff:ff
3: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:e0:4c:1b:a7:04 brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.224/24 brd 192.168.8.255 scope global noprefixroute dynamic enp3s0
       valid_lft 11071sec preferred_lft 11071sec
    inet6 2001:db0:1:0:97d1:1e21:cdb4:13e4/64 scope global noprefixroute dynamic 
       valid_lft 2411110sec preferred_lft 423910sec
    inet6 fe80::db3c:b8f1:b411:9074/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
# 先确定一下网的名称

root:/# mv /etc/sysconfig/ifconfig.eth0 /etc/sysconfig/ifconfig.enp3s0

# 改名,编辑
root:/# vim /etc/sysconfig/ifconfig.enp3s0 
root:/# cat /etc/sysconfig/ifconfig.enp3s0 
ONBOOT=yes
IFACE=enp3s0
SERVICE=ipv4-static
IP=192.168.8.224
GATEWAY=192.168.8.1
PREFIX=24
BROADCAST=192.168.8.255

更新grub

root:/# exit
logout
[root@localhost ~]# 

# 先退出当前的 chroot,然后更新 grub


[root@localhost ~]# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-957.21.3.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.21.3.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-957.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-957.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-385aa5763714407687f69562947dcea6
Found initrd image: /boot/initramfs-0-rescue-385aa5763714407687f69562947dcea6.img
Found Linux From Scratch (8.0) on /dev/sda3
done

[root@localhost ~]# 

好了,一切都结束了,重启就可以了。由于内核的原因网卡启动找不到,下一期我们说说内核编译。就事重新编译一个内核替换过去。好了这期就到这了。感谢收看。

上一篇
下一篇