1. 程式人生 > 其它 >Gentoo Linux 安裝手冊

Gentoo Linux 安裝手冊

前期準備

啟動盤(Boot media)

Gentoo Linux installation media

  • Minimal installation CD
  • Admin CD
  • SystemRescue

Creating bootable LiveUSB drives under Windows
Rufus

Stage archives

  • stage3-openrc
  • stage3-systemd

遠端登入

  • 開啟ssh服務:
    rc-service sshd start
    or
    /etc/init.d/sshd start

  • 設定密碼:
    passwd

以便使用securecrt、ssh client遠端登入上傳stage等(有時線上下載很慢,而區域網上傳很快)

配置網路

網絡卡檢測

  • ifconfig 命令
  • ip 命令

自動配置網路

  • DHCP
root #dhcpcd eth0
  • net-setup
root # net-setup eth0
  • pppoe-setup
root # pppoe-setup
root # pppoe-start

無線網路

準備磁碟

檢視是否支援uefi

root@archiso ~ #  ls /sys/firmware/efi 
config_table  efivars  fw_platform_size  fw_vendor  runtime  runtime-map  systab

fdisk分割槽

fdisk /dev/sda
  • GPT for UEFI (-g)

/dev/sda1 : /boot 256M EFI (-t 1)
/dev/sda2 : / 100G ext4
/dev/sda3 : /home 20G ext4
/dev/sda4 : /swap 1G (-t 19)
(記憶體< 512 MB,分割槽分配2倍記憶體大小的空間;> 1024 MB,可以分配較少的空間甚至不需要swap 分割槽。) -t 82

  • MBR for BIOS (-o)

/dev/sda1 : /boot 100M(32-100M) 設啟動標記 -a
/dev/sda2 : / 20G
/dev/sda3 : /home 20G
/dev/sda4 : /swap 1G (記憶體< 512 MB,分割槽分配2倍記憶體大小的空間;> 1024 MB,可以分配較少的空間甚至不需要swap 分割槽。) -t 82

建立檔案系統

mkfs.vfat -F 32 /dev/sda1
mkfs.ext4 /dev/sda2
mkfs.ext4 /dev/sda3
mkswap /dev/sda4

掛載分割槽

mount /dev/sda2 /mnt/gentoo
mkdir /mnt/gentoo/boot
mount /dev/sda1 /mnt/gentoo/boot
mkdir /mnt/gentoo/home
mount /dev/sda3 /mnt/gentoo/home
swapon /dev/sda4

安裝基本系統

安裝stage3

正確設定日期/時間

  • 顯示時間
    date

  • 手動設定

date 100313162021

如果顯示的日期/時間不正確,可以使用date MMDDhhmmYYYY命令

  • 自動設定
ntpd -q -g

安裝stage

  • 下載Stage3
cd /mnt/gentoo
links http://www.gentoo.org/main/en/mirrors.xml

選擇國內速度較快的映象,進入releases/amd64/autobuilds/目錄裡。你將會看到所有適合你的計算機體系結構的stage檔案(它們也可能放在各個獨立的子體系名稱的子目錄裡)。選擇一個,然後按D來下載。下載完以後,再按Q退出瀏覽器。

或使用SSH Secure Shell登入上傳stage3檔案

  • 解壓Stage3
tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner

配置編譯選項

nano -w /mnt/gentoo/etc/portage/make.conf
# These settings were set by the catalyst build script that automatically
# built this stage.
# Please consult /usr/share/portage/config/make.conf.example for a more
# detailed example.
COMMON_FLAGS="-march=native -O2 -pipe"
CFLAGS="${COMMON_FLAGS}"
CXXFLAGS="${COMMON_FLAGS}"
FCFLAGS="${COMMON_FLAGS}"
FFLAGS="${COMMON_FLAGS}"

# NOTE: This stage was built with the bindist Use flag enabled
PORTDIR="/var/db/repos/gentoo"
DISTDIR="/var/cache/distfiles"
PKGDIR="/var/cache/binpkgs"

# This sets the language of build output to English.
# Please keep this setting intact when reporting bugs.
LC_MESSAGES=C

# EMERGE_DEFAULT_OPTS is set automatically by livecd-tools autoconfig during first live boot.
# This should be equal to number of processors, see "man emerge" for details.
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --jobs=4 --load-average=4"
MAKEOPTS="-j5"                                                                     

CFLAGS="-march=native -O2 -pipe"
CXXFLAGS="${CFLAGS}" # 兩個變數使用相同的設定
MAKEOPTS="-j5" #MAKEOPTS定義在安裝軟體的時候同時可以產生並行編譯的數目,CPU數目加一是個不錯的選擇

  • 檢視cpu資訊:
cat proc/cpuinfo

Chrooting

  • 選擇映象站點:
mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
mirrorselect -i -r -o >> /mnt/gentoo/etc/portage/make.conf
  • 拷貝DNS資訊:
cp -L /etc/resolv.conf /mnt/gentoo/etc/
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/
  • 掛載必要的檔案系統:
mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --bind /run /mnt/gentoo/run
  • 進入新的系統環境:
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"
  • 掛載boot分割槽
mount /dev/sda1 /boot

配置Portage

安裝ebuild repository snapshot

fetch the latest snapshot (which is released on a daily basis) from one of Gentoo's mirrors and install it onto the system:

emerge-webrsync(fetch the latest portage snapshot)
  • 可選 下載解壓快照

Gentoo映象snapshots/目錄: portage-latest.tar.bz2
tar -xvjf /mnt/gentoo/portage-latest.tar.bz2 -C /usr

  • 可選 更新portage樹:
emerge --sync (Updating the Portage tree)
or
emerge --sync --quiet

選擇合適的Profile

eselect profile list
eselect profile set ×

Updating the @world set

emerge --ask --verbose --update --deep --newuse @world

配置USE

  • default USE
    The default USE settings are placed in the make.defaults files
  • description
    A full description on the available USE flags can be found on the system in /var/db/repos/gentoo/profiles/use.desc.
  • currently active USE
    The easiest way to check the currently active USE settings is to run emerge --info and select the line that starts with USE:
root #emerge --info | grep ^USE
USE="X acl alsa amd64 berkdb bindist bzip2 cli cracklib crypt cxx dri ..."

設定時區

ls /usr/share/zoneinfo
echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data

設定locale

nano -w /etc/locale.gen
locale-gen
eselect locale list
eselect locale set x
  • 更新環境變數:
env-update && source /etc/profile

編譯核心

可選 安裝firmware

emerge --ask sys-kernel/linux-firmware

package.license

sys-kernel/linux-firmware  linux-fw-redistributable no-source-code

安裝核心原始碼

選擇核心:如gentoo-sources

emerge --ask sys-kernel/gentoo-sources
eselect kernel list
eselect kernel set x
ls -l /usr/src/linux

手動編譯核心

Most information can be gathered by emerging sys-apps/pciutils which contains the lspci command

配置核心

cd /usr/src/linux
make menuconfig

[Configuring the Linux kernel - Gentoo Wiki](%3Ca href="https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel"%3EConfiguring the Linux kernel - Gentoo Wiki%3C/a%3E)

  • 必須啟用的選項:

  • 顯示卡:Xorg/Configuration

  • 音效卡:ALSA

  • 網絡卡:根據具體網絡卡晶片型號,檢視wiki。

  • 無線網絡卡晶片驅動查詢:Linux Wireless

其他選項根據需要新增,不瞭解保持預設即可.

編譯核心與模組

make && make modules_install

安裝核心到啟動分割槽

make install 

cp arch/x86_64/boot/bzImage /boot/kernel-3.10.10-gentoo

This will copy the kernel image into /boot together with the System.map file and the kernel configuration file.

可選 安裝initramfs

To install an initramfs, install sys-kernel/genkernel first, then have it generate an initramfs:

emerge --ask sys-kernel/genkernel
genkernel --install --kernel-config=/path/to/used/kernel.config initramfs

The initramfs will be stored in /boot/. The resulting file can be found by simply listing the files starting with initramfs:

ls /boot/initramfs*

可選 使用發行版核心

Distribution Kernels are ebuilds that cover the complete process of unpacking, configuring, compiling, and installing the kernel. The primary advantage of this method is that the kernels are upgraded to new versions as part of @world upgrade without a need for manual action. Distribution kernels default to a configuration supporting the majority of hardware but they can be customized via /etc/portage/savedconfig.

emerge --ask sys-kernel/installkernel-gentoo
emerge --ask sys-kernel/gentoo-kernel

System administrators who want to avoid compiling the kernel sources locally can instead use precompiled kernel images:

emerge --ask sys-kernel/gentoo-kernel-bin

可選 使用genkernel編譯核心

emerge genkernel
  • 可選:複製安裝光碟上的核心配置檔案:
zcat /proc/config.gz > /usr/share/genkernel/arch/x86_64/kernel-config
  • 編譯:
genkernel --menuconfig all

一旦genkernel執行完成,一個包括全部模組和initrd的核心將被建立。在後面配置載入程式時我們將會用到這個核心和initrd。請記下核心和initrd的名字,因為您將在配置載入程式的時候用到他們(Grub Legacy使用)。initrd將會在啟動真正的系統前自動識別硬體(如同安裝光碟一樣)。

ls /boot/kernel* /boot/initramfs*

配置系統

檔案系統fstab

  • 建立/etc/fstab
/dev/sda1   /boot        vfat    defaults,noatime     0 2
/dev/sda2   none         swap    sw                   0 0
/dev/sda3   /            ext4    noatime              0 1
/dev/cdrom  /mnt/cdrom   auto    noauto,user          0 0
  • Filesystem labels and UUIDs
blkid

網路資訊

  • Host name, Domainname, etc
nano -w /etc/conf.d/hostname
  • Configuring Network
nano -w /etc/conf.d/net
  • Automatically start networking at boot
cd /etc/init.d
root #ln -s net.lo net.eth0
root #rc-update add net.eth0 default

系統資訊

  • Gentoo uses /etc/rc.conf to configure the services, startup, and shutdown of your system.
nano -w /etc/rc.conf
  • Root Password
passwd

root允許弱口令: enforce=none
vim /etc/security/passwdqc.conf

min=disabled,24,11,8,7
max=72
passphrase=3
match=4
similar=deny
random=47
enforce=none
retry=3
  • Gentoo uses /etc/conf.d/hwclock to set clock options.
nano -w /etc/conf.d/hwclock

安裝系統工具

  • System Logger
emerge syslog-ng
rc-update add syslog-ng default
  • 可選:File Indexing
emerge mlocate
  • 可選:Remote Access
rc-update add sshd default
  • 可選:DHCP Client
emerge dhcpcd

配置啟動項

Using GRUB2

  • BIOS
emerge --ask --verbose sys-boot/grub
grub-install /dev/sda
  • UEFI
echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
emerge --ask sys-boot/grub
grub-install --target=x86_64-efi --efi-directory=/boot

Optionally, install theos-prober utility (provided through the sys-boot/os-prober package) to have GRUB2 probe for other operating systems when running thegrub2-mkconfig command. In most instances, this will enable GRUB2 to automatically detect other operating systems (Windows 7, Windows 8.1, etc.).

Generating GRUB2 configuration:

grub-mkconfig -o /boot/grub/grub.cfg

可選:Using GRUB Legacy

emerge sys-boot/grub:0

編輯配置檔案

nano -w /boot/grub/grub.conf

Example grub.conf

# 預設選擇哪個列表來引導。0表示第一個, 1表示第二個,以此類推。
default 0
# 引導預設列表前等待多少秒
timeout 30
# 使用漂亮、“臃腫”的spalsh影象來增加一點趣味:)
# 如果您沒有安裝顯示卡,請將這行註釋掉
splashimage=(hd0,0)/boot/grub/splash.xpm.gz

title Gentoo Linux 3.10.10
# 核心映象(或者作業系統)所在分割槽
root (hd0,0)
kernel /boot/kernel-3.10.10-gentoo root=/dev/sda2

title Gentoo Linux 3.10.10 (rescue)
# 核心映象(或者作業系統)所在分割槽
root (hd0,0)
kernel /boot/kernel-3.10.10-gentoo root=/dev/sda2 init=/bin/bb

# 接下來的四行只有在您與Windows系統進行雙啟動的情況下才需要。
# 本例中,windows系統位於/dev/sda6。
title Windows XP
rootnoverify (hd0,5)
makeactive
chainloader +1
#win7下注釋掉makeactive

Setting up GRUB Legacy using grub-install:
Creating /etc/mtab:

grep -v rootfs /proc/mounts > /etc/mtab

Install GRUB Legacy:

grub-install --no-floppy /dev/sda

重啟系統

exit
cd
umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -l /mnt/gentoo{/boot,/proc,}
reboot

音效卡配置

ALSA - Gentoo Wiki

To choose the right driver, first detect the used audio controller. Use lspci for this task:

lspci | grep -i audio

核心配置

You need to activate the following kernel options:

Device Drivers --->
    <*> Sound card support
        <*> Advanced Linux Sound Architecture --->
            [*] PCI sound devices  --->
                Select the driver for your audio controller.
                HD-Audio  --->
                   Select a codec or enable all and let the generic parse choose the right one:
                   [*] Build Realtek HD-audio codec support
                   [*] ...
                   [*] Build Silicon Labs 3054 HD-modem codec support
                   [*] Enable generic HD-audio codec parser
            [*] USB sound devices  --->
                Must have as some cards are presented as USB devices.
                [*] USB Audio/MIDI driver
General setup --->
    [*] System V IPC

The lsmod command can be helpful.

If the system has more than 8 sound outputs (Each HDMI output on a GPU will count as one), the max number of sound cards will need to be increased:

KERNEL

Device Drivers --->
    <*> Sound card support
        <*> Advanced Linux Sound Architecture --->
            [*] Dynamic device file minor numbers
            (32) Max number of sound cards

軟體

The media-sound/alsa-utils package provides some tools for troubleshooting and testing the sound system. It is a good idea to merge the package if it is not already installed:

emerge --ask alsa-utils

配置

許可權

If the acl USE flag enabled globally and a login daemon (e.g. systemd-logind or elogind) is being used (i.e the system is using a desktop profile) permissions to sound cards will be handled automatically. Permissions can be checked using getfacl:

getfacl /dev/snd/controlC0 | grep larry
user:larry:rw-

Add the user you want to be able to access the sound card to the audio group:

gpasswd -a larry audio

服務

You can now start ALSA:

/etc/init.d/alsasound start

To start ALSA at boot time, add it your boot runlevel:

rc-update add alsasound boot

Mixer 調節音量,取消靜音

If you can't hear anything, the output channels may be muted. Unmute the channels with the desktop environment's mixer or with alsamixer by selecting the appropriate channels and pressing the M key to mute or unmute:

alsamixer

測試聲音

If everything above is perfect, you should now be able to test your sound card and your speakers. We will use the speaker-test command line tool from package media-sound/alsa-utils (this should already be installed as per our previous recommendation).

speaker-test -t wav -c 2

安裝X桌面環境

安裝Xorg

  • 檢測顯示卡資訊:
dmesg | grep video
lspci  | grep -i VGA
  • 配置INPUT_DEVICE、VIDEO_CARDS變數:
    在安裝Xorg之前,你需要在/etc/portage/make.conf檔案中設定兩個重要的變數。
    (For mouse, keyboard, and Synaptics touchpad support)
    INPUT_DEVICE="evdev  synaptics"   
        (對Intel整合顯示卡)
    VIDEO_CARDS="intel"
    (對nVidia顯示卡)
    VIDEO_CARDS="nvidia"
    (或,對ATI Radeon顯示卡)
    VIDEO_CARDS="radeon"
    (VMware虛擬機器)
    VIDEO_CARDS="vmware"
    (VirtualBox虛擬機器)
    VIDEO_CARDS="virtualbox"
  • 安裝xorg-server“
emerge -pv xorg-drivers

First of all, make sure udev is in your USE flags

echo "x11-base/xorg-server udev" >> /etc/portage/package.use

Next, install Xorg

emerge -av xorg-server

注:現在比較新的版本的Xorg(大概是 1.5 以後的吧) 使用 evdev 替換了 keyboard 和 mouse ,確保 udev 標記在安裝 xorg-server 時被啟用。

  • 更新環境變數
env-update
source /etc/profile
  • 使用startx
    安裝 twm 和 xterm 之後 執行 startx 測試 X 是否正常。
    測試正常之後可以刪除 twm 和 xterm。
emerge -v twm xterm
startx

dbus開機啟動

安裝桌面環境

dwm

lxde

xfce

gnome

kde


參考:

Gentoo AMD64 Handbook - Gentoo Wiki

✎﹏鍵落驚風雨,碼成泣鬼神~~