Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1146124
  • 博文数量: 53
  • 博客积分: 10025
  • 博客等级: 上将
  • 技术积分: 1640
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-15 17:05
文章分类

全部博文(53)

文章存档

2011年(1)

2010年(3)

2009年(25)

2008年(24)

我的朋友

分类:

2009-02-18 09:57:16

关于jhalfs建立LFS的文章不多见,而且有些文章只介绍了jhalfs执行之前的情况,执行之后的操作,包括内核编译等讲解不多,笔者经过一段摸索探索了自己的完整建立lfs的方法,给各位初学者参考!

准备好lfslivecd-x86-6.2-5.iso vmware下启动(vmware下创建linux环境请看另一篇)

1、进入可以一直回车直到命令行出现

2、设置密码(执行jhalfs前最好设置一下密码)

       passwd root

passwd jhalfs

3、如远程控制启动SSH,否则在原机上操作不启动SSH

# /etc/rc.d/init.d/sshd start

客户端软件可以使用PuTTY,远程登陆到服务器

4、分区

fdisk /dev/sda  可以使用cfdisk

/dev/sda

/dev/sda1------------/ swap

/dev/sda2------------/

    mkswap /dev/sda1    格式化swap

mke2fs /dev/sda2    格式化sda2使用格式是ext3

    swapon /dev/sda1    使用swap分区

export LFS=/mnt/lfs

    mkdir –pv $LFS

mount /dev/sda2 $LFS    sda2加到到mnt目录下

mkdir –pv $LFS (lfs必须在jhalfs设置时和这里保持一致)

chmod -v a+wt /mnt/lfs

chown -v jhalfs /mnt/lfs (这个很重要否则jhalfs提示没有写权限)

$LFS/tools/不用创建,jhalfs会自动创建

注意也不用创建lfs帐户了,jhalfs会处理

5、转到jhalfs用户

    # su jhalfs

6、转到jhalfs用户下的jhalfs

    $ cd

$ cd jhalfs-2.1/ 

7、修改编译优化参数(可选)

    $ vi /home/jhalfs/jhalfs-2.1/optimize/opt_config.d/O3pipe

 以下是O3pipe的内容:

CFLAGS_O3pipe="-O3 -pipe"改成你需要的

CXXFLAGS_O3pipe=$CFLAGS_O3pipe

LDFLAGS_O3pipe="unset"

OTHER_CFLAGS_O3pipe=$CFLAGS_O3pipe

OTHER_CXXFLAGS_O3pipe=$CXXFLAGS_O3pipe

OTHER_LDFLAGS_O3pipe=$LDFLAGS_O3pipe

再改O3pipe_march文件

    $ vi /home/jhalfs/jhalfs-2.1/optimize/opt_config.d/O3pipe_march

    以下是O3pipe_march的内容:

CFLAGS_O3pipe_march=$CFLAGS_O3pipe" -march=pentium4"改成你使用的CPU类型

CXXFLAGS_O3pipe_march=$CFLAGS_O3pipe"  -march=pentium4"同上

LDFLAGS_O3pipe_march=$LDFLAGS_O3pipe

 

OTHER_CFLAGS_O3pipe_march=$CFLAGS_O3pipe" -march=pentium4"同上

OTHER_CXXFLAGS_O3pipe_march=$CXXFLAGS_O3pipe" -march=pentium4"同上

OTHER_LDFLAGS_O3pipe_march=$LDFLAGS_O3pipe

8、然后开始执行 make或者time make

    出现以下菜单(注红线标注的地方是值得注意的地方,其他地方默认设置都可以了)

    --- BOOK Settings  --->                                                           

    Use BOOK (Linux From Scratch)  --->选择要编译的类型       

         (X) Linux From Scratch要编译LFS选择个                                                                   

         ( ) Cross-Compiled Linux From Scratch这个是CLFS                                                   

         ( ) Cross-Compiled Linux From Scratch (Sysroot method)也是CLFS不过还在开发                                  

         ( ) Cross-Compiled Linux From Scratch (Embedded Systems)貌似嵌入系统的CLFS                                

         ( ) Hardened Linux From Scratch  HLFS这个是用在安全方面的                                                          

         ( ) Beyond Linux From Scratch    BLFS这个大家都知道                                                       

     Release (Working Copy)  --->     使用哪个版本的BOOK

         ( ) SVN                        最新的BOO,开发中的                                           

         (X) Working Copy               稳定版,也是光盘上带的                                          

         ( ) Branch or stable book      分枝??                                        

         (/usr/share/LFS-BOOK-6.2-XML) Loc of working copy (mandatory)选择书的位置,默认的主可以                                    

         [ ] Add custom tool support                                                                      

         [ ] Add blfs-tool support                                                                         

   --- General Settings  --->常规设置

         [ ] Change the default user/group for this build     建立LFS的用户和组,可以不选                                 

         (/mnt/build_dir) Build Directory 建立的LFS位置,自己按需要改 (这里设置/mnt/lfs)                                 

         [*] Retrieve source files                            源的位置                                 

         (/lfs-sources) Package Archive Directory             别改,默认就可以                                 

         () FTP mirror              如果需要下载,使用这个地址下                                 

        [*]   Always retrieve kernel package (see help)                                       

        [*] Run the makefile                                 退出菜单后直接make                                 

        [ ] Rebuild files                                                                     

--- Build Settings  --->         

        [*] Run testsuites  运行测试,默认是选上的,建议不要取消                                                                                  

        Tests level (Only final system Glibc, GCC and Binutils testsuites)  --->  可以选择测试的内容默认的就行了                     

        Flavour (Don't stop on test suite failures)  --->                                                 

       [ ] Use a custom fstab file             使用fstab文件,需要指定fstab文件位置                                                             

       [ ] Build the kernel       要不要自动编译内核,需要指定内核配置文件的位置,一般没有设定好的配置文件不要选择此项,jhalfs执行完毕后自己编译内核                                                             

       [*] Strip Installed Binaries/Libraries  好像是自动清理调试代码                                                             

       [*] Install vim-lang package            vim的语言支持补丁,建议加上                                                              

       (GMT) TimeZone                         时区                                                              

       ($LANG) Language                       语言设置,你在使用光盘启动的时候选择的语言就是你$LANG的内容

       Groff page size (letter)  --->  

    --- Advanced Features  --->高级设置

       [*] Create SBU and disk usage report                                                            

       [ ] Run comparison analysis on final stage                                                       

       [*] Use optimization (see help)              使用优化参数                                                

           Optimization level  (Final system only)  --->全部默认就行了                                             

   --- Internal Settings (WARNING: for jhalfs developers only)  --->                           

      [ ] Rebuild the Makefile (see help)                                                   

          ---                                                                                    

      Load an Alternate Configuration File                                                  

      Save Configuration to an Alternate File                                               

完成后退出程序开始配置

余下的过程都是自动化的,耐心等待完成即可,一般不会出现错误!

开始编译了,如果机器快的话5个小时就可以收工了

 

执行完毕后会看到以下信息

To be able to boot your new system you need to follow the next steps:

- Enter to the chroot using the command found in the section

   - Entering the Chroot Environment - except if building CLFS with METHOO=boot.

- Set a password for the root user

- Edit /etc/fstab, /etc/hosts, /etc/sysconfig/clock, /etc/sysconfig/console,

  /etc/sysconfig/network, /etc/sysconfig//network-devices/ifconfig.eth0/ipv4

  and any other configuration file required to suit your needs.

- Set-up the boot loader.  See the relevant book section.

- Unmount the filesystems.

If you are an experienced LFS user, several of those steps can be skipped or done in

a different way.  But then, that is something that you already know and there is no

need to discuss it here.

Have a nice day :-)

 

下面的过程就很重要了,一般在网上也找不到文档,由于jhalfs是自动化过程,所以执行完毕后也不知道到哪一步了,网上说直接执行到第7章了其实也不全面,jhalfs除了内核没有编译(如果你有配置文件也可以选择让jhalfs执行)bootstrip的安装也完成了,剩下的工作就是配置、编译内核、设置grub,如果这个过程没有问题就大功告成了!

1、  Jhalfs执行完毕后处于jhalfs用户的状态,可以在该用户下直接进入chroot工作环境执行余下的工作

可以从下面的第二步开始

2、  如果在jhalfs执行完成后你在配置后重启仍然不能正常启动lfs需要重新配置或者中间有重启操作可以执行下面的动作进入

1)设定环境

export LFS=/mnt/lfs

  mkdir -pv $LFS

  mount /dev/sda2 $LFS

swapon /dev/sda1 (加载交换分区,可跳过)

mount --bind /dev /mnt/lfs/dev (这个非常重要,关系到grub能不能找到设备,这个要在进入chroot环境之前做

  2)加载必要的文件系统(jhalfs执行完毕后的起点)

  mount -vt proc proc $LFS/proc

mount -vt sysfs sysfs $LFS/sys

mount –vt devpts devpts $LFS/dev/pts

mount –vt tmpfs shm $LFS/dev/shm

  3)Chroot到目标系统下

  chroot "$LFS" /usr/bin/env -i \

  HOME=/root TERM="$TERM" PS1='\u:\w\$ ' \

   PATH=/bin:/usr/bin:/sbin:/usr/sbin \

  /bin/bash --login

4)安裝kernel

如果是VM下的虚拟机,编译的时候别忘了sata支持,否则你的lfs绝对起不来。

内核部分等笔者有时间补上

编译代码

tar jxvf linux-2.6.16.38.tar.bz2

cd linux-2.6.16.38

patch -Np1 -i ../linux-2.6.16.27-utf8_input-1.patch

make mrproper

make menuconfig

make

make modules_install

cp -v arch/i386/boot/bzImage /boot/lfskernel-2.6.16.38

cp -v System.map /boot/System.map-2.6.16.38

cp -v .config /boot/config-2.6.16.38

5)設定下面文件符合自己需求

 /etc/sysconfig/clock

 /etc/sysconfig/network

 /etc/sysconfig/network-devices/ipconfig.eth0/ipv4

 /etc/resolv.conf

  /etc/hosts

  /etc/fstab

6)设置grub

输入grub

Root (hd0,1)

Setup (hd0)

Quit

设置启动菜单

cat > /boot/grub/menu.lst << "EOF"

# Begin /boot/grub/menu.lst 

# By default boot the first menu entry.

default 0

# Allow 30 seconds before booting the default.

timeout 30

# Use prettier colors.

color green/black light-green/black

# The first entry is for LFS.

title LFS 6.2

root (hd0,1)

kernel /boot/lfskernel-2.6.16.38 root=/dev/sda2

EOF

8.退出chroot下载磁盘

   退出之前最好设置以下root的密码passwd后输入新密码

logout

umount $LFS/dev

umonut /dev/sda2

 余下的工作重启就可以了

 

也可以先编译内核

cd
tar xvf /lfs-sources/linux-2.6.16.27.tar.bz2    (
先建立config文件)(出现了磁盘IO错误,估计是我不应该把文件放到root目录,而应该放到新建的磁盘上去,重来了,这次把文件放到$LFS下面了)
patch -Np1 -i /lfs-sources/linux-2.6.16.27-input.utf8.patch
make menuconfig
ls -la  (
查看.config)
cd;
vi READMI
mkdir jhalfs-config
cp /mnt/lfs/linux-2.6.16.27/.config jhalfs-conf/linux-2.6.16.27.config
export SRC_ARCHIVE=/lfs-sources;
./lfs -D /mnt/lfs -K ~/jhalfs-config/linux-2.6.16.27.config -T 0 -M  
提示我说happyhappy,晕
vi config/common  
修改optimize1,再运行上面时给我看优化设置情况,我yes后退出了

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