歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> GentooLinux1.4

GentooLinux1.4

日期:2017/3/6 15:49:49   编辑:關於Unix
為什麼選擇Gentoo Linux? redhat、suse等很方便,但是裝了太多無用的東西,rpm沒有完全解決包依賴的問題。Debian解決了rpm的問題,但是沒有針對自己的機子優化編譯。slackware?我不知道軟件編譯的時候怎麼解決依賴性問題。LFS這種需要寄生在別的系統上的東
  為什麼選擇Gentoo Linux?
  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, gclearcase/" target="_blank" >cc, 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.

Copyright © Linux教程網 All Rights Reserved