[转]迁移linux到另一块硬盘(分区),首战告捷
一步一步打造自己的Linux--LFS6.3安装过程(二)

一步一步打造自己的Linux--LFS6.3安装过程(一)

獨立的圓 posted @ 2008年2月07日 20:39 in Linux with tags LFS , 20827 阅读

 本站文章已轉移,敬請移步:http://www.xxb.me/ ,謝謝!

I.近日无聊,趁家里网络比学校的好,玩Linux From Scratch,网上有详细教程,但有些地方过时了或者有些小问题,我将之综合整理一下,以作备份用,如有错误,欢迎指出。

(注:本文于2月28日修改,之前在家时由于时间关系,没有把LFS安装完成。回校后重新安装,不再用虚拟机装,改为使用现有的ubuntu 7.10作宿主系统,不再讨论中途重启的问题,如果需要,可以参考《制作LFS过程中各个阶段恢复工作状态的方法 第二版(适合LFS6.3)》

本文参考自以下文章,感谢原作者youbest:

手把手教你如何建立自己的Linux系统 第二版

http://kerrek.linuxfromscratch.org/pub/lfs-livecd/下载安装镜像,我下了lfslivecd-x86-6.3-r2160.iso

II. 构建前的准备工作

用此LiveCD启动电脑,推荐用虚拟机安装LFS,参看ubuntu下VirtualBox 安装和配置指南

启动LiveCD后输入命令cfdisk进行分区管理,保存退出后,进行磁盘分区的格式化:

  1. $ mkswap /dev/hda1
  2. $ mkfs.ext3 /dev/hda2 #格式化为ext3
  3. 或 mkfs.reiserfs /dev/hda2 #格式化为reiserfs
  4. 或 mkfs.xfs /dev/hda2 #格式化为xfs

激活交换分区:

  1. $ swapon /dev/hda1

创建LFS的“创作基地”: (我用现有的ubuntu作宿主系统,故从这步开始制作LFS,登录lfs用户之前一直用root,下文有些路径和实际可能有出入,我就不改了)

  1. $ export LFS=/mnt/lfs
  2. $ mkdir -pv $LFS

相关知识点:
export LFS=/mnt/lfs这条命令的作用是为了后面引用“创作基地”的绝对路径方便而设置LFS这样的环境变量。

加载/dev/hda2到“创作基地”:

  1. $ mount /dev/hda2 $LFS

创建必要的目录并设置属性,创建源代码编译用目录:

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

创建工具链目录:

  1. $ mkdir -v $LFS/tools
  2. $ ln -sv $LFS/tools /

相关知识点:
上面这两句就建立了神奇的工具链目录(是工具链目录不是工具链),这样的创建方式是为了在创建工具链和使用工具链创建目标系统的时候对于工具链的位置都是/tools,这样可保证工具链的正常使用.

创建lfs用户,并设置lfs密码:

  1. $ groupadd lfs
  2. $ useradd -s /bin/bash -g lfs -m -k /dev/null lfs
  3. $ passwd lfs

将tools和sources目录的用户改为lfs,以便后面使用lfs来操作这两个目录:

  1. $ chown -v lfs $LFS/tools
  2. $ chown -v lfs $LFS/sources

登陆到lfs用户:

  1. $ su - lfs

相关知识点:
如果不使用lfs用root也是能完成工具链的,不过需要对root的环境变量进行修改,还要防止因为输入错误而导致覆盖主系统下的文件,所以LFS手册中制作工具链部分就是为了解决这种意外的发生而用lfs用户来建立工具链.

建立lfs用户的环境:

  1. $ cat > ~/.bash_profile << "EOF"
  2. exec env -i HOME=$HOME TERM=$TERM PS1='\u:\w\$ ' /bin/bash
  3. EOF
  4.  
  5. $ cat > ~/.bashrc << "EOF"
  6. set +h
  7. umask 022
  8. LFS=/mnt/lfs
  9. LC_ALL=POSIX
  10. PATH=/tools/bin:/bin:/usr/bin
  11. export LFS LC_ALL PATH
  12. EOF
  13.  
  14. $ source ~/.bash_profile

这里利用了bash的环境变量的设置文件将lfs的环境设置为符合编译工具链要求的最少的环境参数
里面最重要的就是PATH这个参数,目的是为了能够利用工具链里面的工具制作工具链:首先查找/tools/bin下是否有需要的命令,如果没有再到 /bin和/usr/bin下找,然后用/bin或/usr/bin下面的命令来帮助生成需要的命令并放在/tools/bin下,这样此消彼涨,最终可完成一个自给自足的工具链。

检查一下,输入export命令查看输出,应该是:

declare -x HOME="/home/lfs"
declare -x LC_ALL="POSIX"
declare -x LFS="/mnt/lfs"
declare -x OLDPWD
declare -x PATH="/tools/bin:/bin:/usr/bin"
declare -x PS1="\\u:\\w\\\$ "
declare -x PWD="/home/lfs"
declare -x SHLVL="1"
declare -x TERM="linux"

如果没有问题,就可以开始下一步

开始工具链的制作
进入LFS包编译目录:

  1. $ cd $LFS/sources

Binutils-2.17 - Pass 1    (10分钟 #非精确,5分钟以内的一律视为5分钟)

  1. $ tar xvf /lfs-sources/binutils-2.17.tar.bz2
  2. $ mkdir -v binutils-build  #binutils建议使用一个空目录来编译
  3. $ cd binutils-build
  4. $ CC="gcc -B/usr/bin/" \
     ../binutils-2.17/configure --prefix=/tools \
     --disable-nls --disable-werror
  5. $ make
  6. $ make install
  7. $ make -C ld clean
  8. $ make -C ld LIB_PATH=/tools/lib
  9. $ cp -v ld/ld-new /tools/bin
  10. $ cd ..
  11. $ rm -rf binutils-build binutils-2.17

GCC-4.1.2 - Pass 1    (50分钟)

  1. $ tar xvf /lfs-sources/gcc-4.1.2.tar.bz2
  2. $ mkdir -v gcc-build
  3. $ cd gcc-build
  4. $ CC="gcc -B/usr/bin/" \
     ../gcc-4.1.2/configure --prefix=/tools \
     --with-local-prefix=/tools --disable-nls \
     --enable-shared --enable-languages=c
  5. $ make bootstrap
  6. $ make install
  7. $ ln -vs gcc /tools/bin/cc
  8. $ cd ..
  9. $ rm -rf gcc-build gcc-4.1.2

注意:这里不要图省事而不删gcc目录,因为这样可能会给后面的编译产生一些意外的错误。

linux-2.6.22.5    (5分钟  #6.3以前的版本是linux-libc-headers,这个地方郁闷了我很久)

  1. $ tar xvf /lfs-sources/linux-2.6.22.5.tar.bz2
  2. $ cd linux-2.6.22.5
  3. $ make mrproper
  4. $ make headers_check
  5. $ make INSTALL_HDR_PATH=dest headers_install
  6. $ cp -rv dest/include/* /tools/include
  7. $ cd ..
  8. $ rm -rf linux-2.6.22.5

Glibc-2.5.1    (1小时)

  1. $ tar xvf /lfs-sources/glibc-2.5.1.tar.bz2
  2. $ mkdir -v glibc-build
  3. $ cd glibc-build
  4. $ ../glibc-2.5.1/configure --prefix=/tools \
        --disable-profile --enable-add-ons \
        --enable-kernel=2.6.0 --with-binutils=/tools/bin \
        --without-gd --with-headers=/tools/include \
        --without-selinux
  5. $ make
  6. $ mkdir -v /tools/etc
  7. $ touch /tools/etc/ld.so.conf
  8. $ make install
  9. $ cd ..
  10. $ rm -rf glibc-build glibc-2.5.1

相关知识点:
这里的参数--enable-kernel=2.6.0,只是为了说明kernel的大版本,所以不需要根据实际的kernel版本来改,即使是用linux-2.6.22也一样只写2.6.0就可以。

(未完待续)

bstaint 说:
Jun 15, 2011 10:05:49 PM

linux-2.6.22.5 (5分钟 #6.3以前的版本是linux-libc-headers,这个地方郁闷了我很久)

谢谢分享 , 我也遇到这个问题 google来的 呵呵

best CBD gummies 说:
Apr 29, 2020 03:52:40 PM

Thanks for sharing superb informations. Your web-site is very cool. I’m impressed by the details that you¡¦ve on this blog. It reveals how nicely you perceive this subject. Bookmarked this website page, will come back for more articles. You, my pal, ROCK! I found simply the info I already searched all over the place and just could not come across. What an ideal site.

best CBD gummies 说:
May 04, 2020 05:57:56 PM

Perfect piece of work you have done, this internet site is really cool with superb info .

best CBD oil 说:
May 07, 2020 06:28:55 PM

Man that was very entertaining and at the same time informative..,*,`

best CBD capsules 说:
May 15, 2020 02:02:14 AM

Just want to say your article is as astonishing. The clarity in your post is simply great and i can assume you’re an expert on this subject. Well with your permission allow me to grab your RSS feed to keep up to date with forthcoming post. Thanks a million and please keep up the enjoyable work.

best CBD oil for pai 说:
May 18, 2020 12:35:00 PM

Solid post! I actually wasn’t aware of this. It’s refreshing to read because I get so annoyed when writers put no thought into their work. It’s obvious that you know what you’re writing about. I shall definitely visit again!

best CBD oil 说:
May 22, 2020 11:11:51 AM

Exactly what I was searching for, thankyou for posting .

shahmeerkhan 说:
Jul 01, 2020 09:18:42 PM

Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve truly enjoyed surfing around your blog posts. In any case I’ll be subscribing to your rss feed and I hope you write again soon. best deer fence

shahmeerkhan 说:
Jul 29, 2020 02:03:52 AM

Human growth hormone supplements have lots of benefits to provide specifically to those who are currently past the age of thirty. Hgh supplements have been proven efficient in dealing with particular problems related to aging and doesn’t trigger as much side effects in comparison with other forms of Human growth hormone products. Additionally, supplements are effective, risk-free as well as inexpensive unlike Human growth hormone injections. cheapest thermal camera

Immobilienmakler Aur 说:
Aug 24, 2020 02:51:46 AM

I’d must examine with you here. Which is not something I usually do! I take pleasure in reading a post that will make folks think. Additionally, thanks for permitting me to remark!

business insurance l 说:
Sep 17, 2020 07:39:01 PM

You created some decent points there. I looked over the internet for your problem and found most individuals should go coupled with with your internet site.

wohnung verkaufen hü 说:
Oct 03, 2020 08:16:21 PM

You produced some decent points there. I looked on the web to the problem and found most people will go in conjunction with with the internet site.

ETHENS 说:
Oct 03, 2020 10:47:28 PM

I don’t know how I ended up being here it.altomergepdf.com. But I am fully satisfied with whatever happened, here I was able to get my hands on the dream tool. In short I am so happy that I came here.

Brookvale Park 说:
Oct 07, 2020 01:36:18 AM

Superb brief which post helped me a lot. Say thank you We seeking your information?–.

ETHENS 说:
Oct 25, 2020 03:20:45 PM

MSBSHSE Maharashtra Board Government Responsible for Maharashtra State Board of Secondary & Higher Secondary Education (MSBSHSE) is Going to Conducted Higher Secondary Certificate (HSC) /Class 12th Maharashtra 12th Important Question 2021 Annual Examination in Month Coming Soon Maha Board 12th Model Question Paper 2021 Revised Time Table for Maha Board 12th Exams Published on Coming Soon List of Eligible Student, you can Practices for Maha Board 12th Model Paper 2021 Revised Guidelines for the you can Download MSBSHSE HSC Question Paper 2021 for College and University Students.

Smm reseller panel 说:
Apr 29, 2021 11:03:02 PM

I would recommend my profile is important to me, I invite you to discuss this topic...

cheap smm panel 说:
May 03, 2021 10:48:46 PM

This website and I conceive this internet site is really informative ! Keep on putting up!

social media reselle 说:
May 15, 2021 06:32:50 PM

I think it could be more general if you get a football sports activity

Steuererklärung Bade 说:
May 19, 2021 11:51:02 PM

I have a mission that I’m just now working on, and I have been at the look out for such information

Faddy 说:
Jul 10, 2021 06:00:53 PM

Very useful info. Hope to see more posts soon!. delta 8 THC

face mask 说:
Jul 18, 2021 08:36:28 PM

Kudos to your place together with terrific hints.. quite possibly That i at the same time are convinced labor is certainly a very powerful aspect of becoming results. face mask

no excuses runner 说:
Jul 28, 2021 04:43:24 PM

Wrapze brings home reusable essentials. Our mission is to produce high quality and eco-friendly products to save the planet from waste mice trap

no excuses runner 说:
Jul 28, 2021 06:24:30 PM

Water and Waste Plumbing are your Local Plumber Darwin. We are certified plumbers and proudly offer an array of plumbing services at affordable prices. plumber darwin

no excuses runner 说:
Jul 28, 2021 07:58:13 PM

Winner of Best of Yolo County 2020 and Best of Weedmaps Kind Farma is Davis Californias Premier medical and recreational Cannabis dispensary. Davis CA dispensary

asdzxc 说:
Aug 09, 2021 01:29:38 AM

Enamel Badges provides a massive range of custom enamel badges in the UK. we offer soft and hard enamel badges, die struck badges, and printed badges. enamel badges

AAA 说:
Nov 05, 2021 03:01:51 PM

Appreciate it intended for placing a really good document! I stumbled upon your blog perfect for the desires. Its full of superb in addition to very helpful threads. Sustain the favorable do the job! jim cramer net worth

AAA 说:
Nov 09, 2021 07:17:46 PM

Your current tunes can be remarkable. You've got a number of quite accomplished musicians. My spouse and i would like anyone the top involving good results. Home improvement

AAA 说:
Nov 09, 2021 11:53:03 PM

Admiring the time and effort you put into your blog and detailed information you offer!.. Kanadan viisumihakemus

AAA 说:
Nov 14, 2021 04:08:50 AM

What is an outstanding post! “I’ll be back” (to read more of your content). Thanks for the nudge! INDIAN VISA APPLICATION ONLINE

AAA 说:
Nov 22, 2021 03:44:48 AM

Great things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks Tenerife ilm

AAA 说:
Nov 30, 2021 09:44:20 PM

Hello, I have browsed most of your posts. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this. Are you aware of any other websites on this subject. cialis 60mg in australia


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter