免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 80054 | 回复: 154
打印 上一主题 下一主题

从 0 开始,打造自己的 Linux 。 [复制链接]

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
跳转到指定楼层
[收藏(0)] [报告]
发表于 2012-04-11 02:22 |只看该作者 |正序浏览
刚看到一个问题,如何把 Linux 系统安装在 U 盘里。

说实在话,这个话题在新手园地来谈,确实有些大了,不过为了解答新手园区的问题,还是放这里了。

一、问题:如何打造一个 Linux 系统,并将之安装到 U 盘里。(这里的打造是指自己编译内核,自己编译命令。)

说实在话,这个问题,新手能提出来,俺还是很佩服这个勇气的。

在开始讲这个话题之前,首先得说一下什么是操作系统,操作系统是干什么的?操作系统又是如何驱动硬件,并为我们提供一个人机交互环境的?操作系统与开发语言的关系是什么?

简单说,操作系统是一个中间层,它位于应用软件和计算机硬件之间,用于将应用软件的指令翻译成机器指令并提交给机器执行。这个机器指令其实就是二进制代码,对应于机器硬件的指令就是电路中的通、断。

操作系统通过与固化到 flash 中的硬件指令来驱动硬件,并提供一个人机交互的环境。(这里说简单点,说太多咱就漏了,毕竟只有半桶水啊^_^.)。做过嵌入式开发的朋友可能知道,所谓的“烧板”其实就是把硬件指令写入到硬件的 flash 中。更形象一点,就是我们的 x86 指令集、mips指令集等等 。

开发语言实际上是通过一定的编译程序,将我们用中、高级语言写成的代码首先翻译成汇编代码,再由汇编器翻译成机器码,然后由链接器将一个一个的代码片段链接成能执行完整程序功能的执行代码,并保存在非易失存储器上。

计算机系统的启动过程。

(本部分以 x86 系列为例,MBR模式,非 EFI 模式,其实说太多了,俺也说不清楚了。)

系统加电以后,首先会有一个自己检测的过程,这一个过程主要是通过接口来测试各个硬件能否正常工作,如果可以,那么系统首先会以实模式启动,此时系统仅能访问 1 MB 内存的内容,实际上由于还有留部分内存给硬件中断,我们实际能访问到的是 640KB。然后系统会根据 cmos 中设置的启动顺序,从外部的硬件中查找能启动系统的信息,此时如果找到,则系统将转入到这个外部的介质上,读取最初的启动信息,这个最初的启动信息很小,它只是指明了真正的操作系统内核加载的地址位,并将继承器的第20位置为1,开启虚模式,此时系统能使用较大的内存了(一般是 4GB , 特殊的方式【PAE】能映射到 16GB)。然后系统移到这个偏移地址,将真正的操作系统内核装入,完成系统的进一步自检,如果没有错误,开始初始化系统的软件环境。

最后进入到一个提供人机交互的环境,这个环境下供用户选择自己使用的 shell 。(DOS 年代,没有选择 ,就是 command.com )

我们执行的可执行文件,有一定的格式,在 linux 下一般是 ELF 格式,这个格式下,系统的指令是动态装入的,需要的时候才装入,不需要的时候,系统并不装入执行的动态链接库信息。需要指出的是,不同的可执行文件格式,其实真正的执行码,在同一种硬件架构上是一样的,不同的是这个可执行文件的文件头。操作系统根据这个文件头决定在什么时候,什么地址装入可执行指令和数据。


好了,前面说这么多,只是一个引子,目的是抛砖引玉。

评分

参与人数 2可用积分 +14 收起 理由
send_linux + 6 很辛苦,值得鼓励!
chenyx + 8 赞一个!

查看全部评分

求职 : Linux运维
论坛徽章:
1
数据库技术版块每日发帖之星
日期:2016-01-22 06:20:00
154 [报告]
发表于 2016-01-31 15:43 |只看该作者
继续呀,我还没看够呢

求职 : Linux运维
论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-12-09 06:20:00
153 [报告]
发表于 2015-12-06 20:49 |只看该作者
高手,看这个就知道是高手,,一般情况下比我牛逼的都是高手,,,交个朋友,,,时时调教我被

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-08-07 06:20:00
152 [报告]
发表于 2015-08-04 15:07 |只看该作者
不是有个LFS的教程吗

论坛徽章:
1
操作系统版块每日发帖之星
日期:2015-08-07 06:20:00
151 [报告]
发表于 2015-08-04 15:06 |只看该作者
不是有个LFS的教程吗

论坛徽章:
0
150 [报告]
发表于 2015-07-19 22:53 |只看该作者
认真拜读了全文,对于新手理解linux帮助太大了,多谢!

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
149 [报告]
发表于 2015-02-15 18:43 |只看该作者
我好像第二次编译的时候,是用第一次编译的 gcc 做的。

年代久远,记得不是很清楚了。

论坛徽章:
0
148 [报告]
发表于 2015-01-31 02:32 |只看该作者
求助 : 我的情况是这样的     mac os  10.10  
安装 binutils-2.25   
第一次编译的时候没有任何问题,./configure  ,make  ,make install
装好之后 原文件删掉了,可是问题就出来了 ,第二次编译的  binutils-2.25 时候就开始报ld 错了   包括编译 gcc 源码 也报ld 错
Ξ nasm/build → clang -v
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix
Ξ nasm/build → ld -v
@(#)PROGRAM:ld  PROJECT:ld64-241.9
configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
LTO support using: LLVM version 3.5svn

$gcc -v  
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
Target: x86_64-apple-darwin14.1.0
Thread model: posix

$gdb
this GDB was configured as follows:
   configure --host=x86_64-apple-darwin14.0.0 --target=x86_64-apple-darwin14.0.0
             --with-auto-load-dir={prefix}/share/auto-load
             --with-auto-load-safe-path={prefix}/share/auto-load
             --with-expat
             --with-gdb-datadir=/usr/local/share/gdb (relocatable)
             --with-jit-reader-dir=/usr/local/lib/gdb (relocatable)
             --without-libunwind-ia64
             --without-lzma
             --with-python=/System/Library/Frameworks/Python.framework/Versions/2.7
             --without-guile
             --with-separate-debug-dir=/usr/local/lib/debug (relocatable)
             --with-zlib
             --without-babeltrace
我想问问这个target 是怎么回事 还有 --host

第二次编译 binutils-2.25 如下错误 麻烦楼主帮忙分析下, 不甚感激。应该是编译ld 的时候出错,然后是 size 命令。但是 第一次没错,第二次却有错了,不知道原因所在。

libtool: link: gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -g -O2 -Wl,-no_pie -o size size.o bucomm.o version.o filemode.o  ../bfd/.libs/libbfd.a -ldl ../libiberty/libiberty.a ./../intl/libintl.a -liconv -lz
ld: warning: ld: warning: ld: warning: ignoring file ../libiberty/libiberty.a, file was built for archive which is not the architecture being linked (x86_64): ../libiberty/libiberty.aignoring file ../bfd/.libs/libbfd.a, file was built for archive which is not the architecture being linked (x86_64): ../bfd/.libs/libbfd.aignoring file ./../intl/libintl.a, file was built for archive which is not the architecture being linked (x86_64): ./../intl/libintl.a


Undefined symbols for architecture x86_64:
  "__bfd_std_section", referenced from:
      _sysv_internal_sizer in size.o
      _sysv_internal_printer in size.o
  "_bfd_arch_list", referenced from:
      _list_supported_architectures in bucomm.o
  "_bfd_check_format", referenced from:
      _display_file in size.o
      _display_bfd in size.o
  "_bfd_check_format_matches", referenced from:
      _display_bfd in size.o
  "_bfd_close", referenced from:
      _display_file in size.o
  "_bfd_close_all_done", referenced from:
      _display_info in bucomm.o
  "_bfd_core_file_failing_command", referenced from:
      _display_bfd in size.o
  "_bfd_errmsg", referenced from:
      _bfd_nonfatal in bucomm.o
      _bfd_nonfatal_message in bucomm.o
      _set_default_bfd_target in bucomm.o
  "_bfd_get_error", referenced from:
      _display_file in size.o
      _display_bfd in size.o
      _bfd_nonfatal in bucomm.o
      _bfd_nonfatal_message in bucomm.o
      _set_default_bfd_target in bucomm.o
      _display_info in bucomm.o
  "_bfd_init", referenced from:
      _main in size.o
  "_bfd_malloc", referenced from:
      _bfd_get_archive_filename in bucomm.o
  "_bfd_map_over_sections", referenced from:
      _print_sizes in size.o
  "_bfd_openr", referenced from:
      _display_file in size.o
  "_bfd_openr_next_archived_file", referenced from:
      _display_file in size.o
  "_bfd_openw", referenced from:
      _display_info in bucomm.o
  "_bfd_printable_arch_mach", referenced from:
      _display_info in bucomm.o
  "_bfd_scan_vma", referenced from:
      _parse_vma in bucomm.o
  "_bfd_set_default_target", referenced from:
      _set_default_bfd_target in bucomm.o
  "_bfd_set_error", referenced from:
      _display_file in size.o
  "_bfd_set_format", referenced from:
      _display_info in bucomm.o
  "_bfd_target_list", referenced from:
      _list_supported_targets in bucomm.o
  "_bfd_target_vector", referenced from:
      _display_info in bucomm.o
  "_expandargv", referenced from:
      _main in size.o
  "_libintl_bindtextdomain", referenced from:
      _main in size.o
  "_libintl_gettext", referenced from:
      _main in size.o
      _usage in size.o
      _set_default_bfd_target in bucomm.o
      _list_matching_formats in bucomm.o
      _list_supported_targets in bucomm.o
      _list_supported_architectures in bucomm.o
      _display_info in bucomm.o
      ...
  "_libintl_textdomain", referenced from:
      _main in size.o
  "_make_temp_file", referenced from:
      _display_info in bucomm.o
  "_xexit", referenced from:
      _bfd_fatal in bucomm.o
      _fatal in bucomm.o
  "_xmalloc", referenced from:
      _print_sizes in size.o
      _template_in_dir in bucomm.o
  "_xmalloc_set_program_name", referenced from:
      _main in size.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [size] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-binutils] Error 2
make: *** [all] Error 2


论坛徽章:
0
147 [报告]
发表于 2014-06-21 12:57 |只看该作者
写的蛮不错的,热门linux中...

论坛徽章:
8
2015年辞旧岁徽章
日期:2015-03-03 16:54:15午马
日期:2015-02-04 12:00:07羊年新春福章
日期:2015-02-04 11:57:56双子座
日期:2014-12-02 11:44:59金牛座
日期:2014-10-08 16:47:08狮子座
日期:2014-08-29 13:37:46巳蛇
日期:2014-08-26 17:32:29NBA常规赛纪念章
日期:2015-05-04 22:32:03
146 [报告]
发表于 2014-06-20 14:41 |只看该作者
楼主写的很好,赞!

论坛徽章:
0
145 [报告]
发表于 2014-06-20 14:01 |只看该作者
支持楼主~~~~~~~~
  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP