环境准备
启动镜像
可以在Gentoo官网下载Minimal Installation CD
https://www.gentoo.org/downloads/
虚拟磁盘
1 2
| mkdir -p /home/kvm/dev qemu-img create -f qcow2 -o size=32G,preallocation=metadata /home/kvm/dev/dev.qcow2
|
用下载的LiveCD启动虚拟机
1 2 3 4 5 6 7 8 9
| virt-install --name dev --ram 4096 --vcpus=2 --disk path=/home/kvm/dev/dev.qcow2,format=qcow2,size=32,bus=virtio --cdrom /home/users/test/install-amd64-minimal-20200419T214502Z.iso --network bridge=brlan --noautoconsole --graphics vnc,listen=0.0.0.0,port=5910,password=11223311
|
VNC连接
1 2 3
| 配置IP, 可连接公网 配置root密码 开启sshd服务后改为ssh连接(方便)
|
安装
硬盘分区、格式化、挂载
1 2 3
| fdisk mke2fs /dev/vda1 -t ext4 -L / mount /dev/vda1 /mnt/gentoo/
|
DNS配置
1
| echo "nameserver 114.114.114.114" >> /etc/resolv.conf
|
stage3
官网下载https://www.gentoo.org/downloads/或把预下载好的scp到/mnt/gentoo目录
不要太旧
, 否则后面portage更新后, 会被折磨死
1 2
| cd /mnt/gentoo tar xpvf stage3-*.tar.xz --xattrs-include='*.*' --numeric-owner
|
建议portage
更新源换为163或阿里
1 2
| mkdir /mnt/gentoo/etc/portage/repos.conf cp /mnt/gentoo/usr/share/portage/config/repos.conf /mnt/gentoo/etc/portage/repos.conf/gentoo.conf
|
/mnt/gentoo/etc/portage/repos.conf
1 2 3 4 5 6 7 8
| [DEFAULT] main-repo = gentoo
[gentoo] location = /var/db/repos/gentoo sync-type = websync sync-uri = https://mirrors.163.com/gentoo-portage/ auto-sync = no
|
建议下载源
换为163或阿里
1
| mirrorselect -i -o >> /mnt/gentoo/etc/portage/make.conf
|
chroot
1 2 3 4 5 6 7
| cp /etc/resolv.conf /mnt/gentoo/etc/resolv.conf mount --bind /sys /mnt/gentoo/sys mount --bind /dev /mnt/gentoo/dev mount -t proc proc /mnt/gentoo/proc chroot /mnt/gentoo/ /bin/bash
export PS1="(chroot) ${PS1}"
|
更新portage
按需选择profile
1 2 3 4 5 6 7 8 9
| (chroot) livecd ~ # eselect profile list Available profile symlink targets: [1] default/linux/amd64/17.1 (stable) * [2] default/linux/amd64/17.1/selinux (stable) [3] default/linux/amd64/17.1/hardened (stable) [4] default/linux/amd64/17.1/hardened/selinux (stable) ... ...
(chroot) livecd ~ # eselect profile set NUMBER
|
更新系统
1
| emerge --ask --verbose --update --deep --newuse @world
|
先安装vim, 方便编辑(非必须)
设置时区(非必须)
1 2
| echo "Asia/Shanghai" > /etc/timezone emerge --config sys-libs/timezone-data
|
配置内核
下载内核
1
| emerge --ask sys-kernel/gentoo-sources
|
安装pciutils(非必须)
1
| emerge --ask sys-apps/pciutils
|
按需配置、编译、安装
参考 https://wiki.gentoo.org/wiki/QEMU/Linux_guest
1 2 3 4
| cd /usr/src/linux make defconfig make kvm_guest.config make -j`nproc` && make modules_install && make install
|
/etc/fstab配置
1
| LABEL=/ / ext4 noatime 0 1
|
网络配置
1
| emerge -av net-misc/netifrc
|
/etc/conf.d/net
1 2
| config_eth0="192.168.0.2 netmask 255.255.255.0 brd 192.168.0.255" routes_eth0="default via 192.168.0.1"
|
eth0 开机启动
1 2
| ln -s /etc/init.d/net.lo /etc/init.d/net.eth0 rc-update add net.eth0 default
|
配置root密码
sshd开机启动
1
| rc-update add sshd default
|
一些工具安装
1 2 3 4 5 6 7
| emerge -av sys-process/cronie rc-update add cronie default
emerge -av app-admin/rsyslog rc-update add rsyslog default
emerge -av sys-apps/mlocate
|
Grub2(bootloader)安装
1 2 3
| emerge -av sys-boot/grub:2 grub-install /dev/vda grub-mkconfig -o /boot/grub/grub.cfg
|
测试
退出chroot, 重启测试
1
| virsh destroy|start dev2
|
排错
挂载Live CD启动
/etc/libvirt/qemu/dev2.xml
cdrom 指定iso
1 2 3 4 5 6 7
| <disk type='file' device='cdrom'> <driver name='qemu' type='raw'/> <source file='/home/users/test/install-amd64-minimal-20200419T214502Z.iso'/> <target dev='hdc' bus='ide'/> <readonly/> <address type='drive' controller='0' bus='1' unit='0'/> </disk>
|
优先cdrom 启动
1 2 3 4 5
| <os> <type arch='x86_64' machine='pc-q35-5.1'>hvm</type> <boot dev='cdrom'/> <boot dev='hd'/> </os>
|
网卡命名不是eth0
1 2 3
| ln -s /dev/null 80-net-name-slot.rules ln -s /dev/null 80-net-setup-link.rules ln -s /dev/null 80-net-setup-slot.rules
|