安装


准备u盘

  1. 在 gentoo 官网下载 mini 安装 iso 文件和 openrc 的 stage3 文件。
  2. 使用 UltraISO.v.9.6.2.3059 软件先打开 iso 文件,然后把 stage3 文件添加到 iso 文件中,然后保存。
  3. 写入硬盘镜像,把 u 盘格式化写入这个新的 iso 文件。

u盘启动

  1. r9000p 插入 u 盘重启,按 F2 进入 boot 设置
  2. 在进入界面的中下方,列出了当前可启动的几种介质,把 u 盘调到第一个
  3. 更多设置里面,找到 secure boot,选择为 disable, 然后按 F10 保存退出。
  4. 顺利进入 gentoo 的启动界面,等到进入命令行,输入 shutdown -h now 关机,退出。

添加硬盘

  1. 拆掉 r9000p 后盖
  2. 拔掉电池线
  3. 把右侧主硬盘拔掉,插入新的硬盘。
  4. 原来的 win 盘先收起来,等后面安装好了在插上去。或者现在插到备用盘位置也可以。

网络配置

  1. 重新上电后,进入 gentoo 系统
  2. 使用 ifconfig 查看当前网卡状态,发现只有有线可用,接上网线,使用 ifconfig, 发现获得了 ip,使用 ping www.baidu.com 来查看外网连接状态。

硬盘分区

  1. ls /dev/nv* 查看硬盘状态,发现可以看到影片了, nvme0 下面只有一个 nvme0n1,而 nvme1 下面有5个,分别是 nvme1n1p1, nvme1n1p2, nvme1n1p3, nvme1n1p4, nvme1n1p5。可以确定下来, nvme0n1 这个就是我们先添加的影片, nvme1n1 这个就是原装的 win 硬盘
  2. fdisk 和 gpt 中选择 fdisk, 虚拟内存选择为 128g 的配置,因为考虑到休眠,所以是准备物理内存 * 2,当前内存是 16g,未来肯定扩大内存,官方说是 32g,但是欧洲那边说最多可以 64g,所以把虚拟内存先弄大点,后期好扩展物理内存。
  3. fdisk nvme0n1 进入 fdisk 配置。使用p 打印当前硬盘状态。g 用来生成硬盘 gpt 标签,d 用来删除分区,n 用来新建分区。 参考: https://blog.csdn.net/weiweiliulu/article/details/103990458
  4. 上一步在 g 了之后,在 n,然后选取 1 分区,起始扇区使用默认的 2048,大小使用 +256M,这时候生成了第一个分区,是 linux 文件系统。然后 t,默认第一分区,选择分区类型 1,这样第一分区就转换为 efi 文件系统了。
  5. n,默认第二分区,默认起始地址,大小 +128G,生成了一个 128g 的分区,t,默认第二分区,选择类型 19,这样第二分区就转换为 swap 分区了。
  6. n,默认第三分区,默认起始地址,默认结束地址,剩余空间全部作为第三分区,也就是根目录。
  7. p 最后检查以下,分区没有问题,就 w 进行分区写入。然后可以通过 /dev/nv* 来检查分区。
  8. mkfs.vfat -F 32 /dev/nvme0n1p1 把第一个分区格式化为 fat32 格式。
  9. mkfs.ext4 /dev/nvme0n1p3 把第三个分区格式化为 ext4 格式。
  10. mkswap /dev/nvme0n1p2 把第二个分区作为 swap 分区,swapon /dev/nvme0n1p2 使能虚拟内存。
  11. mount /dev/nvme0n1p3 /mnt/gentoo 挂载 根目录。

stage3

  1. date 检查当前的 utc 时间对不对。如果不对,ntpd -q -g 使用联网时间,或者date 100313162016 手动设置为 2016-10-03 13:16 类似这样。
  2. cp /mnt/cdrom/stage3* /mnt/gentoo/ 把预先下载的 stage3 文件复制到 根目录。
  3. cd /mnt/gentoo tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner 解压 stage3 压缩包。
  4. vi /mnt/gentoo/etc/portage/make.conf 在 common_files 里面添加 -march=native,在最后添加一行 MAKEOPTS="-j9" 设置为核心数 + 1.

安装基础系统

  1. mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf 选择镜像地址,把 china 里面都选上就行了。
  2. mkdir --parents /mnt/gentoo/etc/portage/repos.conf cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
  3. cp --dereference /etc/resolv.conf /mnt/gentoo/etc/ 复制 dns
  4. 准备 chroot
    root #mount --types 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
  5. chroot
    root #chroot /mnt/gentoo /bin/bash
    root #source /etc/profile
    root #export PS1="(chroot) ${PS1}"
  6. mount /dev/sda1 /boot 挂载 boot 分区,为了后面生成 bootloader 等
  7. emerge-webrsync 更新 ebuild 仓库
  8. eselect news list 列出新闻,eselect news read阅读新闻,man news.eselect 查看说明
  9. eselect profile list 列出可选的系统特性
  10. eselect profile set 5 我选择了 desktop(stable) 11 emerge --ask --verbose --update --deep --newuse @world 按照新特性更新系统。
  11. portageq envvar ACCEPT_LICENSE 查看当前的许可证选项
  12. emerge --ask vim chroot 之后,编辑器只剩 nano 了,所以先安装 vim, 方便编辑配置文件。
  13. vim /etc/portage/make.conf 里面添加 ACCEPT_LICENSE="-* @FREE" 只安装免费软件和文档。如果有些软件需要额外的许可证,可以在/etc/portage/package.license 下建立独立的文件,添加许可证。
  14. ls /usr/share/zoneinfo 在这个下面找到合适的时区。 echo "Asia/Shanghai" > /etc/timezone 把上海时区写入时间文件。emerge --config sys-libs/timezone-data 更新当前的系统时区。
  15. date 重新检查一下时间,并修改为当地时间。
  16. 增加语言
    vim /etc/locale.gen
    en_US ISO-8859-1
    en_US.UTF-8 UTF-8
    zh_CN.UTF-8 UTF-8
    zh_CN.GBK GBK
    zh_CN GB18030
    zh_CN.GB2312 GB2312
  17. locale-gen 生成语言,locale -a 检查语言
  18. eselect locale list 列出可选语言,eselect locale set 6 选择 en_US.utf8
  19. 也可以通过修改 /etc/env.d/02locale 来手动设置系统语言。
    LANG="en_US.UTF-8"
    LC_COLLATE="C.UTF-8"
  20. env-update && source /etc/profile && export PS1="(chroot) ${PS1}" 重载环境。

配置内核

  1. emerge --ask sys-kernel/gentoo-sources 下载内核,ls -l /usr/src/linux 查看内核文件
  2. emerge --ask sys-apps/pciutils 安装 pciutils,为了使用 lspci 来查看系统信息。
  3. 配置 gentoo
    Gentoo Linux --->
    Generic Driver Options --->
    [*] Gentoo Linux support
    [*]   Linux dynamic and persistent device naming (userspace devfs) support
    [*]   Select options required by Portage features
        Support for init systems, system and service managers  --->
          [*] OpenRC, runit and other script based systems and managers
  4. 在 x86_64 平台,有些硬件错误没有打印到 dmesg 里面,而是/dev/mcelog 里面,但是这需要安装 app-admin/mcelog,并且内核里面需要开启相应支持。
    Processor type and features
    Machine Check / overheating reporting (NEW)
        <*> Support for deprecated /dev/mcelog character device (NEW)
  5. 配置 devtmpfs
    Device Drivers --->
    Generic Driver Options --->
    [*] Maintain a devtmpfs filesystem to mount at /dev
    [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs
  6. 配置硬盘
    Device Drivers --->
    SCSI device support  --->
      <*> SCSI disk support

    nvme 支持

    Device Drivers
    NVME Support
        <*> NVM Express block device
        <*> NVMe multipath support
        <*> NVMe hardware monitoring
        <M> NVM Express over Fabrics FC host driver
        <M> NVM Express over Fabrics TCP host driver

    注意: NVM Express over Fabrics FC host driver 这个暂时编译为模块,fabrics 是用于分布式 nvme 存储用的,暂时用不到. 参考: https://wiki.gentoo.org/wiki/NVMe
    https://blog.csdn.net/weixin_30399871/article/details/98532040
    https://blog.csdn.net/BtB5e6Nsu1g511Eg5XEg/article/details/87944261

  7. 文件系统
    File systems --->
    <*> Second extended fs support
    <*> The Extended 3 (ext3) filesystem
    -*- The Extended 4 (ext4) filesystem
    DOS/FAT/NT Filesystems  --->
    <*> MSDOS fs support
    <*> VFAT (Windows-95) fs support
    <*> exFAT filesystem support
    (utf8) Default iocharset for exFAT
    <*> NTFS file system support
    <*> NTFS write support
    Pseudo Filesystems --->
    -*- /proc file system support
    -*- Tmpfs virtual memory file system support (former shm fs)

    注意:exFat 适用于 u 盘需要大于 4G 单个文件的情况,u 盘不推荐 ntfs格式。 ntfs 主要是为了以后读写从盘的 win 文件。 参考: https://baijiahao.baidu.com/s?id=1598880904532177567&wfr=spider&for=pc

  8. 多核
    Processor type and features  --->
    [*] Symmetric multi-processing support
  9. usb 和 HID 支持
    Device Drivers --->
    HID support  --->
    -*- HID bus support
    <*>   Generic HID driver
    [*]   Battery level reporting for HID devices
      USB HID support  --->
        <*> USB HID transport layer
    [*] USB support  --->
    <*>     xHCI HCD (USB 3.0) support
    <*>     EHCI HCD (USB 2.0) support
    <*>     OHCI HCD (USB 1.1) support
  10. 32位程序支持
    Binary Emulations
    [*] IA32 EMulation
  11. gpt 支持
    -*- Enable the block layer --->
    Partition Types --->
      [*] Advanced partition selection
      [*] EFI GUID Partition support
  12. uefi 支持
    Processor type and features  --->
    [*] EFI runtime service support 
    [*]   EFI stub support
    [*]     EFI mixed-mode support
    Firmware Drivers  --->
    EFI (Extensible Firmware Interface) Support  --->
        <*> EFI Variable Support via sysfs
  13. 配置 ntfs 相关,具体见下面 ‘双启动’ 章节。
  14. 编译内核和模块并安装到 /boot 下面
    make && make modules_install
    make install
  15. find /lib/modules/<kernel version>/ -type f -iname '*.o' -or -iname '*.ko' | less 查看编译后可用的模块,需要用到那个模块就写入到 /etc/modules-load.d/network.conf 这个文件里面,一个模块一行。
  16. emerge --ask sys-kernel/linux-firmware 安装固件。 提示许可证有问题。
    mkdir /etc/portage/package.license
    vim /etc/portage/package.license/linux-firmware
    >=sys-kernel/linux-firmware-20210511 linux-fw-redistributable no-source-code

    重新安装就可以了。

  17. emerge --ask sys-kernel/genkernel 安装 genkernel, genkernel --install --kernel-config=/usr/src/linux/.config initramfs 生成相应的 initramfs, 可以在 /boot 目录下看到生成的 initramfs. 注意,如果内核更新了,这个 initramfs 也要重新生成。

配置系统

  1. blkid 查看所有硬盘分区的 uuid, label 等。
  2. 修改 fstab
    vim /etc/fstab
    /dev/nvme0n1p1   /boot        vfat    defaults,noatime     0 2
    /dev/nvme0n1p2   none         swap    sw                   0 0
    /dev/nvme0n1p3   /            ext4    noatime              0 1

    注意: ssd 可以启用 discard 这个选项,从而使得 trim 可以执行,但是据说会影响性能。建议是不要添加这个选项,使用周期任务,执行这个 trim 操作。 参考: https://linux.cn/article-11959-1.html

  3. 设置主机名
    vim /etc/conf.d/hostname
    hostname="tux"
  4. dns 和 nis 可以不用设置,为了去除 dns 没有设置时的开机警告信息,把 /etc/issue 文件中的 .\O 去掉。
  5. emerge --ask --noreplace net-misc/netifrc 把 netifrc 这个软件添加到 world 列表中。 world 列表在 /var/lib/portage/world中,依赖的软件包在 /var/lib/portage/world_sets 中。 参考: http://www.jinbuguo.com/pkgmanager/gentoo/emerge.html
  6. 配置为 dhcp
    vim /etc/conf.d/net
    config_eno1="dhcp"

    /usr/share/doc/netifrc-*/net.example.bz2 这个里面有关于网络配置更加详细的信息。

  7. 配置网络为开机启动
    cd /etc/init.d
    ln -s net.lo net.eno1
    rc-update add net.eno1 default
  8. 修改 hosts
    vim /etc/hosts
    127.0.0.1    tux localhost
  9. passwd 设置 root 密码
  10. 使能 rc_logger
    vim /etc/rc.conf
    rc_logger="YES"
  11. /etc/conf.d/hwclock 这个文件中的 clock 设置为 UTC 表示使用 utc 时钟,设置为 local 表示使用本地时钟。如果和 win 双启动,可以设置为 local,也可以设置为 utc,但是 utc 的话,需要在 win 中新建注册表选项,指明是 utc 时钟。

安装系统工具

  1. 安装 log 工具
    emerge --ask app-admin/sysklogd
    rc-update add sysklogd default
  2. 安装守护进程
    emerge --ask sys-process/cronie
    rc-update add cronie default
  3. 安装文件索引工具
    emerge --ask sys-apps/mlocate
  4. 开机启动 ssh 服务
    rc-update add sshd default
  5. emerge -a sys-fs/dosfstools 安装 win 文件系统。
  6. emerge --ask net-misc/dhcpcd 安装 dhcp 客户端 参考: https://wiki.gentoo.org/wiki/Dhcpcd/zh-cn
    https://wiki.gentoo.org/wiki/Network_management_using_DHCPCD
  7. emerge --ask net-wireless/iw net-wireless/wpa_supplicant 安装无线工具。
  8. 安装 ntfs 相关软件,具体见下面 ‘双启动’ 章节。

配置 boot

  1. 安装 grub2
    echo 'GRUB_PLATFORMS="efi-64"' >> /etc/portage/make.conf
    emerge --ask sys-boot/grub:2
  2. grub-install --target=x86_64-efi --efi-directory=/boot grub2 生成 boot 文件
  3. grub-mkconfig -o /boot/grub/grub.cfg 生成 grub 配置文件
  4. 退出 chroot 并重启
    exit
    cd
    umount -l /mnt/gentoo/dev{/shm,/pts,}
    umount -R /mnt/gentoo
    reboot

安装完成后配置

  1. 重启后,发现字体很小

    rc-update add consolefont boot
    vim /etc/conf.d/consolefont
    consolefont="sun12x22"
    reboot

    console font 字体在 /usr/share/consolefonts 下面,但是不是所有字体都可以使用。如果想要修改后的字体能够显示,还要把 consolefont 加入 boot 启动等级。也有说法是,这个字体只支持内核中使能的字体。还有说法是,这个字体是 framebuffer 使用的字体,所以只支持几种。 Select the initial font to use. The value ‘name’ can be any of the compiled-in fonts: 10x18, 6x10, 6x8, 7x14, Acorn8x8, MINI4x6, PEARL8x8, ProFont6x11, SUN12x22, SUN8x16, TER16x32, VGA8x16, VGA8x8. 参考: https://forums.gentoo.org/viewtopic-t-524264-start-0.html
    https://www.zhihu.com/question/20558559
    https://www.kernel.org/doc/html/latest/fb/fbcon.html
    https://forums.gentoo.org/viewtopic-t-1129080-highlight-font+size.html
    https://forums.gentoo.org/viewtopic-t-1119313-highlight-font+size.html

  2. 准备双启动 win echo ">=sys-boot/grub-2.06_rc1 mount" > /etc/portage/package.use/grub 添加 USE。 emerge -a os-prober 安装 grub2 的附属软件 os-prober。
    vim /etc/default/grub
    GRUB_DISABLE_OS_PROBER=false

    grub-mkconfig -o /boot/grub/grub.cfg 生成新的配置。但是貌似 os-prober 并没有检测到 win. 经过网上搜索和尝试,确定问题出在没有安装 ntfs 的文件系统软件上。 旧版的安装说明上面是有关于 ntfs 的,新版的教程上面没有,所以遗漏了这一项。 首先修改内核

    File systems  --->
    DOS/FAT/NT Filesystems  --->
        <*> NTFS file system support
        <*>   NTFS write support
    <*> FUSE (Filesystem in Userspace) support

    然后重新编译内核并安装,生成 initramfs

    make && make modules_install
    make install
    genkernel --install --kernel-config=/usr/src/linux/.config initramfs

    然后安装 ntfs 软件

    emerge --ask sys-fs/ntfs3g

    然后再次运行 os-prober 就可以看到发现 win 系统在另外一个 ssd 了。 运行grub-mkconfig -o /boot/grub/grub.cfg 重新生成 grub 配置文件,新的 grub.cfg 里面就有了 win 相关项了。 然后重启系统,grub 界面上有 win 选项,点击,登录一切正常。这次双启动就完成了。 参考: https://wiki.gentoo.org/wiki/GRUB2
    https://forums.gentoo.org/viewtopic-t-1135596-highlight-osprober.html
    https://forums.gentoo.org/viewtopic-t-1133346-highlight-osprober.html
    https://wiki.gentoo.org/wiki/UEFI_Dual_boot_with_Windows_7/8
    https://wiki.gentoo.org/wiki/GRUB2/Chainloading
    https://wiki.gentoo.org/wiki/NTFS

结束安装

  1. 创建一个普通用户并设置密码。
    useradd -m -G users,wheel,audio -s /bin/bash larry
    passwd larry

    如果需要提权,可以使用 su - 来提升为 root,也可以安装 sudo。 sudo 对于权限管理更加合适。 参考: https://wiki.gentoo.org/wiki/Sudo

  2. rm /stage3-*.tar.* 删除 stage3 文件。

gentoo 上工作


portage 介绍

portage 仓库

  1. portage 的 ebuilds 都在 /var/db/repos/gentoo 里面
  2. emerge --sync 是增量更新。 emerge-webrsync 下载整个包,但是容易通过防火墙,并且只下载gentoo 发行的,不能下第三方的。

软件维护

  1. emerge --search pdf 搜索软件名称有 pdf 的,emerge --searchdesc pdf 搜索软件描述有 pdf 的。
  2. emerge --ask app-office/gnumeric 安装软件,emerge --pretend gnumeric 打印本次需要安装的软件,emerge --fetchonly gnumeric 只下载源码不安装,源码在 /var/cache/distfiles/ 下面。
  3. emerge -vp category/package 用来查看软件的 USE。
  4. 软件如果开启了 doc 这个 USE,那么会安装自己的文档,文档在 /usr/share/doc/ 下面。
  5. equery files --filter=doc alsa-lib 可以用来查看软件的文档位置,equery 属于 app-portage/gentoolkit 这个工具包附带的。
  6. 安全删除软件,使用 emerge --deselect gnumeric,如果要同时删除依赖的软件包,使用 --depclean
    • 先把 ebuilds 更新到最新,然后可以通过 emerge --update --ask @world 来更新整个系统中记录在/var/lib/portage/world 里面的软件;
    • 如果把相应的依赖也更新,那么需要使用 emerge --update --deep @world;
    • 但是系统中还有些软件,属于编译和构建时候用到的,这些软件如果也需要更新,那么使用命令 emerge --update --deep --with-bdeps=y @world, 建议每过一段时间,偶尔运行一下即可;
    • 如果 USE 被改变了,那么需要运行 emerge --update --deep --with-bdeps=y --newuse @world 来对相应的 USE 改变的进行重新编译安装。或者 emerge -auDN --with-bdeps=y @world
  7. 有些软件集合不太容易删除干净,需要先更新系统,然后移除所有孤立的不再依赖的包,使用下面的命令即可:
    emerge --update --deep --newuse @world
    emerge --ask --depclean

    最新的 portage 已经不需要在 depclean 之后,手动的运行命令,重新链接库文件了。

    许可证

  8. 许可证在 /etc/portage/make.conf 文件中,使用 ACCEPT_LICENSE="-* @FREE" 来配置,默认是只安装自由软件。
  9. 单个软件的许可证可以在 /etc/portage/package.license 文件夹下面进行更改,比如说 chrome www-client/google-chrome google-chrome
  10. 许可证在 /var/db/repos/gentoo/licenses/ 下面,许可证组在 /var/db/repos/gentoo/profiles/license_groups 里面。
  11. ACCEPT_LICENSE="* -@EULA" 表示允许所有不需要用户阅读确认的许可证。

    portage 抱怨

  12. 有些软件,比如日志软件,多个日志软件,对应一个虚拟日志软件。如果安装软件时需要依赖日志软件,那么安装虚拟日志中的第一个软件,除非已经安装了日志软件。
  13. block 的包,有些可能是编译时 block,属于 DEPEND ,有些可能是运行时 block,属于 RDEPEND
  14. mask 的包也有很多种可能。
Reason for mask Description
~arch keyword The application is not tested sufficiently to be put in the stable branch. Wait a few days or weeks and try again.
-arch keyword or -* keyword The application does not work on your architecture. If you believe the package does work file a bug at our Bugzilla website.
missing keyword The application has not been tested on your architecture yet. Ask the architecture porting team to test the package or test it for them and report the findings on our Bugzilla website.
package.mask The package has been found corrupt, unstable or worse and has been deliberately marked as do-not-use.
profile The package has been found not suitable for the current profile. The application might break the system if it is installed or is just not compatible with the profile currently in use.
license The package's license is not compatible with the ACCEPT_LICENSE value. Permit its license or the right license group by setting it in /etc/portage/make.conf or in /etc/portage/package.license
  1. USE 需要修改的,放入 /etc/portage/package.use 文件夹下面。

USE 标识

  1. 当前的 profile 指向可以看 /etc/portage/make.profile 这个软链接的指向。当前的基础 profile 在 /var/db/repos/gentoo/profiles/base 里面。
  2. emerge --info | grep ^USE 可以打印当前的 USE。
  3. 修改系统 USE,只要修改 /etc/portage/make.conf 即可,如:USE="-kde -qt4 -qt5 ldap"
  4. /etc/portage/package.use 这个文件夹下面的单个文件可以作为独立的 USE 配置,如:
    echo "media-video/vlc bluray" >> /etc/portage/package.use/vlc
    dev-lang/php -bzip2
  5. USE="-pulseaudio" emerge www-client/seamonkey 临时 USE 标识用法
  6. 优先级从高到底:临时 > package.use > make.conf > profile
  7. 修改了 USE 后,升级系统的操作:
    emerge --update --deep --newuse @world
    emerge -p --depclean
    emerge --depclean
    emerge @preserved-rebuild
  8. 查看软件的 USE:emerge --pretend --verbose www-client/seamonkey
  9. 查看软件详细的USE以及对应的说明: equery --nocolor uses =gnumeric-1.12.31。注意:这个 equery 需要先安装软件 emerge --ask app-portage/gentoolkit
  10. ebuild 处理 USE 主要是针对 REQUIRED_USE, 具体用法如下:
Example Description
REQUIRED_USE="foo? ( bar )" If foo is set, bar must be set.
REQUIRED_USE="foo? ( !bar )" If foo is set, bar must not be set.
REQUIRED_USE="foo? ( || ( bar baz ) )" If foo is set, bar or baz must be set.
REQUIRED_USE="^^ ( foo bar baz )" Exactly one of foo bar or baz must be set.
REQUIRED_USE="|| ( foo bar baz )" At least one of foo bar or baz must be set.
REQUIRED_USE="?? ( foo bar baz )" No more than one of foo bar or baz may be set.

portage 特性

  1. /etc/portage/make.conf 中可以设置 FEATURES 这个参数来开启相应的特性,具体可以 man make.conf
  2. 查看默认的 featrues,可以emerge --info | grep ^FEATURES=
  3. 如果需要使用分布式编译,可以考虑 Distcc 参考: https://wiki.gentoo.org/wiki/Distcc
    https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Features
  4. 如果是从事软件开发,需要经常反复编译软件,可以考虑 ccache 参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Features
  5. 如果我希望我编译好的软件生成二进制包,可以使用 quickpkg 命令,或者 emerge 增加 --buildpkg--buildpkgonly 参数。如果希望所有的软件包都生成二进制包,那么需要在 FEATURES 上增加 buildpkg 这个特性。具体这个二进制包在什么位置,通过配置 make.conf 来决定 PORTAGE_BINHOST="ftp://buildhost/gentoo" 参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Features
    https://wiki.gentoo.org/wiki/Project:Catalyst/FAQ
  6. 如果要从二进制包重新安装软件 emerge --usepkg --getbinpkg gnumeric,更加详细的可以 man emerge
  7. USE 中带有 bindist 不可以使用他人编译好的包。如果要临时屏蔽带 bindist 的包,可以在 emerge 时,带有 --accept-restrict=-bindist 参数。
  8. 如果不希望 portage 只能 root 使用,那么需要设置 EATURES="userfetch",然后 chown --recursive --verbose portage:portage /var/db/repos/gentoo,这回带来一些安全性的提升。 9。 重新下载验证源码 emerge --ask --fetchonly --emptytree @world

系统启动脚本

  1. 系统启动时,bootloader 先启动,然后加载内核,内核启动准备好后,先检查 /etc/fstab,然后执行 /etc/init.d/ 中的启动脚本,最后到终端界面。
  2. /etc/init.d/ 中的脚本并不是随机执行,也不是全部执行,具体要看 /etc/runlevels/ 这个下面。
  3. 先执行 /etc/init.d/ 中软连接到 /etc/runlevels/boot/ 下面的,通常是按照字母顺序执行,除非有依赖关系。 4。/etc/runlevels/boot/执行完了之后,执行 /etc/runlevels/default/,通常情况下增加开机启动,都是增加到 default 里面,通过命令 rc-update add sshd default
  4. 具体的启动脚本控制,在 /etc/inittab 里面 参考:https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Initscripts
  5. 运行等级,一共7中,3种内部,4种用户定义。内部分别是:系统初始化,关机,重启。用户定义分别是:boot, default, 无网络,single,其中 boot 是通用的,后面三种只能选一种,default 是正常用的,无网络就是断网,single 好像是固定?
  6. rc-service postfix start 这样是启动服务,还可以停止和重启还有查看当前状态,分别是 stop, restart, status
  7. 停止服务,但是不停止依赖它的服务。 rc-service --nodeps postfix stop
  8. 如果状态显示在运行,实际已经停止,可以使用 rc-service postfix zap 把服务复位为停止。
  9. 查看当前服务的依赖。ineed 用于显示真正必须的依赖,iwantiuse 这两个用于显示可用的服务,但是不一定是必须的。 整个命令如:rc-service postfix ineed
  10. 查看那些服务依赖当前服务, 可以用needsme,usesme或者 wantsme。例如: rc-service postfix needsme
  11. rc-update 自动调用 depscan.sh 重建脚本依赖树。rc-update del postfix default 用于从 default 中删除服务,rc-update -v show 用来显示所有可用的启动服务和他们的等级。rc-update show列出所有已启用的服务和他们的等级。
  12. /etc/conf.d/ 下面的脚本用来分别配置各个服务的具体选项。例如: /etc/conf.d/apache2 里面配置为:APACHE2_OPTS="-D PHP5",类似于 make.conf 中的写法。
  13. 启动脚本的写法参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Initscripts
  14. 可以创建启动软等级,比如说 offline,具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Working/Initscripts

环境变量

  1. 重要的环境变量如下:
Variable Description
PATH This variable contains a colon-separated list of directories in which the system looks for executable files. If a name is entered of an executable (such as ls, rc-update, or emerge) but this executable is not located in a listed directory, then the system will not execute it (unless the full path is entered as the command, such as /bin/ls).
ROOTPATH This variable has the same function as PATH, but this one only lists the directories that should be checked when the root-user enters a command.
LDPATH This variable contains a colon-separated list of directories in which the dynamical linker searches through to find a library.
MANPATH This variable contains a colon-separated list of directories in which the man command searches for the man pages.
INFODIR This variable contains a colon-separated list of directories in which the info command searches for the info pages.
PAGER This variable contains the path to the program used to list the contents of files through (such as less or more).
EDITOR This variable contains the path to the program used to change the contents of files with (such as nano or vi).
KDEDIRS This variable contains a colon-separated list of directories which contain KDE-specific material.
CONFIG_PROTECT This variable contains a space-delimited list of directories which should be protected by Portage during updates.
CONFIG_PROTECT_MASK This variable contains a space-delimited list of directories which should not be protected by Portage during updates.
  1. /etc/env.d/ 下面的文件专门用来存放环境变量,每个软件有环境变量的设置就在这个目录下面新建一个文件,然后把它自己需要的写入进去,软件自带的环境变量由 portage 来维护,如果用户修改了,下次升级系统的时候也会被覆盖掉。如果用户需要设置相应的环境变量,可以单独建立 /etc/env.d/99local 并写入。比如 http_proxy="proxy.server.com:8080" 写入到 99local 里面。
  2. env-update 会把所有/etc/env.d/下面的环境变量综合起来,按照前面的数字顺序来。
  3. 只有ADA_INCLUDE_PATH, ADA_OBJECTS_PATH, CLASSPATH, KDEDIRS, PATH, LDPATH, MANPATH, INFODIR, INFOPATH, ROOTPATH, CONFIG_PROTECT, CONFIG_PROTECT_MASK, PRELINK_PATH, PRELINK_PATH_MASK, PKG_CONFIG_PATH, and PYTHONPATH 这些环境变量才会串联综合起来,其他的环境变量使用最后一个文件里面定义的。
  4. COLON_SEPARATEDSPACE_SEPARATED 中添加变量,就是增加串联列表。这两个变量也在 /etc/env.d/ 里面。
  5. env-update 这个命令先生成环境变量,再把他们放到 /etc/profile.env里面,这个文件会被/etc/profile 使用,而且会把 LDPATH 中的内容取出来,用来创建 /etc/ld.so.conf,然后运行 ldconfig 来重新创建 /etc/ld.so.cache用于动态链接。记住这条命令 env-update && source /etc/profile,这个命令只能作用于当前终端,其他已经打开的终端作用不到,必须运行source /etc/profile 才行; 如果是 X11,那么需要重启 X 才行,如果是已经登录了,那么需要重启 /etc/init.d/xdm
  6. 用户级别的环境变量,在~/.bashrc~/.bash_profile 里面,重新登录生效。
  7. 如果用户只是临时设置环境变量,可以在终端里面设置, 例如: export PATH="${PATH}:/home/my_user/tmp/usr/bin"

portage 文件与文件夹

  1. portage 的默认配置文件 /usr/share/portage/config/make.globals,里面有很详细的说明。
  2. 不同的 profile 查看/etc/portage/make.profile 指向的目录, portage 的配置选项来源于 make.defaults 以及 profile 继承的 make.defaults
  3. 如果要修改配置,不要动 /usr/share/portage/config/make.globalsmake.defaults,而是应该修改 /etc/portage/make.conf, make.conf 的优先级比那两个要高。
  4. /usr/share/portage/config/make.conf.example 这个只是示例文件,不起作用。
  5. /etc/portage/make.profile 只是一个软连接,指向 /var/db/repos/gentoo/profiles/
  6. 只建议修改 /etc/protage/里面的文件和目录:
目录 作用
package.mask 它列出了你永远不希望Portage安装的软件包。
package.unmask 它列出了本来Gentoo的开发者不建议安装的,但是你希望能安装的软件包。
package.accept_keywords 它列出了还未被确认适合你的系统或架构,但是你希望能安装的软件包。
package.use 它列出了你希望某些特定软件包使用的而不是整个系统使用的USE标记
  1. 更加详细信息: man portage man make.conf
  2. ebuild 默认仓库 /var/db/repos/gentoo/usr/share/portage/config/repos.conf 定义。如果想要修改这个设置,需要把这个 repos.conf 复制到 /etc/portage/repos.conf/gentoo.conf 并修改 location 这个值。当修改了位置之后,别忘了修改 /etc/portage/make.profile 这个软连接的指向。 并且这几个值也需要修改 PKGDIR, DISTDIR, and RPMDIR
  3. 如果使用预编译二进制包,会在 /var/cache/binpkgs 中查找,这个位置通过 PKGDIR 定义。
  4. 源码默认放在 /var/cache/distfiles, 通过 DISTDIR 定义。
  5. portage 安装了哪些包,在 /var/db/pkg 里面有记录。
  6. portage 缓存在 /var/cache/edb
  7. portage 临时目录 /var/tmp/,通过 PORTAGE_TMPDIR 定义。
  8. portage 为每个软件在 /var/tmp/portage/ 中创建编译目录,通过 PORTAGE_TMPDIR 定义。
  9. 默认 portage 把所有软件安装到当前文件系统,但是如果需要创建一个新的镜像的时候,可以修改 ROOT 来改变目录。
  10. 只有设定了 PORT_LOGDIR,ebuild 每次编译的 log 才会记录下来。定义了 PORT_LOGDIR 并使用 elog.
  11. PORTAGE_ELOG_CLASSES 设置哪个等级的信息被记录, 如果需要组合,那用空格分开:
等级 详细
info 记录下ebuild打印的 "einfo" 信息
warn 记录下ebuild打印的"ewarn" 信息
error 记录下ebuild打印的 "eerror"信息
log 记录下ebuild打印的 "elog"信息
qa 记录下ebuild打印的 "QA Notice"信息
  1. PORTAGE_ELOG_SYSTEM 设置用来处理日记信息的模块,需要组合,使用空格分开:
模块 详细
save 表示将每一个软件包的日志保存在PORT_LOGDIR/elog中,或者是在PORT_LOGDIR/没有配置的情况下保存在/var/log/portage/elog 目录下面。
custom 将所有的信息传递给用户在$PORTAGE_ELOG_COMMAND中定义的命令,这将在随后讨论。
syslog 把所有的信息发送给已安装的系统日志软件。
mail 把所有的信息传递给用户在$PORTAGE_ELOG_MAILURI中定义的邮件服务器;这将在随后讨论。这一elog的邮件特性需要>=portage-2.1.1。
save_summary 和save类似,不过它把所有的信息保存在PORT_LOGDIR/elog/summary.log里,或者/var/log/portage/elog/summary.log里,如果PORT_LOGDIR没有定义的话。
mail_summary 和mail类似,不过它会在emerge结束时把所有的信息在一个邮件里发送出去。
  1. PORTAGE_ELOG_COMMAND 只有在 custom 模块被激活时,起作用,用于指定一个命令来处理日志,${PACKAGE}是软件包名字和版本,${LOGFILE}是日志的绝对路径。可能的用法: PORTAGE_ELOG_COMMAND="/path/to/logger -p '\${PACKAGE}' -f '\${LOGFILE}'"
  2. PORTAGE_ELOG_MAILURI 用于设置 mail 模块的地址、用户、密码、邮件服务器、端口,默认是 "root@localhost localhost", smtp 的例子: PORTAGE_ELOG_MAILURI="user@some.domain username:password@smtp.some.domain:995"
  3. PORTAGE_ELOG_MAILFROM 配置 mail 中 from 的地址,默认是 portage.
  4. PORTAGE_ELOG_MAILSUBJECT 配置 mail 的主题行,可以使用两个变量,${PACKAGE} 是软件和版本,${HOST} 是主机。例如: PORTAGE_ELOG_MAILSUBJECT="package \${PACKAGE} was merged on \${HOST} with some messages"
  5. 如果使用了 enotice,那么会和 elog 冲突,需要卸载 enotice.

portage 配置

  1. portage 通过 /etc/portage/make.conf 或者 /etc/portage/ 的子目录进行配置。详细信息查看 man make.confman portage
  2. 编译选项
选项 说明
CFLAGS 和 CXXFLAGS 为C和C++编译定义所需的编译器标志。
CHOST 为应用程序的编译脚本定义用于build的主机信息
MAKEOPTS 传递给make命令,通常用于定义编译期间使用的指令。有关make选项的更多信息可以在make手册页中找到。
  1. 当 merge 一个软件的新版本时,会删除就版本,但是会提供一个延时,这个延时时间由 CLEAN_DELAY 来定义。
  2. EMERGE_DEFAULT_OPTS 告诉 emerge 每次运行使用哪些选项,可用的选项是 --ask, --verbose, --tree, 等等。
  3. 软件的配置文件收到保护,受保护的目录由CONFIG_PROTECT来定义,目录列表用空格分割,受保护目录被 portage 写入新配置文件时,旧配置文件会被重新命名,并提醒用户。要了解当前的 protect 的设置,emerge --info | grep ^FEATURES=
  4. 要取消受保护目录下面的子目录,使用 CONFIG_PROTECT_MASK
  5. portage 下载,GENTOO_MIRRORS 定义源码服务器,PORTAGE_BINHOST 定义二进制服务器。
  6. sync-type 定义同步协议,默认是rsyncsync-uri 同步服务器
  7. GENTOO_MIRRORS, sync-type, sync-uri 这三个都可以通过 mirrorselect 来配置,当然需要先 emerge 这个软件才行。具体的可以 mirrorselect --help
  8. 如果系统需要代理服务器,那么 http_proxy, ftp_proxy, RSYNC_PROXY 都需要设定。
  9. portage 下载源码是通过 wget,可以通过 FETCHCOMMAND 来配置。
  10. portage 可以恢复下载,默认也是用 wget,可以通过 RESUMECOMMAND 来配置
  11. 确保 FETCHCOMMAND RESUMECOMMAND 保存源码在正确的位置,${URI}${DISTDIR} 用来设置源码服务器和本地源码目录。还可以选择特定的传输协议,比如 FETCHCOMMAND_HTTP, FETCHCOMMAND_FTP, RESUMECOMMAND_HTTP, RESUMECOMMAND_FTP 等等。
  12. 同步设置中 PORTAGE_RSYNC_OPTS 这个不要随便修改。PORTAGE_RSYNC_EXTRA_OPTS 用来设置一些额外的,PORTAGE_RSYNC_RETRIES 用来设置退出前尝试连接到 SYNC 指定镜像的次数,默认是 3. 更多参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Portage/Variables
  13. ACCEPT_KEYWORDS 可以用来切换分支,默认是稳定分支
  14. PORTAGE_NICENESS 可以设置 portage 的 nice 值。
  15. NOCOLOR 用来设置输出颜色,默认是 false,也就是彩色。

混合使用软件分支

  1. ACCEPT_KEYWORDS 用来选择分支,默认是 amd64,如果要使用测试分支,在 make.conf 中设置 ACCEPT_KEYWORDS="~amd64"
  2. 特定软件使用测试版本,可以在 /etc/portage/package.accept_keywords 中设置,比如 app-office/gnumeric, 如果是特定版本,可以使用=>, >=, <, <=,如: =app-office/gnumeric-1.2.13
  3. 有些包被 gentoo 屏蔽了,如果你要使用,在 /etc/portage/package.unmask 中设置 =net-mail/hotwayd-0.8
  4. 如果想要屏蔽某些软件的时候,只需要在 /etc/portage/package.mask 中设置就行了。经常用来屏蔽某些高版本的软件。比如: >sys-kernel/gentoo-sources-4.9.16

portage 额外的工具

  1. dispatch-conf 用于配置文件的版本控制,受保护的配置文件夹中的新文件会被改名为 ._cfg0000_<name>dispatch-conf 会自动合并只有注释变更和空白字符变更的更新,进入功能时,按 u 使用新配置,按z 使用旧配置,按n 跳到下一个配置,按q 退出,按 m 进行手动合并。具体查阅 man dispatch-conf
  2. dispatch-conf 升级配置文件后,旧的配置文件会被保存起来,保存路径由 /etc/dispatch-conf.confarchive-dir 设置,默认是 /etc/config-archive/
  3. etc-update 也可以用来配置文件变更,虽然可以交互,但是旧配置文件不会被自动保存,风险高,不合适。
  4. quickpkg 可以对已经安装的软件进行打包,例如: quickpkg curl,这些包会保存在 $PKGDIR 设定的目录,默认是 /var/cache/binpkgs/,保存在 $PKGDIR/CATEGORY 中。

定制 portage

  1. 排除包,排除可以写在 make.conf 中的 PORTAGE_RSYNC_EXTRA_OPTS 里面,例如: PORTAGE_RSYNC_EXTRA_OPTS="--exclude-from=/etc/portage/rsync_excludes" ,然后在 /etc/portage/rsync_excludes 中写具体排除的包 games-*/*,这样所有的 游戏包就都被排除了。但是这样时间长了容易出问题,可能有些新的包会依赖被排除的包。为了这种方法起作用,必须禁用验证,需要设置 UES 中的 rsync-verify,或者在 repos.conf 中设置 sync-rsync-verify-metamanifest=no
  2. 可以自定义一个 ebuild 仓库,比如说 /var/db/repos/localrepo,这个自定义的仓库结构要类似于 portage,
    mkdir -p /var/db/repos/localrepo/{metadata,profiles}
    chown -R portage:portage /var/db/repos/localrepo

    然后设置仓库的名字,比如说 localrepo, echo 'localrepo' > /var/db/repos/localrepo/profiles/repo_name 然后在/var/db/repos/localrepo/metadata/layout.conf 中说明,主分支还是 gentoo,自定义分支不自动更新。

    masters = gentoo
    auto-sync = false

    最后在 /etc/portage/repos.conf 中使能自定义仓库,也就是新建/etc/portage/repos.conf/localrepo.conf,然后输入:

    [localrepo]
    location = /var/db/repos/localrepo
  3. 使用overlay,可以通过两种,eselect-repository 或者 layman, 具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Portage/CustomTree
    https://wiki.gentoo.org/wiki/Eselect/Repository
    https://wiki.gentoo.org/wiki/Project:Overlays/Overlays_guide
  4. 手动维护的包,不希望 portage 来自动执行,比如说内核源码和 nvidia 的驱动代码等,只需要在 /etc/portage/profile/package.provided 中写入 sys-kernel/gentoo-sources-4.9.16,注意这里带版本但是没有带 =.

portage 高级特性

  1. 通常,软件编译使用的是 make.conf 中定义好的,如果某些软件需要特殊指定,那么/etc/portage/env `` /etc/portage/package.env 可以满足要求。比如说给某个软件增加 debug.
    vim /etc/portage/env/debug-cflags   // Specific variables for debugging
    CFLAGS="-O2 -ggdb -pipe"
    FEATURES="${FEATURES} nostrip"
    /etc/portage/package.env  // Using debug-cflags for the mplayer package
    media-video/mplayer debug-cflags
  2. 还可以在 emerge 的过程中,增加 hook 挂接到某些过程,或者把某些包添加到系统包里面,或者使用专门的补丁文件夹,等等,具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Portage/Advanced

网络入门

  1. 新网卡
    cd /etc/init.d
    ln -s net.lo net.eth0

    配置网卡

vim /etc/conf.d/net
# For DHCP
config_eth0="dhcp"

# For static IP using CIDR notation
config_eth0="192.168.0.7/24"
routes_eth0="default via 192.168.0.1"
dns_servers_eth0="192.168.0.1 8.8.8.8"

# For static IP using netmask notation
config_eth0="192.168.0.7 netmask 255.255.255.0"
routes_eth0="default via 192.168.0.1"
dns_servers_eth0="192.168.0.1 8.8.8.8"
  1. /etc/init.d/net.eth0 start 启动网卡,/etc/init.d/net.eth0 stop 停止网卡。
  2. 启动网卡服务
    rc-update add net.eth0 default
    rc

    第二个 rc 的意思是 启动当前运行等级中所有还没有运行的服务。

网卡高级设置

  1. 网卡设置中关键特性
描述
null Do nothing.
noop If the interface is up and there is an address then abort configuration successfully.
An IPv4 or IPv6 address Add the address to the interface.
dhcp, adsl, or apipa (or a custom value from a 3rd party module) Run the module which provides the command. For example dhcp will run a module that provides DHCP which can be served by dhcpcd, dhclient, or pump.
  1. /etc/conf.d/net 示例
# Adding three IPv4 addresses
config_eth0="192.168.0.2/24
192.168.0.3/24
192.168.0.4/24"

# Adding an IPv4 address and two IPv6 addresses
config_eth0="192.168.0.2/24
4321:0:1:2:3:4:567:89ab
4321:0:1:2:3:4:567:89ac"

# Keep our kernel assigned address, unless the interface goes
# down so assign another via DHCP. If DHCP fails then add a
# static address determined by APIPA
config_eth0="noop
dhcp"
fallback_eth0="null
apipa"
  1. /etc/init.d/ 中的脚本可以依赖于特性网卡,具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Networking/Advanced
  2. 网络接口的名称可以是任意字符,不是英文字母的会用 _ 来代替,需要转义的用 \
  3. 网卡名称也不是随意的,内核先收集板载注册名称,可以在 ID_NET_NAME_ONBOARD 中查到,然后看网卡插槽,可以在 ID_NET_NAME_SLOT 中查,然后看网卡设备路径,可以在 ID_NET_NAME_PATH 中查,然后看 MAC 地址,可以在 ID_NET_NAME_MAC 中查。 比如说:板载经常是 eno1,设备路径经常是 enp3s0,如果一个都没有命中,那么就是内核默认的 eth0 之类的。 可以使用 udevadm 命令来查看

    udevadm test-builtin net_id /sys/class/net/enp3s0 2>/dev/null
    ID_NET_NAME_MAC=enxc80aa9429d76
    ID_OUI_FROM_DATABASE=Quanta Computer Inc.
    ID_NET_NAME_PATH=enp3s0
  4. 如果想要用旧的内核名称,可以在加载引导程序中设置 net.ifnames=0
  5. 如果想要把网卡名称修改为自己想要的名称,那么如下修改
    udevadm test-builtin net_id /sys/class/net/eth0 2>/dev/null
    ID_NET_NAME_MAC=enxc80aa9429d76
    ID_OUI_FROM_DATABASE=Quanta Computer Inc.
    vim /etc/udev/rules.d/70-net-name-use-custom.rules
    # First one uses MAC information, and 70- number to be before other net rules
    SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="c8:0a:a9:42:9d:76", NAME="lan0"
    vim /etc/udev/rules.d/76-net-name-use-custom.rules
    # Second one uses ID_NET_NAME_PATH information, and 76- number to be between
    # 75-net-*.rules and 80-net-*.rules
    SUBSYSTEM=="net", ACTION=="add", ENV{ID_NET_NAME_PATH}=="enp3s0", NAME="wifi0"

模块化网络

  1. 可以制定网络模块需要的包。比如 /etc/conf.d/net中,系统安装了 ifconfig 和 iproute2,但是喜欢 ifconfig,所以指定 ifconfig. 毕竟 ifconfig 和 iproute2 对于正常的脚本设定都能够生效。
# Prefer ifconfig over iproute2
modules="ifconfig"

# You can also specify other modules for an interface
# In this case we prefer pump over dhcpcd
modules_eth0="pump"

# You can also specify which modules not to use - for example you may be
# using a supplicant or linux-wlan-ng to control wireless configuration but
# you still want to configure network settings per ESSID associated with.
modules="!iwconfig"
  1. dhcp 默认使用 dhcpd,如果要设置特定参数,使用 module_eth0="...",如果网卡要转入 dhcp 模式,使用 dhcpcd_eth0
描述
release Releases the IP address for re-use.
nodns Don't overwrite /etc/resolv.conf
nontp Don't overwrite /etc/ntp.conf
nonis Don't overwrite /etc/yp.conf

/etc/conf.d/net 中:

# Only needed if you have more than one DHCP module installed
modules="dhcpcd"
config_eth0="dhcp"
dhcpcd_eth0="-t 10" # Timeout after 10 seconds
dhcp_eth0="release nodns nontp nonis" # Only get an address
  1. 网卡绑定可以多块网卡工作于一个网络,用于提高带宽等等,需要交换机支持。具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Networking/Modular
  2. 还可以设置桥接,具体参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Networking/Modular
  3. 可以在 /etc/conf.d/net 中修改 mac 地址:
# To set the MAC address of the interface
mac_eth0="00:11:22:33:44:55"

# To randomize the last 3 bytes only
mac_eth0="random-ending"

# To randomize between the same physical type of connection (e.g. fibre,
# copper, wireless) , all vendors
mac_eth0="random-samekind"

# To randomize between any physical type of connection (e.g. fibre, copper,
# wireless) , all vendors
mac_eth0="random-anykind"

# Full randomization - WARNING: some MAC addresses generated by this may
# NOT act as expected
mac_eth0="random-full"
  1. 隧道,可以在/etc/conf.d/net 中设置
# For GRE tunnels
iptunnel_vpn0="mode gre remote 207.170.82.1 key 0xffffffff ttl 255"

# For IPIP tunnels
iptunnel_vpn0="mode ipip remote 207.170.82.2 ttl 255"

# To configure the interface
config_vpn0="192.168.0.2 peer 192.168.1.1"
  1. 想要使用 vlan,那么不能用 ifconfig,只能用 iproute2,需要在 /etc/conf.d/net 中修改。 首先是号码 vlans_eth0="1 2" 然后是给网卡配置 vlan:
config_eth0_1="172.16.3.1 netmask 255.255.254.0"
routes_eth0_1="default via 172.16.3.254"

config_eth0_2="172.16.2.1 netmask 255.255.254.0"
routes_eth0_2="default via 172.16.2.254"

最后是特定配置:

vlan1_name="vlan1"
vlan1_ingress="2:6 3:5"
eth0_vlan1_egress="1:2"

log 配置

  1. /etc/portage/make.conf 中配置下面选项
PORTAGE_ELOG_CLASSES="log warn error qa"
PORTAGE_ELOG_SYSTEM="save"
PORT_LOGDIR="/var/log/portage"

参考: https://wiki.gentoo.org/wiki/Portage_log/en

  1. 安装 elogv 用来查看 log, emerge --ask app-portage/elogv,参考: https://wiki.gentoo.org/wiki/Elogv
  2. logrotate, 先安装 emerge --ask app-admin/logrotate,然后修改 /etc/logrotate.conf
    # rotate log files weekly
    #weekly
    daily

    然后新建 /etc/logrotate.d/portage

    /var/log/portage/*.log {
    su portage portage
    createolddir 755 portage portage
    rotate 1
    weekly
    nocreate
    missingok
    ifempty
    olddir /var/log/portage/old
    compress
    }

    参考: https://wiki.gentoo.org/wiki/Logrotate

无线

  1. 修改内核
[*] Networking support  --->
    [*] Wireless  --->
        <M>   cfg80211 - wireless configuration API
        [ ]     nl80211 testmode command
        [ ]     enable developer warnings
        [ ]     cfg80211 certification onus
        [*]     enable powersave by default
        [ ]     cfg80211 DebugFS entries
        [ ]     support CRDA
        [ ]     cfg80211 wireless extensions compatibility
        <M>   Generic IEEE 802.11 Networking Stack (mac80211)
        [ ]   Minstrel
              *** Some wireless drivers require a rate control algorithm ***
        [ ]   Enable mac80211 mesh networking (pre-802.11s) support
        -*-   Enable LED triggers
        [ ]   Export mac80211 internals in DebugFS
        [ ]   Trace all mac80211 debug messages
        [ ]   Select mac80211 debugging features  ----

Device Drivers  --->

        [*] Network device support  --->

        --- Network device support
        [*]   Wireless LAN  --->

            --- Wireless LAN
            [ ]   mac80211-based legacy WDS support
            [ ]   ADMtek devices
            [ ]   Atheros/Qualcomm devices
            [ ]   Atmel devices
            [ ]   Broadcom devices
            [ ]   Cisco devices
            [*]   Intel devices
            < >     Intel PRO/Wireless 2100 Network Connection
            < >     Intel PRO/Wireless 2200BG and 2915ABG Network Connection
            < >     Intel Wireless WiFi 4965AGN (iwl4965)
            < >     Intel PRO/Wireless 3945ABG/BG Network Connection (iwl3945)
            <M>     Intel Wireless WiFi Next Gen AGN - Wireless-N/Advanced-N/Ultimate-N (iwlwifi)
            <M>       Intel Wireless WiFi DVM Firmware support
            <M>       Intel Wireless WiFi MVM Firmware support
                      Debugging Options  --->
            [ ]   Intersil devices
            [ ]   Marvell devices
            [ ]   MediaTek devices
            [ ]   Ralink devices
            [ ]   Realtek devices
            [ ]   Redpine Signals Inc devices
            [ ]   STMicroelectronics devices
            [ ]   Texas Instrument devices
            [ ]   ZyDAS devices
            [ ]   Quantenna wireless cards support
            < >   Simulated radio testing tool for mac80211
            < >   Wireless RNDIS USB support

wifi 相关的编译为模块,便于 ax200 的固件加载。确保 linux-firmware 安装好了。 ax200 依赖的是 iwlwifi-cc-46.3cfab8da.0.tgz,可以在 /lib/firmware 下面查看。参考: https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi#firmware

  1. make && make modules_install make install,然后 find /lib/modules/<kernel version>/ -type f -iname '*.o' -or -iname '*.ko' | less 查看可用的模块
  2. 把 wifi 相关的模块写入 /etc/modules-load.d/network.conf, 让内核自动加载
    mac80211
    cfg80211
    libarc4
    iwlmvm
    iwlwifi
    iwldwm

    参考: https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Kernel#Configuring_the_modules

  3. reboot 然后检查是否识别到无线网卡, tree /sys/class/net 或者 ifconfig -a 能够看到加载了出现了 wlp4s0. 参考: https://wiki.gentoo.org/wiki/Iwlwifi

  4. wpa_supplicant 用于 wpa 网络,net-wireless/iw 用于非 wpa 网络。先安装这两个软件。
  5. 修改 /etc/conf.d/net 增加 modules="wpa_supplicant"
  6. 复制 /usr/share/doc/wpa_supplicant-<version>/wpa_supplicant.conf.gz/etc/wpa_supplicant,并使用 bzip2 -d wpa_supplicant.conf.gz 解压配置文件。 参考: https://blog.csdn.net/changkaibo/article/details/80091816
  7. ifconfig wlp4s0 up 启动无线网卡
  8. iw dev wlp4s0 scan | grep wifi_essid 可以扫描周围的 wifi. 并打印详细信息。如果打印简要信息,可以使用命令 wpa_cli scan_result, 注意 wpa_cli scan 是显示网卡,而不是网络。 参考: https://www.cnblogs.com/-glb/p/11601326.html
    https://forums.gentoo.org/viewtopic-t-1046238-start-0.html
  9. iw dev wlp4s0 scan | grep -A 60 wifi_essid, 扫描指定 ssid,并打印匹配的后60行,便于设置配置文件。参考:https://blog.csdn.net/zq_dser/article/details/108612009
  10. 按照扫描出来的信息,修改 wpa_supplicant.conf
  11. cd /etc/init.d ln -s net.lo net.wlp4s0 /etc/init.d/net.wlp4s0 restart, 根据提示,把 conf 中的一些参数注释掉。
  12. ifconfig 之后发现 wifi 获取的 ip 地址不对。
  13. 改动内核
    Device Drivers  --->
    [*] PCI support  --->
        [*] Network device support  --->
        [*]   Message Signaled Interrupts (MSI and MSI-X)

    还有使能 CONFIG_IWLWIFI_DEBUG 可以获取更多的信息。 新建 /etc/modprobe.d/iwlwifi.conf 输入 options iwlwifi 11n_disable=1 swcrypto=1。 然后重新编译内核, 但是通过 dmesg 可以查看错误信息,/var/log/messages 里面的信息更新详细。 参考: https://wireless.wiki.kernel.org/en/users/drivers/iwlwifi/debugging#tracing
    https://bugzilla.kernel.org/show_bug.cgi?id=195957

标签: Gentoo

添加新评论