Chinaunix首页 | 论坛 | 博客
  • 博客访问: 164190
  • 博文数量: 18
  • 博客积分: 299
  • 博客等级: 二等列兵
  • 技术积分: 731
  • 用 户 组: 普通用户
  • 注册时间: 2011-02-19 00:39
文章分类

全部博文(18)

文章存档

2013年(7)

2012年(11)

分类: LINUX

2012-12-18 23:50:46

linux玩了有一段时间了,某次重新买电脑的时候直接买了零件安装,然后从裸机安装linux,安装的时候在想,如果能从零件购买电脑,并且从源代码编译出自己操作系统使用那是一件多好的事情阿,在编译的过程中,比较繁琐,主要是学习和熟悉系统的编译选项,想要把这个过程记录下来以备忘记,于是就有了以下的文章,缓慢更新中。


准备工作:

host linux开辟出来的10Gb空间备用,作为编译的Linux的空间。

能上所有网络的手段

英语字典一本


主要参考资料:linux from scratch


第一步:首先,检查host系统是不是符合编译的要求,是否所有库的版本都安装为最新的。

(以下操作都在root下进行)

运行下列脚本确认:


点击(此处)折叠或打开

  1. cat > version-check.sh << "EOF"
  2. #!/bin/bash
  3. # Simple script to list version numbers of critical development tools

  4. export LC_ALL=C
  5. bash --version | head -n1 | cut -d" " -f2-4
  6. echo "/bin/sh -> `readlink -f /bin/sh`"
  7. echo -n "Binutils: "; ld --version | head -n1 | cut -d" " -f3-
  8. bison --version | head -n1
  9. if [ -e /usr/bin/yacc ];
  10.   then echo "/usr/bin/yacc -> `readlink -f /usr/bin/yacc`";
  11.   else echo "yacc not found"; fi

  12. bzip2 --version 2>&1 < /dev/null | head -n1 | cut -d" " -f1,6-
  13. echo -n "Coreutils: "; chown --version | head -n1 | cut -d")" -f2
  14. diff --version | head -n1
  15. find --version | head -n1
  16. gawk --version | head -n1
  17. if [ -e /usr/bin/awk ];
  18.   then echo "/usr/bin/awk -> `readlink -f /usr/bin/awk`";
  19.   else echo "awk not found"; fi

  20. gcc --version | head -n1
  21. ldd --version | head -n1 | cut -d" " -f2- # glibc version
  22. grep --version | head -n1
  23. gzip --version | head -n1
  24. cat /proc/version
  25. m4 --version | head -n1
  26. make --version | head -n1
  27. patch --version | head -n1
  28. echo Perl `perl -V:version`
  29. sed --version | head -n1
  30. tar --version | head -n1
  31. echo "Texinfo: `makeinfo --version | head -n1`"
  32. xz --version | head -n1

  33. echo 'main(){}' > dummy.c && gcc -o dummy dummy.c
  34. if [ -x dummy ]
  35.   then echo "gcc compilation OK";
  36.   else echo "gcc compilation failed"; fi
  37. rm -f dummy.c dummy
  38. EOF


第二步:准备编译的前期过程,分区,下载package,编译临时tools


分区:首先,先空出10G的可用空间,然后用

fdisk /dev/sda(或者hda)


进入分区的选项,然后选择n对没有分区的盘进行分区。但是这个选项如果删除一个已经挂在的盘可能会出现问题,所以还是推荐在安装系统的时候直接就空出10G进行操作比较好。

使用


点击(此处)折叠或打开

  1. mke2fs -jv /dev/sdax(或者hdax)

 创建一个ext3的文件系统。


挂载新的文件夹,

现将LFS赋值成/mnt/lfs


点击(此处)折叠或打开

  1. export LFS=/mnt/lfs

创建文件夹,并且挂载在前面创建的文件系统当中。


点击(此处)折叠或打开

  1. mkdir -pv $LFS
  2. mount -v -t ext3 /dev/sdax(或者hdax) $LFS

*mount是一个临时命令,如果关机了需要重新再挂载一下。

建立/mnt/lfs下的3个文件夹:


点击(此处)折叠或打开

  1. mkdir -v $LFS/sources
  2. chmod -v a+wt $LFS/sources



这个chmod命令当中的t是什么意思呢?查询了man chmod当中,有以下解释:



The letters rwxXst select file mode bits for the affected users: read

(r), write (w), execute (or search for directories) (x), execute/search

only if the file is a directory or already has execute permission for

some user (X), set user or group ID on execution (s), restricted dele‐

tion flag or sticky bit (t). Instead of one or more of these letters,

you can specify exactly one of the letters ugo: the permissions granted

to the user who owns the file (u), the permissions granted to other

users who are members of the file's group (g), and the permissions

granted to users that are in neither of the two preceding categories

(o).

Sticky” means that even if multiple users have write permission on a directory, only the owner of a file can delete the file within a sticky directory. 

意思是说,增加了这个t在多用户的情况下能对一个文件夹写操作,但是只有owner才有删除这个文件的权限。



下载所有的包:



下列网址的内容保存成文件,并且执行

wget -i wget-list -P $LFS/sources



检查下载的包是否正确:

下列网址内容保存文件,放在 $LFS/sources里面,并且执行


点击(此处)折叠或打开

  1. pushd $LFS/sources md5sum -c md5sums popd



这样,所有的需要用到的packages都放在了$LFS/sources这个文件夹下面了。

阅读(2637) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~