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. igv

    integrative genomics viewer 下载: http://www.broadinstitute.org/igv/download 下载前要注册 导入参考基因组:http://www ...

  2. centos 服务器操作

     CENTOS下创建FTP登录用户 yum install vsftpd2.启动/重启/关闭vsftpd服务器[root@localhost ftp]# /sbin/service vsftpd re ...

  3. AngularJS的路由、模块、依赖注入

    AngularJS的路由在实际应用中更多是由另外封装好的angular-ui-router.js实现的! 为什么不用Ajax而要用前端路由?

  4. c 函数及指针学习 6

    不完整声明 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 /* 方法一   */ struct tag_a{ ...

  5. 转:linux 修改sftp服务默认提供者sshd的session timeout

    ssh连接超时问题解决方案: 1.修改server端的etc/ssh/sshd_config ClientAliveInterval 60 #server每隔60秒发送一次请求给client,然后cl ...

  6. c#部分---输入班级人数,输入语文数学英语成绩,打印语文前两名,数学后两名,英语平均分

    1.开始收集输入项 2.用冒泡排序,统计语文成绩,并附带把语数英三门课全排列 3.数学成绩排序,附带把三门课全排序‘ 4.最后算英语的平均分:

  7. [HAOI2012]音量调节

    题目描述 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都需要改变一次音量.在演出开始之前,他已经做好一个列表,里面写着每首歌开始之前他想要改变的音量是多少. ...

  8. android中的DatePicker与TimePicker

    1.布局文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns ...

  9. 针对主流浏览器的CSS-HACK写法及IE常用条件注释

    一.通用区分方式: IE6.IE7能识别*,标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important:IE7能识别*,也能识别 !important:IE8能识别\0,不能识别 ...

  10. JPA的Column注解总结

    就像@Table注解用来标识实体类与数据表的对应关系类似,@Column注解来标识实体类中属性与数据表中字段的对应关系. 该注解的定义如下: @Target({METHOD, FIELD}) @Ret ...