gentoo安装

为什么选择Gentoo Linux?

http://blog.csdn.net/kissinger2000/archive/2004/09/18/108555.aspx
redhat、suse等很方便,但是装了太多无用的东西,rpm没有完全解决包依赖的问题。Debian解决了rpm的问题,但是没有针对自己的机子优化编译。slackware?我不知道软件编译的时候怎么解决依赖性问题。LFS这种需要寄生在别的系统上的东西,只有玩家才喜欢。而Gentoo,就象是Linux中的FreeBSD,能够自己根据情况优化编译,又有类似ports的portage,太优秀了!还犹豫什么?跟我走进Gentoo的世界吧。

本文参考了www.gentoo.org上的安装说明,删除了一些我认为对于初次安装没有用的东西,另外也补充了自己的一些安装体会。

1、关于安装
这一新的boot CD可以从大多数Linux支持的CD-ROM上引导,包括IDE和SCSI接口的。

从CD引导安装,要求至少486和64M内存以上。(虽然Gentoo Linux在64M内存和64M swap空间的机子上成功编译安装过,但编译过程慢得简直就是一场噩梦。)

Gentoo Linux用三个“stage”包中的一个安装。选哪个包要看你希望你自己编译系统的程度。如果是初次安装,就选择stage3吧,具体的区别等入门后再自己细细体会。

LiveCD ISO映象文件从http://www.ibiblio.org/gentoo/releases/1.4_rc4/x86/ 下载。最好选择"gentoo-3stages" 这个映象,它包含了所有的stage1,stage2和stage3的内容。

2、引导

从光盘引导系统,看到一个具有想象力的界面了吗?这里请选择引导的内核参数。如果你的硬件没有特殊的地方,显示器也支持1024X768的分辨率,直接敲“ENTER”。以下是可用的内核与选项或者按F2看帮助。

可用的内核 描述
gentoo 基本的gentoo内核(缺省)
800 800x600 framebuffer模式
1024 1024x768 framebuffer模式(缺省)
1280 1280x1024 framebuffer模式
nofb 关闭framebuffer模式
smp 在framebuffer模式下启动smp内核
acpi 使acpi=on+在init时加载acpi模块
memtest 引导内存检测程序

可选的引导选项 描述
doataraid 从initrd装载ide raid模块
dofirewire 在initrd中探测fireware模块(为了firewire cdroms等设备)
dokeymap 为了non-us的键盘打开keymap选择
dopcmcia 启动pcmcia服务
doscsi 扫描scsi设备(暂停一些以太网卡)
noapm 不装载apm模块
nodetect 由于hwsetup/kudzu和hotplug引起的不能运行
nodhcp 当检测到网卡时dhcp不能自动启动
nohotplug 关闭装载hotplug服务
noraid 不装载evms模块
nousb 关闭装载usb模块,关闭hotplug
ide=nodma 由于ide设备故障强制性关闭dma支持
cacache 缓存需要使用的cd上的部分到内存,这需要40M的内存,但是允许你umount /mnt/cdrom并且mount另外的cdrom.

一般情况下,敲Enter后等一会儿就可以自动以“root”登录了,你可以看见“#”提示,并且可以用ALT+F2,ALT+F3,ALT+F4切换到其他终端。切记先用“passwd”修改root的密码。(开始的root密码是随机生成的)

请注意看屏幕上的一些说明提示。

3 、Load 内核模块
首先,看看加载了什么模块
# lsmod
最重要是网卡、scsi卡等。如果你的网卡没有被自动配置,那么先用ls /lib/modules/*/kernel/drivers/net看都支持什么网卡模块。找到相应的模块,用以下命令load:
# modprobe 8139too
(8139too是我的网卡,请用自己的网卡代替)
如果有scsi,ATA-RAID等设备,也用类似的方法加载。如果有问题,上Gentoo主页先看看吧。

Gentoo LiveCD一般情况下已经打开了硬盘的DMA支持,如果没有,用hdparm设置硬盘DMA:
# hdparm -d 1 /dev/hda (打开DMA支持)
# hdparm -d1 -A1 -m16 -u1 -a64 /dev/hda (打开DMA支持并且加了另外一些安全的加强性能的选项)
# hdparm -X66 /dev/hda (强制打开Ultra-DMA支持,注意可能引起一些问题)

4 、配置网络
用/sbin/ifconfig看看网络是否已经设置好了。如果好了,可以看到
eth0 Link encap:Ethernet HWaddr 00:50:BA:8F:61:7A
inet addr:192.168.0.2 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: fe80::50:ba8f:617a/10 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1498792 errors:0 dropped:0 overruns:0 frame:0
TX packets:1284980 errors:0 dropped:0 overruns:0 carrier:0
collisions:1984 txqueuelen:100
RX bytes:485691215 (463.1 Mb) TX bytes:123951388 (118.2 Mb)
Interrupt:11

用ping测试一下。如果正常,恭喜了!

如果通过ADSL上网(没有宽带?那就停止吧,不要再继续了^_^),需要运行脚本
# adsl-setup
# adsl-start
如果有问题,检查/etc/ppp/pap-secrets或者/etc/ppp/chap-secrets这两个文件。

最简单的方法是
# net-setup eth0
照着提示设置。

如果DHCP服务可用,那么
# dhcpcd eth0

实在不行,手工配置也不难
# ifconfig eth0 192.168.168.168 broadcast 192.168.168.255 netmask 255.255.255.0
# /sbin/route add -net default gw 192.168.168.1 netmask 0.0.0.0 metric 1 (设置缺省网关)

注意修改/etc/resolv.conf,我的如下:
domain mydomain.com
nameserver 202.101.103.55
nameserver 202.101.103.54
(gentoo默认编辑器是nano。vi需要另外安装。)

如果使用代理,那么还要
# export http_proxy="machine.company.com:1234"
# export ftp_proxy="$http_proxy"
# export RSYNC_PROXY="$http_proxy"

然后ping www.sina.com.cn试试网络是否正常?

5 、设定系统时间(这个可以省略不做)
# date
Thu Feb 27 09:04:42 CST 2003
(If your date is wrong, set your date with this next command)
# date 022709042003
(date MMDDhhmmCCYY)

6 、文件系统、分区和块设备

我喜欢使用cfdisk分区,fdisk不够直观。
# cfdisk /dev/hda

至少得一个/和一个swap分区,这个就不多说了,应该都知道吧。假设
/boot /dev/hda1 ext3 (100M)
swap /dev/hda2
/ /dev/hda3 reiserfs(1.5G)

分好区后,创建文件系统,还是用ext3和reiserfs吧,其他的自己看gentoo主页吧。
# mke2fs -j /dev/hda1
# mkswap /dev/hda2
# mkreiserfs /dev/hda3

7 、mount分区
首先,激活swap分区
# swapon /dev/hda2

接着,创建挂接点并且mount分区
# mkdir /mnt/gentoo
# mount /dev/hda3 /mnt/gentoo (先mount “/” 分区)
# mkdir /mnt/gentoo/boot
# mount /dev/hda1 /mnt/gentoo/boot (再mount "/boot"分区)

8 、Stage包和chroot

初次安装,选择stage3吧
# cd /mnt/gentoo
# tar -xvjpf /mnt/cdrom/gentoo/stage3-x86-1.4_rc4.tar.bz2

然后进入chroot
# mount -t proc proc /mnt/gentoo/proc
# cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf
# chroot /mnt/gentoo /bin/bash
# env-update
# source /etc/profile

9 、用sync取得Current Portage
# emerge sync
需要的时间看你的网络快慢了。

10 、设置Gentoo 编译优化选项(make.conf)
如果不是为了这些优化的编译选项,用debian算了。先安装一个断点续传的软件
#emerge net-www/prozilla

完成后
# nano -w /etc/make.conf

至少修改两个地方:第一个地方是CFLAGS="-O3 -mcpu=i686 –pipe"根据你的CPU改一改,比如我的是P4的CPU,我就改为CFLAGS="-O3 -march=pentium4 –pipe".第二个地方是把注释掉的#FETCHCOMMAND='/usr/bin/proz --no-getch -s ${URI} -P {DISTDIR}'的#号去掉,就是打开PROZILLA,修改好后,按CTRL+X保存退出。

11 、从stage3开始
我们选择了stage3,所以就直接从这开始,如果选择stage1,请看附录一。
# export CONFIG_PROTECT="_*"
# emerge -up system (这里system也可以是world)
# emerge -u system (同上)
# unset CONFIG_PROTECT

12 、设定时区
中国的应该是这个吧
#ln –sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

13 、安装内核与系统的log守护程序
一般情况下,都是这个了
#emerge sys-kernel/gentoo-souces/gentoo-sources-2.4.20-r3.ebuild

完成后,编译内核
# cd /usr/src/linux
# make menuconfig
# make dep && make clean bzImage modules modules_install
# cp /usr/src/linux/arch/i386/boot/bzImage /boot
需要注意的是Gentoo使用devfs文件系统,编译的时候,选择“Code maturity level options”,选Y,然后到”File system”,到”/dev File system”,选Y,把下面的“automatically mount at boot time”选Y。其他的根据自己的情况选吧。

选择下面三个中的一个log守护程序吧
# emerge app-admin/sysklogd
# rc-update add sysklogd default
or
# emerge app-admin/syslog-ng
# rc-update add syslog-ng default
or
# emerge app-admin/metalog
# rc-update add metalog default
or
# emerge app-admin/msyslog
# rc-update add msyslog default

cron也是需要的吧
# emerge sys-apps/dcron
# rc-update add dcron default
# crontab /etc/crontab
or
# emerge sys-apps/fcron
# rc-update add fcron default
# crontab /etc/crontab
or
# emerge sys-apps/vcron
# rc-update add vcron default
You do not need to run crontab /etc/crontab if using vcron.

其他的包自己看着办吧。

14 、修改/etc/fstab
# nano -w /etc/fstab
在本例中,应该是这样吧
# /etc/fstab: static file system information.
#
# noatime turns off atimes for increased performance (atimes normally aren't
# needed; notail increases performance of ReiserFS (at the expense of storage
# efficiency). It is safe to drop the noatime options if you want and to
# switch between notail and tail freely.

# <fs> <mount point> <type> <opts> <dump/pass>

# NOTE: If your BOOT partition is ReiserFS, add the notail option to opts.

/dev/hda1 /boot ext3 noauto,noatime 1 2
/dev/hda3 / reiserfs noatime 0 1
/dev/hda2 none swap sw 0 0
/dev/cdroms/cdrom0 /mnt/cdrom iso9660 noauto,ro 0 0
proc /proc proc defaults 0 0

15 、修改root密码
# passwd

16 、设置hostname
# echo mymachine.mydomain.com > /etc/hostname

17 、修改/etc/hosts
127.0.0.1 localhost
# the next line contains your IP for your local LAN, and your associated machine name
192.168.168.168 mymachine.mydomain.com mymachine

18 、网络设置
如果网卡驱动编译成模块,那么修改/etc/modules.autoload,参照里面的形式修改吧

然后在第一次重新启动后
# nano -w /etc/conf.d/net
# rc-update add net.eth0 default

19 、修改基本设置
主要是时区与键盘设置等,编辑rc.conf,把原来的TIME=‘UTC’改为TIME=‘local’,KEYMAP一般都是"us"

20 、配置bootloader
用stage3,grub已经装好了,但是需要编辑/boot/grub/menu.lst文件,当然以下是要的(如果没有其他bootloader的话)
# grub
grub> root (hd0,0)
grub> setup (hd0)
具体怎么使用grub看IBM DevelopWorks的文章吧。

21 、安装完成
不容易啊,终于可以结束了
# etc-update
# exit (退出chroot)
# cd /
# umount /mnt/gentoo/boot
# umount /mnt/gentoo/rpoc
# umount /mnt/gentoo
# reboot

好好享受自己的优化过的系统吧!

附录一
1.Starting from Stage1

Note: If you are not starting from a stage1 tarball, skip this section.


The stage1 tarball is for complete customization and optimization. If you have picked this tarball, you are most likely looking to have an uber-optimized and up-to-date system. Have fun, because optimization is what Gentoo Linux is all about! Installing from a stage1 takes a lot of time, but the result is a system that has been optimized from the ground up for your specific machine and needs.

Now, it is time to start the "bootstrap" process. This process takes about two hours on my 1200MHz AMD Athlon system. During this time, the GNU C library, compiler suite and other key system programs will be built. Start the bootstrap as follows:

Code listing 11.1: Bootstrapping

# cd /usr/portage
# scripts/bootstrap.sh



The "bootstrap" process will now begin.

Note: Portage by default uses /var/tmp during package building, often using several hundred megabytes of temporary storage. If you would like to change where Portage stores these temporary files, set a new PORTAGE_TMPDIR before starting the bootstrap process, as follows:

Code listing 11.2: Changing Portage's Storage Path

# export PORTAGE_TMPDIR="/otherdir/tmp"



bootstrap.sh will build binutils, gcc, gettext, and glibc, rebuilding binutils, gcc, and gettext after glibc. Needless to say, this process takes a while. Once this process completes, your system will be equivalent to a "stage2" system, which means you can now move on to the stage2 instructions.

2.Starting from Stage2 and continuing Stage1

Note: This section is for those continuing a stage1 install or starting at stage2. If this is not you (ie. you're using a stage3,) then skip this section.


The stage2 tarball already has the bootstrapping done for you. All that you have to do is install the rest of the system.

Note: If you are starting from a pre-built stage2 and want to ensure that your compiler toolchain is fully up-to-date, add the -u option to the commands below. If you don't know what this means, it's safe to skip this suggestion.

Code listing 12.1: Installing the Rest of the System

# emerge -p system
(lists the packages to be installed)
# emerge system



It is going to take a while to finish building the entire base system. Your reward is that it will be thoroughly optimized for your system. The drawback is that you have to find a way to keep yourself occupied for some time to come. The author suggests "Star Wars - Super Bombad Racing" for the PS2.

Building is now complete. Go ahead and skip down to the "Setting your time zone" section.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值