加載完光驅后
1進行ping命令查看網絡是否通暢
2設置硬盤的標識為GPT(主要用於64位且啟動模式為UEFI,還有一個是MBR,主要用於32位且啟動模式為bois)
parted -a optimal /dev/sda
(parted)print 命令查看是否有除了sda其他分區 如果有則刪除 (parted)rm 2(2為分區的編號,有其他的也需要一並刪除)
(parted)
mklabel gpt
此操作會清除掉所有分區上的所有數據 如果是MBR 則使用命令mklabel msdos(此命令創建的主分區最多為4個)
(parted)
unit mib 告訴parted制定長度的單位為兆
(parted)
mkpart primary 1 3 從硬盤的第1M地址到第3M的地址
(parted)
name 1 grub 命名為grub
(parted)
set 1 bios_grub on 設置flags為bios_grub
(parted)
print 查看修改后的信息
然后創建boot引導分區 128M
(parted)
mkpart primary 3 131
(parted)
name 2 boot
(parted)
mkpart primary 131 643
(parted)
name 3 swap
(parted)
mkpart primary 643 -1
(parted)
name 4 rootfs
如果用的是UEFI去引導的分區 需要標識下boot分區為EFI(通常64位機器上都是UEFI)
(parted)
set 2 boot on
quit 退出
這個時候后我們看ls /dev/sda* 就會出來五個結果
4分區已經建好了,下面一步需要在分區上掛文件類型
btrfs 功能強大但是不穩定
ext2 啟動慢且沒有文件日志系統
ext3 文件日志系統增強,可靠
ext4 推薦的通用所有平台文件系統
f2fs 被外界認為不成熟 但是在gentoo的usb、microSD 卡和其他基於閃存的存儲來說是個不錯的選擇
JFS IBM的高性能日志記錄文件系統
ReiserFS 處理許多小文件的成本小,比其他文件系統維護成本大
XFS 對硬件問題的兼容性較小
vfat 不支持任何權限設置。它主要是用於與其他操作系統的互操作性(主要是Microsoft Windows)但也是必需的一些系統固件(如UEFI)。
NTFS 只用於與微軟Windows系統的互操作性
當我們使用ext2, ext3, ext4 的文件系統用在一個小於8G的分區上時,我們得設置增加一個計算節點數量計算的選項
ex2時 使用root #
mkfs.ext2 -T small /dev/<device>
ex3或ex4時 使用root #
mkfs.ext2 -j -T small /dev/<device>
這通常會生成四倍的節點量(從16kb到4kb)可通過root #
mkfs.ext2 -i <ratio> /dev/<device>調節比例
我們這里使用ext4和ext2
處理文件系統的工具 sys-fs/e2fsprogs已經存在於系統設置中,因此我們一句命令即可解決
root #
mkfs.ext2 /dev/sda2 將boot引導為sda2
然后可以看到我們的節點的信息變為31232,算下來122M,這就是當時我們建的128M,然后4k一個節點
root #
mkfs.ext4 /dev/sda4 將root設置為sda4
接下來初始化swap交換空間 root #
mkswap /dev/sda3 然后激活交換空間
root #
swapon /dev/sda3
分區和文件類型都已經搞好了,接下來就是掛載到目錄上去
root #
mount /dev/sda4 /mnt/gentoo
掛載boot引導分區的時候,我們要創建一個掛載目錄
root #
mkdir /mnt/gentoo/boot
root #
mount /dev/sda2 /mnt/gentoo/boot
root #
chmod 1777 /mnt/gentoo/tmp
root #
date 121513162016 表示2016年12月15號13點16分
root #
ntpd -q -g 時區設置在下面給出
root #
export http_proxy="http://proxy.server.com:port"
root #
export ftp_proxy="http://proxy.server.com:port"
root #
cd /mnt/gentoo目錄
root #
links https://www.gentoo.org/downloads/mirrors/ 去瀏覽下載 如果有代理則root #
links -http-proxy proxy.server.com:8080 https://www.gentoo.org/downloads/mirrors/
root #
lynx https://www.gentoo.org/downloads/mirrors/ 但它不是菜單驅動的。
root #
tar xvjpf stage3-*.tar.bz2 --xattrs 提取文件 x提取 v顯示過程 j使用bzip2解壓縮 p保存權限 f指定解壓縮的是文件而非標准輸入 --xattrs為了根據擴展的屬性存儲到對應的文件文檔里
root #
nano -w /mnt/gentoo/etc/portage/make.conf 打開配置文件,影響Portage和GCC編譯器
# Use the same settings for both variables CXXFLAGS="${CFLAGS}"
8、安裝gentoo基礎系統
獲取鏡像途徑1、portage會使用make.conf里的GENTOO_MIRRORS 變量來獲取鏡像列表。也可以使用mirrorselect工具root #mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
2、第二個獲取鏡像的途徑是通過配置文件/etc/portage/repos.conf/gentoo.conf來獲取gentoo倉庫。首先創建文件夾root #
mkdir /mnt/gentoo/etc/portage/repos.conf
復制dns配置到本地確保網絡鏈接
然后復制gentoo倉庫的文件到這里root #
cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
root #
cp -L /etc/resolv.conf /mnt/gentoo/etc/
因為環境改變,所有需要掛載一些必要的文件
root #
mount -t proc proc /mnt/gentoo/proc
root #
mount --rbind /sys /mnt/gentoo/sys
root #
mount --make-rslave /mnt/gentoo/sys
root #
mount --rbind /dev /mnt/gentoo/dev
root #
mount --make-rslave /mnt/gentoo/dev
后面兩個目錄是綁定掛載。--make-rslave為了支持下面的安裝
更改根目錄在新環境中root #
chroot /mnt/gentoo /bin/bash 根目錄改變從/改變到/mnt/gentoo
root #
source /etc/profile 將設置生效
root #
export PS1="(chroot) $PS1" 主提示符更改,為幫助我們記住這個會話在chroot環境中。
現在所有的更改都在新的環境中去了
配置Portage
root #
emerge-webrsync
安裝Portage快照
上面命令會更新Portage tree24小時外的快照,如果想更新時間近點的,可使用emerge --sync可獲取更新一小時前的Portage tree
更新完如果提示有需要更新的items,可使用
root #
eselect news list
root #
eselect news read
選擇配置文件安裝
root #
eselect profile list 可用來查看配置文件列表
為了使用純凈的64位環境,可使用no-multilib 配置項root #
eselect profile set 11 (
default/linux/amd64/13.0/no-multilib選項前綴數字) 這個會比較小,包比較少
USE="-gtk -gnome qt4 kde dvd alsa cdr"(如果想要禁用所有缺省的選項,則-*)
不過我選的時系統去判斷選項root #eselect profile set default/linux/amd64/13.0/systemd 這個會比較大 包比較多
root #emerge --ask --update --deep --newuse @world
配置USE變量
USE變量很有用,決定了程序編譯哪些是支持的,哪些是不支持的。如gnome gtk -kde -qt4 編譯項目的時候,用GNOME (and GTK) 支持,不支持KDE (and Qt)
配置的詳細信息root #
less /usr/portage/profiles/use.desc 按q退出
如果你想修改USE,則用命令root #nano
-w /etc/portage/make.conf
如啟用KDE-based系統,支持DVD, ALSA 和 CD 錄音
設置時區
root #
ls /usr/share/zoneinfo
root #
echo "Asia/Shanghai" > /etc/timezone
en_US ISO-8859-1
root #
emerge --config sys-libs/timezone-data
配置本地化
root #
nano -w /etc/locale.gen
en_US.UTF-8 UTF-8
zh_CN GB18030
zh_CN.GBK GBK
zh_CN.GB2312 GB2312
zh_CN.UTF-8 UTF-8
root #
locale-gen 使其生效
9、安裝source
root #
eselect locale list 查看環境列表
root #
eselect locale set 10 選擇環境
root #
env-update && source /etc/profile && export PS1="(chroot) $PS1" 配置生效
安裝Linux kernel
root #
emerge --ask sys-kernel/gentoo-sources
root #
ls -l /usr/src/linux 安裝完后會有符號鏈接到linux內核中去
然后開始編譯安裝linux內核 1、手動根據手冊進行配置 2、利用genkernel自動編譯安裝 為了優化環境我們使用手動
root #
emerge --ask sys-apps/pciutils 合並相關幫助信息
root #
cd /usr/src/linux 進去內核目錄
root #
make menuconfig 菜單模式查看
現在開始配置gentoo內核,配置內核有幾個好處1,更加靈活2,內核更小3,更短的編譯時間4,學習5,嚴重的無聊6,不少的內核配置知識7,完全控制
大多數有三種選項,一種是什么都不創建,一種是創建內核目錄,一種是創建模塊。用戶自己可以決定加載或不加載什么模塊。
創建在內核中需要固件支持,所以在內核的配置文件中要FW_LOADER=y和
CONFIG_FIRMWARE_IN_KERNEL=y這兩個或者菜單選項中
Device Drivers ---> Generic Driver Options ---> -*- Userspace firmware loading support [*] Include in-kernel firmware blobs in kernel binary
一般默認就是對的。
SATA的支持在linux中是鏈接到libata的,在SCSI子系統下面。所以,SATA驅動在SCSI驅動配置文件選項下。系統的存儲設備被當做SCSI的設備。 SCSI disk/cdrom的支持也是必須的。
第一個SATA硬盤被標記為/dev/sda,第一個SATA CD/DVD驅動被標記為 /dev/sr0
Device Drivers ---> SCSI device support ---> <*> SCSI device support //我這邊顯示的是--*-- <*> SCSI disk support <*> SCSI CDROM support [ ] SCSI low-level drivers ---> <*> Serial ATA and Parallel ATA drivers (libata) --->
tips:非標准的驅動放在Serial ATA and Parallel ATA drivers (libata)下的SCSI low-level drivers中
USB的配置,xHCI支持usb3.0也兼容USB 1.0, 1.1, 2.0, 3.0 EHCI支持USB2.0 1.x的我們基本已經不使用了。
Device Drivers ---> USB support ---> <*> Support for Host-side USB --- USB Host Controller Drivers <*> xHCI HCD (USB 3.0) support <*> EHCI HCD (USB 2.0) support < > OHCI HCD (USB 1.1) support < > UHCI HCD (most Intel and VIA) support
多個處理器,超線程和多核系統的配置
Processor type and features ---> [*] Symmetric multi-processing support [*] SMT (Hyperthreading) scheduler support [*] Multi-core scheduler support (NEW)
Power management and ACPI options --->
[*] ACPI (Advanced Configuration and Power Interface) Support
壓縮內核模塊
首先我們得在USE配置里添加對壓縮模塊的支持,在USE(/etc/portage/make.conf)里添加
USE后面加上“lzma tools zlib debug doc static-libs python3_5”
root #
emerge --ask --oneshot --changed-use sys-apps/kmod 然后執行這條指令去開啟model壓縮,還需要選擇一條壓縮的
root #
cd /usr/src/linux
root #
make menuconfig
Enable loadable module support ---> [*] Compress modules on installation Compression algorithm () ---> <X> GZIP XZ
內核的配置文件通常在/usr/src/linux/.config或者自動生成在 /proc/config.gz 文件中,但是首先得把這些配置文件關聯到內核中去
首先輸入命令make menuconfig,然后按/鍵搜索,搜索CONFIG_TMPFS_XATTR會顯示很多信息
Symbol: TMPFS_XATTR [=n] 代表內核配置入口是否可以被搜索得到,為n的時候,表明該設置未被啟用
Type: boolean 代表該搜索是一個布爾值 enabled disabled
Prompt: Tmpfs extended attributes make menuconfig入口里的文本,控制.config文件里的變量TMPFS_XATTR
Depends on: TMPFS [=y]CONFIG_TMPFS
必須被啟用才能看到這個,這里已經啟用了,(
所以
[=y]),如果不是這樣,請先啟用CONFIG_TMPFS.
Location: ... make menuconfig 結構設置的位置,這個設置為了Tmpfs extended屬性
Selected by: TMPFS_POSIX_ACL [=n] && TMPFS [=y] 如果兩個選項都為y,CONFIG_TMPFS_XATTR會自動啟用而不會停止啟用
有了上面的信息,可以較容易的翻譯任何CONFIG_*文件,簡單來說,每個用戶必須
1、啟用Depends
2、導航到Location:
對應的目錄
3、開關Prompt的值
查看一些問題的命令
root #
uname -v 可以查看引導內核編譯的時間
ls -l /usr/src/linux/arch/i386/boot/bzImage 硬盤上的內核鏡像最后一次編譯的時間
devtmpfs
devtmpfs 的功用是在 Linux 核心 啟動早期建立一個初步的 /dev,令一般啟動程序不用等待 udev,縮短 GNU/Linux 的開機時間。
Device Drivers ---> Generic Driver Options ---> [*] Maintain a devtmpfs filesystem to mount at /dev [ ] Automount devtmpfs at /dev, after the kernel mounted the rootfs
然后去文件系統,然后選擇你使用的文件系統的支持。不要編譯使用在root文件系統中充當module的文件系統。Gentoo系統無法掛載這個partition。
File systems ---> (Select one or more of the following options as needed by your system) <*> Second extended fs support <*> Ext3 journalling file system support <*> The Extended 4 (ext4) filesystem <*> Reiserfs support <*> JFS filesystem support <*> XFS filesystem support ... Pseudo Filesystems ---> [*] /proc file system support [*] Virtual memory file system support (former shm fs)
如果使用PPPoE 或 撥號上網,需要如下設置
Device Drivers ---> Network device support ---> <*> PPP (point-to-point protocol) support <*> PPP support for async serial ports <*> PPP support for sync tty ports
大多數系統有多核處理,所以對於支持Symmetric multi-processing也很重要。
Processor type and features --->
[*] Symmetric multi-processing support
在多核系統中,每個核心算作一個處理器。然后添加usb支持(如鍵盤和鼠標)
Device Drivers --->
[*] HID Devices --->
<*> USB Human Interface Device (full HID) support
因為我們分區用的是GPT模式,所以我們要啟用GPT的支持
-*- Enable the block layer ---> ... Partition Types ---> [*] Advanced partition selection ... [*] EFI GUID Partition support
10、配置已經完成現在可以進行編譯安裝了
root #
make && make modules_install //進行編譯
編譯完成后,把進行復制到 /boot/中去
root #
make install //復制鏡像到boot中去,System.map文件和內核配置文件
文件系統信息
在Linux下,所有在系統中的分區都必須列出在/etc/fstab,該文件包含這些分區的掛載點,以及他們用哪些特殊的選項去掛載(自動與否,是否用戶可以掛載他們)。
創建fstab文件
該文件里的數據每行有六個字段,用空格隔開,每個字段都有他們的意思。1、設備文件的路徑 2、掛在點 3、分區所掛載的文件系統 4、掛載的時候使用的選項,逗號分割 5、分區在需要的時候是否可以被廢棄 6,文件系統是否需要自檢
root #
blkid 可以檢查Labels和UUIDs
root #
nano -w /etc/conf.d/hostname 可以修改host文件
root #
nano -w /etc/conf.d/net 域名修改
11、配置網絡
之前網絡配置是為了在安裝的時候配置的,現在我們需要在環境中去配置網絡。
所有網絡的配置信息都聚集在/etc/conf.d/net。詳細的解釋在/usr/share/doc/netifrc-*/net.example.bz2中可以查看。
首先安裝gentoo網絡接口netifrc
root #
emerge --ask --noreplace net-misc/netifrc
默認使用DHCP,需要安裝DHCP客戶端。
靜態ip地址如下
config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" routes_eth0="default via 192.168.0.1"
dhcp配置如下
config_eth0="dhcp"
在boot期間自動開啟網絡
如果想要在boot階段啟用網絡接口,需要在默認運行級別中添加
root #
cd /etc/init.d
root #
ln -s net.lo net.eth0
root #
rc-update add net.eth0 default
root #
nano -w /etc/rc.conf
root #
nano -w /etc/conf.d/keymaps
root #
emerge --ask app-admin/sysklogd
root #
rc-update add sysklogd default
root #
emerge --ask sys-process/cronie
root #
rc-update add cronie default
root #
crontab /etc/crontab
root #
emerge --ask sys-apps/mlocate
root #
rc-update add sshd default
root #
nano -w /etc/inittab
# SERIAL CONSOLES s0:12345:respawn:/sbin/agetty 9600 ttyS0 vt100 s1:12345:respawn:/sbin/agetty 9600 ttyS1 vt100
Filesystem | Package |
Ext2, 3, and 4 | sys-fs/e2fsprogs |
XFS | sys-fs/xfsprogs |
ReiserFS | sys-fs/reiserfsprogs |
JFS | sys-fs/jfsutils |
VFAT (FAT32, ...) | sys-fs/dosfstools |
Btrfs | sys-fs/btrfs-progs |
root #
emerge --ask net-misc/dhcpcd
root #
emerge --ask --verbose sys-boot/grub:2
root #
echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf)
然后
root #
emerge --ask --update --newuse --verbose sys-boot/grub:2 去重新計算World set (Portage)的依賴。
root #
grub-install /dev/sda
root #
grub-install --target=x86_64-efi --efi-directory=/boot
root #
grub-mkconfig -o /boot/grub/grub.cfg
Generating grub.cfg ... Found linux image: /boot/vmlinuz-3.16.5-gentoo Found initrd image: /boot/initramfs-genkernel-amd64-3.16.5-gentoo done
輸出中必須要至少有一個linux鏡像被找到。這些是引導系統的必要條件。
14重新啟動系統
退出chrooted環境,卸載所有已掛載的分區。然后輸出一個神奇的命令:reboot
root #
exit
cdimage ~#
cd
cdimage ~#
umount -l /mnt/gentoo/dev{/shm,/pts,}
cdimage ~#
umount -R /mnt/gentoo
cdimage ~#
reboot
15用戶管理
直接使用root被認為是危險的,下面是各個用戶組的對應的功能
Group | Description |
audio | Be able to access the audio devices. |
cdrom | Be able to directly access optical devices. |
floppy | Be able to directly access floppy devices. |
games | Be able to play games. |
portage | Be able to access portage restricted resources. |
usb | Be able to access USB devices. |
video | Be able to access video capturing hardware and doing hardware acceleration. |
wheel | Be able to use su. |
16硬盤清理
刪除tarballsroot #
rm /stage3-*.tar.bz2*