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. Open vSwitch简述

    一.基础术语 1.Packet (数据包):网络转发的最小数据单元,每个包都来自某个端口,最终会被发往一个或多个目标端口,转发数据包的过程就是网络的唯一功能. 2.Bridge (网桥):Open v ...

  2. 通过开发MSBuild ,引发的注册表相关知识

    最近在做一个小项目,目的就是只需要点一个按钮,就把web程序发布到指定的服务器中.基本步骤就是 编译——>打包->复制包到远程服务器->解压缩.我想重点说一下解压缩,我们可以用win ...

  3. 15. 3Sum

    Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...

  4. 使用isInEditMode解决可视化编辑器无法识别自定义控件的问题

    如果在自定义控件的构造函数或者其他绘制相关地方使用系统依赖的代码, 会导致可视化编辑器无法报错并提示:Use View.isInEditMode() in your custom views to s ...

  5. 使用ASP.NET web API创建REST服务(三)

    本文档来源于:http://www.cnblogs.com/madyina/p/3390773.html Creating a REST service using ASP.NET Web API A ...

  6. JS初学之-选项卡(图片切换类)

    初学选项卡,主要问题卡在了索引值上面,花了较长的时间学习. 索引值其实很好理解,就是为每一个元素用JS的方法添加一个属性,即自定义属性. 在for循环里的函数里用i,会直接弹出这个数组的length, ...

  7. jQuery显示隐藏动态效果的几种写法

    <script type="text/javascript"> $(document).ready(function() {     /*$("#test1& ...

  8. google-http-java-client(android学习篇)

    package com.example.android; import java.io.IOException; import java.util.HashMap; import android.ap ...

  9. when compile /home/wangxiao/NVIDIA-CUDA-7.5 SAMPLES, it warning: gcc version larger than 4.9 not supported, so: old verson of gcc and g++ are needed

    1. when compile /home/wangxiao/NVIDIA-CUDA-7.5 SAMPLES, it warning: gcc version larger than 4.9 not ...

  10. Google Java Style Guide

    https://google.github.io/styleguide/javaguide.html   Table of Contents 1 Introduction 1.1 Terminolog ...