---
title: "Gentoo Linux X86 安装"
author: "sqe_james"
date: "2008-06-13T18:40:21Z"
tags: [".net", "Fortran", "Linux", "Perl", "Unix"]
slug: "gentoo-linux-x86"
draft: false
lastmod: "2008-11-29T17:12:19Z"
id: 203078
url: "https://janwer.iteye.com/blog/203078"
---

1\. 下载 minimal installation CD , 并刻录成启动盘;

 

2.  使用如下命令可以查看机器的配置情况，如CPU, 硬盘，内在等;

livecd root # lspci

 

如果你需要加载一些新硬件，可用 **modprobe** ，如

livecd root # modprobe r8169

 

通过如下命令可探测你硬件的性能，并可估算出大概的安装时间：

\# grep bogo /proc/cpuinfo

 bogomips:3337.81

 

\# hdparm -tT /dev/sda

  /dev/hda:

Timing cached reads:1100 MB in 2.00 seconds=549.97 MB/sec

Timing buffered disk reads:224 MB in  3.01 seconds =  74.36 MB/sec

 

\# grep MemTotal /proc/meminfo  
    MemTotal:509248 kB

 

3\. 配置网络

假如你的网络现在不能工作，可以通过 net-setup 命令配置网络。你可能需要先通过 modprobe 配置引导你的网卡。假如你使用ADSL ，可用 pppoe-setup 和 pppoe-start 来安装。对于 PPTP 的支持，首先编辑 /etc/ppp/chap-secrets 和 /etc/ppp/options.pptp 然后使用 pptp &lt;server ip&gt; 配置。

对于无线网络，使用 iwconfig 来设置无线参数，然后也通过 net-setup 来配置，或者手动运行 ifconfig.dhcpcd/route 。假如你通过代理上网的话，别忘了通过 export http\_proxy, ftp\_proxy 和 RSYNC\_PROXY 初始化系统。

 

livecd root # net-setup eth0

 

或者你可以手动启动你的网络，如下示例通过指派一个IP 地址，定义路由地址和服务名称来激活网路。

livecd root # ifconfig eth0 192.168.1.10/24  
livecd root # route add default gw 192.168.1.1  
livecd root # echo nameserver 192.168.1.1 &gt; /etc/resolv.conf

 

4\. 安装 CD  允许运行 sshd, irssi lynx links or wget 等等.

例如：启动 sshd 服务

livecd root # time /etc/init.d/sshd start  
 * Generating hostkey ...  
(sshd generates the key and displays more output)  
 * starting sshd ...                             \[ok]

real  0m13.688s  
user  0m9.420s  
sys   0m0.090s

 

5\. 创建分区

livecd ~ # fdisk /dev/sda

(The rest of this guide uses the following partitioning scheme)

 

p , 显示现有分区信息

n-----&gt;p , 创建新分区( 输入 n ，然后再输入 p , 接着输入你要创建的分区号, 回车，分区大小如+102M ，如果是 /boot 分区的话别忘了激活，通过命令 a , 然后要激活的分区，如果是 swap 分区，加紧忘了选择分区类型，输入命令 t ，然后输入你的设置为 swap 的编号如:2 , 再输入 swap 代码82 , 这些命令均在 fdisk 模式下运行)

 

接着格式化文件系统，

mke2fs(ext2), mke2fs -j(ext3), mkreiserfs(Reiserfs),mkfs.xfs(xfs),mkfs.jfs(Jfs)

 

如下创建 Reiserfs 文件系统：

(ext2 is all you need on the /boot partition)  
livecd ~ # mke2fs /dev/hda1

(Let's use reiserfs on the main partition)  
livecd ~ # mkreiserfs  /dev/hda3

(Create and activate swap)  
livecd ~ # mkswap /dev/hda2 && swapon /dev/hda2

 

接着挂载文件系统

livecd ~ # mount /dev/hda3 /mnt/gentoo  
livecd ~ # mkdir /mnt/gentoo/boot  
livecd ~ # mount /dev/hda1 /mnt/gentoo/boot  
livecd ~ # cd /mnt/gentoo

 

至此文件系统已创建并格式完成。接下来进行系统的安装配置。

 

6\. 设置时间

(Check the clock)  
livecd gentoo # date  
Mon Mar  6 00:14:13 UTC 2006

(Set the current date and time if required)  
livecd gentoo # date 030600162006 (Format is MMDDhhmmYYYY)  
Mon Mar  6 00:16:00 UTC 2006

 

7\. 下载stage 和最新Portage

由于官方在国内下载网速较慢，所以可以选择较近的镜像站点来下载，如，由于我在上海所以选择最近的韩国镜像来下载。当然你也可以事先下载好。

 livecd gentoo # links [http://www.gentoo.org/main/en/mirrors.xml](http://www.gentoo.org/main/en/mirrors.xml)

(Pick a mirror, move to the releases/x86/2008.0\_beta2/ directory, highlight the  
stage3 of your choice, probably the i686 stage3 and press D to download it)

 

(Or download it directly with wget without choosing a nearby mirror)

livecd gentoo # wget

 http://ftp.lecl.net/pub/gentoo/releases/x86/2008.0\_beta2/stages/stage3-i686\*tar.bz2  

 

接着解压

livecd gentoo # tar xjpf stage3*

 

然后下载最新的Portage 并解压

livecd usr # wget [http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2](http://gentoo.osuosl.org/snapshots/portage-latest.tar.bz2)  
livecd usr # time tar xjf portage-lat*

 

7\. Chrooting

挂载 /proc 文件系统，cp /etc/resolv.conf 文件，然后 chroot 到你的Gentoo 环境。

livecd usr # cd /  
livecd / # mount -t proc proc /mnt/gentoo/proc  
livecd / # cp -L /etc/resolv.conf /mnt/gentoo/etc/  
livecd / # chroot /mnt/gentoo /bin/bash  
livecd / # env-update && source /etc/profile  
&gt;&gt;&gt; Regenerating /etc/ld.so.cache...

 

设置时区

livecd / # ls /usr/share/zoneinfo  
(Using Brussels as an example)  
livecd / # cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

livecd / # date  
Wed Mar  8 00:46:05 CST 2008

 

设置主机名和域名

livecd / # cd /etc  
livecd etc # echo "127.0.0.1 janwer.dematch janwer localhost" &gt; hosts  
livecd etc # sed -i -e 's/HOSTNAME.\*/HOSTNAME="mybox"/' conf.d/hostname  
(Use defined host name and check)  
livecd etc # hostname janwer  
livecd etc # hostname -f

janwer.dematch

 

8\. 内核配置

在编译内核前，先配置一下 /etc/make.conf

方案一  
CHOST="i686-pc-linux-gnu"  
CFLAGS="-march=prescott -mtune=prescott -O2 -pipe -fomit-frame-pointer -mfpmath=sse,387 -mmmx -msse -msse2 -msse3 -m3dnow -fforce-addr -finline-functions -finline-limit=400 -Wa,-march=prescott -falign-loops -fgcse-after-reload"  
CXXFLAGS="${CFLAGS}"  
LDFLAGS="-Wl,-O1 -s"

方案二  
CHOST="i686-pc-linux-gnu"  
CFLAGS="-march=prescott/nocona -mtune=prescott -O3 -pipe -fomit-frame-pointer -mfpmath=sse,387 -mmmx -msse -msse2 -msse3 -m3dnow -fforce-addr -finline-limit=400 -Wa,-march=prescott"  
CXXFLAGS="${CFLAGS}"  
LDFLAGS="-Wl,-O1 -s"

\# CPU优化系数

MAKEOPTS="-j3"

\# 以下不使用的功能

USE="-bluetooth -ipv6 -gnome -kde -gtk"  
\# 最近的源码境像站点  
GENTOO\_MIRRORS="http://ftp.kaist.ac.kr/pub/gentoo/ ftp://ftp.kaist.ac.kr/gentoo/ ftp://ftp.lecl.net/pub/gentoo/ http://ftp.lecl.net/pub/gentoo/ ftp://ftp.daum.net/gentoo/ http://ftp.daum.net/gentoo/ http://ftp.twaren.net/Linux/Gentoo/ ftp://ftp.twaren.net/Linux/Gentoo/ http://ftp.ncnu.edu.tw/Linux/Gentoo/ ftp://ftp.ncnu.edu.tw/Linux/Gentoo/ http://ftp.cs.pu.edu.tw/Linux/Gentoo/ ftp://ftp.cs.pu.edu.tw/Linux/Gentoo/ http://gentoo.cs.nctu.edu.tw/gentoo/ ftp://gentoo.cs.nctu.edu.tw/gentoo/ "

SYNC="rsync://rsync.asia.gentoo.org/gentoo-portage"

 

接着安装内核, 然后进行配置，编译和 cp arch/i386/boot/bzImage 文件到 /boot

如下安装一个 hardened-sources ( 服务器版)

livecd etc # emerge hardened-sources  
livecd etc # cd /usr/src/linux  
livecd linux # make menuconfig  
(Configure your kernel)  
livecd linux # make –j3 ( 根据你的系统来写 CPU 数加 1)

(Elapsed time depends highly on the options you selected)

livecd linux # make modules\_install  
livecd linux # cp arch/i386/boot/bzImage /boot/kernel

 

9\. 配置系统

编辑 /etc/fstab , 用实际的分区名称替换 BOOT,ROOT, 和 SWAP ，别忘了检查一下文件格式是否和你安装的相匹配。

livecd linux # cd /etc  
livecd etc # nano -w fstab

( 注意：如果 /boot 是 reiserfs 文件格式，别忘了在 opt 里加上 notail )  
/dev/hda1   /boot     ext2    noauto,noatime      1 2  
/dev/hda3   /         reiserfs    noatime , notail     0 1  
/dev/hda2   none      swap    sw                 0 0

 

在 /etc/conf.d/net 中配置网络，增加 net.eth0 初始化脚本到默认运行级别，假如你有多张网卡，把它们链接到 net.eth0 脚本并增加到默认运行级别，用 nano 或 以下 命令来编辑 /etc/conf.d/net 脚本。

livecd etc # cd conf.d  
livecd conf.d # echo 'config\_eth0=( "192.168.123.176/24" )' &gt;&gt; net  
livecd conf.d # echo 'routes\_eth0=( "default via 192.168.123.1" )' &gt;&gt; net  
livecd conf.d # rc-update add net.eth0 default  
(If you compiled your network card driver as a module,  
add it to /etc/modules.autoload.d/kernel-2.6)  
livecd conf.d # echo r8169 &gt;&gt; /etc/modules.autoload.d/kernel-2.6  
(If you want to reconnect via ssh after you have rebooted your new box)  
livecd conf.d # rc-update add sshd default

 

设置 root 密码

livecd conf.d # passwd  
New UNIX password: type\_the\_password  
Retype new UNIX password: type\_the\_password\_again

passwd: password updated successfully

 

配置时区

livecd conf.d # nano -w /etc/conf.d/clock

TIMEZONE="Asia/Shanghai"

CLOCK=”local”

 

1.      安装系统工具

syslogger and a cron daemon

livecd conf.d # emerge syslog-ng vixie-cron  
livecd conf.d # rc-update add syslog-ng default  
livecd conf.d # rc-update add vixie-cron default ( 可选，用于任务调试 )

 

  **安装一些必须的系统工具**

（ xfspprogs,reiserfsprogs or jfsutils,dhcpcd,ppp and so on )

livecd conf.d # emerge xfsprogs        (If you use the XFS file system)  
livecd conf.d # emerge jfsutils        (If you use the JFS file system)  
livecd conf.d # emerge reiserfsprogs   (If you use the Reiser file system)  
livecd conf.d # emerge dhcpcd          (If you need a DHCP client)  
livecd conf.d # emerge ppp             (If you need PPPoE ADSL connectivity)

 

**安装配置** **grub**

livecd conf.d # emerge grub  
livecd conf.d # nano -w /boot/grub/grub.conf

 

**Example grub.conf**  
default 0  
timeout 10

title Gentoo  
root (hd0,0)  
kernel /boot/kernel root=/dev/hda3

 

**Install grub**  
livecd conf.d # grub  
Probing devices to guess BIOS drives. This may take a long time.

grub&gt; root (hd0,0)  
 Filesystem type is ext2fs, partition type 0xfd

grub&gt; setup (hd0)  
 Checking if "/boot/grub/stage1" exists... yes  
 Checking if "/boot/grub/stage2" exists... yes  
 Checking if "/boot/grub/e2fs\_stage1\_5" exists... yes  
 Running "embed /boot/grub/e2fs\_stage1\_5 (hd0)"...  16 sectors are embedded.  
succeeded  
 Running "install /boot/grub/stage1 (hd0) (hd0)1+16 p (hd0,0)/boot/grub/stage2 /boot/  
grub/menu.lst"... succeeded  
Done.

grub&gt; quit

 

**Reboot**  
livecd conf.d # exit  
livecd / # umount /mnt/gentoo/proc /mnt/gentoo/boot /mnt/gentoo  
livecd / # reboot  
(Don't forget to remove the CD)

 

**Add a new user**  
janwer~ # adduser -g users -G lp,wheel,cdrom,portage,cron -m janwer  
janwer ~ # passwd janwer  
New UNIX password: Set Janwer's password  
Retype new UNIX password: Type Janwer's password again  
passwd: password updated successfully

 

**Use mirrorselect and set MAKEOPTS**  
janwer ~ # emerge mirrorselect  
janwer ~ # mirrorselect -i -o &gt;&gt; /etc/make.conf  
janwer ~ # mirrorselect -i -r -o &gt;&gt; /etc/make.conf  
(Usually, (the number of processors + 1) is a good value)  
janwer ~ # echo 'MAKEOPTS="-j3"' &gt;&gt; /etc/make.conf

 

**View USE flags in use and enable or disable some**  
janwer ~ # emerge -vpe world  
(Portage displays the packages and their USE flags, as an example, let's  
disable ipv6 and fortran, and enable unicode)  
janwer ~ # echo 'USE="nptl nptlonly -ipv6 -fortran unicode"

 

**Define locales**  
janwer ~ # cd /etc  
janwer etc # nano -w locale.gen (add en.UTF-8 UTF-8 zh.UTF-8 UTF-8 zh.GBK GBK)  
janwer etc # locale-gen

 

Last but not least, you may want to alter the CFLAGS variable in your /etc/make.conf to optimise the code to your specific needs. Please note that using a long list of flags is rarely needed and can even lead to a broken system. It is recommended to specify the processor type in the march option and stick to -O2 -pipe .

You may also want to switch to ~x86 . You should only do this if you can deal with the odd broken ebuild or package. If you'd rather keep your system stable, don't add the ACCEPT\_KEYWORDS variable. Adding FEATURES="ccache" is also a good idea.

 

Last edit of make.conf  
janwer etc # nano -w make.conf  
(Add the following line)  
FEATURES="ccache"  
(Only add the following if you know what you're doing)  
ACCEPT\_KEYWORDS="~x86"

 

**Update your packages**  
(Install ccache)  
janwer etc # emerge ccache

(Please note that the switch to ~x86 causes many packages to be upgraded)

janwer etc # emerge -vpuD --newuse world  
(Take a good look at the package list and their USE flags,  
remove blocking packages if any, and start the lengthy process)

janwer etc # time emerge -vuD --newuse world

(79 packages have been (re)compiled)

real  180m13.276s  
user  121m22.905s  
sys   36m31.472s

 

(Remerge libtool to avoid further potential problems)  
janwer etc # emerge --oneshot libtool

 

(Update config files, make sure you do not let dispatch-conf  
update config files you have edited)

janwer etc # dispatch-conf

(If perl has been updated, you should run the perl-cleaner script)

janwer etc # time perl-cleaner all  
real  1m6.495s  
user  0m42.699s  
sys   0m10.641s