0. 首先解释下build, host和target

build:编译过程运行在build上

host:编译出来的东西运行在host上

target:运行在host上的编译器编译出来的东西运行于target。

例如,编译gcc时,build=x86,host=arm,target=mips,表示:

a) 在x86上编译gcc源代码;

b) a步骤得到的gcc在arm上运行(姑且把这个编译器叫做xxx-linux-gcc)

c) 你写了个小东西main.c在arm上用xxx-linux-gcc编译,得到的东西在mips上运行。

   `./configure --build=mipsel-linux --host=mipsel-linux --target=mipsel-linux' will build native mipsel-linux binutils on mipsel-linux.
   `./configure --build=i386-linux --host=mipsel-linux --target=mipsel-linux' will cross-build native mipsel-linux binutils on i386-linux.
   `./configure --build=i386-linux --host=i386-linux --target=mipsel-linux' will build mipsel-linux cross-binutils on i386-linux.
   `./configure --build=mipsel-linux --host=i386-linux --target=mipsel-linux' will cross-build mipsel-linux cross-binutils for i386-linux on mipsel-linux.

As you see, only if $build != $host a cross-compilation is performed.

1. We start from VMWare

2. Add a new disk in VMWare for our guest OS (Maybe you need restart)

3. fdisk this new disk, one partition for root, one partition for swap

4. format our new partitions:

# mkfs -t ext4 /dev/sdb1

# mkswap /dev/sdb2

5. # mkdir /mnt/lfs

6. # mount /dev/sdb1 /mnt/lfs

6.1 # chmod a+w lfs

7. # mkdir -p /mnt/lfs/sources

8. # chmod a+wt /mnt/lfs/sources

9. # mkdir /mnt/lfs/tools

这个目录存放系统构建过程中要用到,系统构造完成后就可以吃干抹净的东西。

10. # ln -s /mnt/lfs/tools /

在host的根目录上创建一个指向lfs/tools的symbolic link,这样在host侧和lfs侧能够用相同路径访问工具链。

11. 新建一个用户专用于我们的工作

# groupadd lfs

# useradd -s /bin/bash -g lfs -m -k /dev/null lfs    -s: bash;  -g: group;  -m: create home directory;

-k: useradd默认会从/etc/skel复制东西来初始化用户目录,-k /dev/null让useradd从/dev/null复制。

12. passwd lfs

13. su - lfs

切换到lfs

14. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash

exec命令替换当前shell,因此该命令会清除系统默认环境变量(/etc/profile),得到一个干净的环境。

注意\u和\w小写。

15. cat > ~/.bashrc << "EOF"
      set +h           # 禁止bash记住最近执行命令的路径,以使得bash总是使用最新的可执行文件。
      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

关于set +h多解释下:比如你在/bin下有个gcc执行了一下,后来在/tools/bin下有了个gcc,尽管PATH规定先搜索/tools/bin,但bash会记住/bin下已经有个gcc而执行/bin下的。我们需要禁止该功能。

16. 因为我们打算从源代码开始构造整个系统,所以我们要先构造编译环境。我们需要从Binutils开始,因为gcc要用到Binutils。我们不想让gcc使用host上的Binutils,以得到纯净系统,避免因gcc和Binutils不匹配导致的可能出现的稀奇古怪问题。

17. 在sources目录下解压Binutils。Binutils的Doc说建一个build目录用于编译:

cd binutils-2.26 && mkdir build && cd build

../configure --prefix=/tools                      \ # 安装目录
                         --with-sysroot=$LFS           \ # build system在需要时到$LFS下找target system的libraries
                         --with-lib-path=/tools/lib      \ # 编译出来的linker在运行时使用的lib所在目录
                         --target=$LFS_TGT           \ # 编译出来的东西要使用该前缀,前缀使用约定名+自定义名的形式,必须以约定名开始。
                         --disable-nls                       \ # 不要国际化
                         --disable-werror                  # 忽略编译过程中的警告

make

mkdir -v /tools/lib && ln -s lib /tools/lib64         # 64位系统用

make install   # 因为我们安装目录是/tools,不需要su就可安装

[在binutils的configure文件中完全找不到--with-sysroot和--with-lib-path选项:也许这两者其实是不必要的?]

[此处我们将去除以上选项编译binutils,以验证之。如果发生问题,我们会再回来。]

18.

Linux From Scratch [1]的更多相关文章

  1. Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(三)

    八. 构建LFS系统 1. 准备虚拟内核文件系统 内核会挂载几个文件系统用于自己和用户空间程序交换信息.这些文件系统是虚拟的,并不占用实际磁盘空间, 它们的内容会放在内存里. mkdir -pv $L ...

  2. Linux From Scratch(从零开始构建Linux系统,简称LFS)- Version 7.7(一)

    一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...

  3. Linux From Scratch - Version 7.7-systemd (中文)

    Linux From Scratch - Version 7.7-systemd: https://linux.cn/lfs/LFS-BOOK-7.7-systemd/index.html

  4. What is Cross Linux From Scratch?

    /**************************************************************************** * What is Cross Linux ...

  5. Welcome to Linux From Scratch!

    /**************************************************************************** * Welcome to Linux Fro ...

  6. LFS(Linux From Scratch)学习

    一.简介 LFS──Linux from Scratch,就是一种从网上直接下载源码,从头编译LINUX的安装方式.它不是发行版,只是一个菜谱,告诉你到哪里去买菜(下载源码),怎么把这些生东西( ra ...

  7. Linux From Scratch(从零开始构建Linux系统,简称LFS)(三)

    九. 系统配置 1. 安装 LFS-Bootscripts-20150222 软件包包含一套在 LFS 系统启动和关闭时的启动和停止脚本. cd /sources tar -jxf lfs-boots ...

  8. Linux From Scratch(从零开始构建Linux系统,简称LFS)(一)

    一. 准备工作 1. 需要一个Linux宿主系统,例如早先版本的 LFS,Ubuntu/Fedora,SuSE 或者是在你的架构上可以运行的其它发行版 如果想实现Win7与Linux双系统,可参考我的 ...

  9. 高手从零开始的全定制发行版-Linux from Scratch

    在制作Linux发行版中Linux from Scratch可谓是真正的大师级.Linux from Scratch是在线的社区创建的一本电子书,目的是帮助那些根深蒂固的想方设法提高计算机性能的人(t ...

  10. LFS Linux From Scratch 笔记2(经验非教程)BLFS

    LFS 完了. 其实还没完,还要装一些其他的组件,系统才算是对人类有用的系统. 正好这里有个BLFS Beyound Linux From Scratch 的教程. 其实,按照现有的可运行的LFS系统 ...

随机推荐

  1. 合并两个有序数组a和b到c

    问题:两个有序数组a和b,合并成一个有序数组c. // 合并两个有序数组a和b到c void Merge_Array(int a[], int n, int b[], int m, int c[]) ...

  2. iOS中的多线程及GCD

    多线程中的一些概念 //任务:代码段  方法  线程就是执行这些任务 //NSThread类 创建线程 执行线程 [NSThread isMainThread]//判断是否是主线程 #import & ...

  3. static讲解

    static表示"全局"或者"静态"的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念.  被stati ...

  4. Codeforces Round #368 (Div. 2)A B C 水 图 数学

    A. Brain's Photos time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  5. c++函数重载---2

    原创博客:转载请标明出处:http://www.cnblogs.com/zxouxuewei/ 写在前面: 函数重载的重要性不言而明,但是你知道C++中函数重载是如何实现的呢(虽然本文谈的是C++中函 ...

  6. leetcode 122. Best Time to Buy and Sell Stock II ----- java

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  7. spark 分析sql内容再插入到sql表中

    package cn.spark.study.core.mycode_dataFrame; import java.sql.DriverManager;import java.util.ArrayLi ...

  8. 写出bool,int,float,指针与零值比较的if语句

    这个里面float与零值的比较颇有些意思. bool: bool flag; if (flag == true) return; int: int var; if (var == 0) { retur ...

  9. (转) A Survival Guide to a PhD

    A Survival Guide to a PhD Sep 7, 2016 This guide is patterned after my “Doing well in your courses”, ...

  10. Windows下IntelliJ IDEA中运行Spark Standalone

    ZHUAN http://www.cnblogs.com/one--way/archive/2016/08/29/5818989.html http://www.cnblogs.com/one--wa ...