Skip to content

Instantly share code, notes, and snippets.

@PetrusZ
Last active March 21, 2020 17:46
Show Gist options
  • Save PetrusZ/947293692243c48fc21c744eb32f3816 to your computer and use it in GitHub Desktop.
Save PetrusZ/947293692243c48fc21c744eb32f3816 to your computer and use it in GitHub Desktop.
Use backup/restore scripts install gentoo

安装gentoo

Gentoo官方安装手册:amd64 handbook

备份/恢复配置脚本:AutoBackup

Gentoo配置备份:Gentooconfig

准备工作

  1. 准备一个U盘
  2. 下载ubuntu或其他发行版最新版本的livcd/installmedia https://ubuntu.com/download/desktop
  3. dd bs=4M if=/path/to/ubuntu.iso of=/dev/sdx status=progress oflag=sync将ubuntu installmedia安装到U盘中
  4. 使用ubuntu installmedia启动,选择try without install,联网并打开gentoo amd64_handbook参考

分区

分区列表

sda1    /boot      vfat                         >=256M          #注意分区设置flags为esp
sda2    /          ext4,btrfs,xfs,jfs.etc       remaining space

分区操作

parted -a optimal /dev/sdx
# 设置gpt label
(parted)mklabel gpt
# 设置单位为Mib
(parted)unit mib
# 设置boot分区
# esp is an alias for boot on GPT
(parted) mkpart primary fat32 1 257
(parted) set 1 esp on
(parted) name 1 boot
# 设置root分区
# For one other partition using 100% of remaining space
(parted) mkpart primary ext4 257 100%
(parted) name 2 rootfs
# 检查分区是否正确
(parted) print

# 格式化分区
mkfs.vfat /dev/sdx1
mkfs.ext4 /dev/sdx2

安装

  1. 下载stage3并解压
# 检查并同步时间
date; ntpd -q -g
# 或手动设置时间 eg:设置为2020年2月23日22点15分
# Use the MMDDhhmmYYYY syntax (Month, Day, hour, minute and Year).
date 022322152020

# 挂载rootfs
mkdir /mnt/gentoo
mount /dev/sdx2 /mnt/gentoo

# 下载stage3到/mnt/gentoo https://www.gentoo.org/downloads/
cd /mnt/gentoo; wget <PASTED_STAGE_URL>
# 验证其有效性
# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Media#Verifying_the_downloaded_files
gpg --keyserver hkps://hkps.pool.sks-keyservers.net --recv-keys 0xBB572E0E2D182910
# or
wget -O- https://gentoo.org/.well-known/openpgpkey/hu/wtktzo4gyuhzu8a4z5fdj3fgmr1u6tob?l=releng | gpg --import

# https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Stage#Verifying_and_validating
openssl dgst -r -sha512 stage3-amd64-<release>.tar.?(bz2|xz)
openssl dgst -r -whirlpool stage3-amd64-<release>.tar.?(bz2|xz)
gpg --verify stage3-amd64-<release>.tar.?(bz2|xz){.DIGESTS.asc,}

# 解压stage3到/mnt/gentoo
tar xpvf stage3-*.tar.bz2 --xattrs-include='*.*' --numeric-owner
  1. 挂载分区
# cp DNS info
cp --dereference /etc/resolv.conf /mnt/gentoo/etc/

mount --types proc /proc /mnt/gentoo/proc
mount --rbind /sys /mnt/gentoo/sys
mount --make-rslave /mnt/gentoo/sys
mount --rbind /dev /mnt/gentoo/dev
mount --make-rslave /mnt/gentoo/dev

# debian系系统需要
test -L /dev/shm && rm /dev/shm && mkdir /dev/shm
mount --types tmpfs --options nosuid,nodev,noexec shm /dev/shm
chmod 1777 /dev/shm

mount /dev/sdx1 /boot
mount ....
etc
  1. 进入chroot环境安装
chroot /mnt/gentoo /bin/bash
source /etc/profile
export PS1="(chroot) $PS1"

配置gentoo

配置make.conf

git clone git@github.com:PetrusZ/Backup4Config.git

cd Backup4config
./restore_config.sh portage

Sync ebuild repos

emerge-websync

Choose profile

Use custom profile which restored/installed by Backup4Config

https://wiki.gentoo.org/wiki/Profile_(Portage)#Creating_custom_profiles https://wiki.gentoo.org/wiki/Handbook:AMD64/Portage/CustomTree#Defining_a_custom_repository

eselect profile set <local-profile>

安装/更新

emerge -avt dev-vcs/git
emerge --sync

# update world前可能需要注释掉make.conf中的VIDEO_CARDS
emerge -avuDN --with-bdeps=y @world
dispatch-conf
emerge @preserved-rebuild

# 安装显卡驱动
emerge -avt nvidia-drivers

配置杂项

# Timezone
echo "Asia/Shanghai" > /etc/timezone
emerge --config sys-libs/timezone-data

# locales
# Add `zh_CN ISO-8859-1` & `zh_CN.UTF-8 UTF-8` to /etc/locales.gen
# And only enable `en_US.UTF-8 UTF-8` & `zh_CN.UTF-8 UTF-8`
vim /etc/locale.gen
locale-gen
eselect locale set en_US.utf8

# reload environment
env-update && source /etc/profile && export PS1="(chroot) ${PS1}"

配置/安装内核

eselect kernel, and use genkernall all for now.

配置系统

# /etc/fstab
# 详细信息可查看fstab文件中的注释和wiki https://wiki.gentoo.org/wiki/Fstab
/dev/sda1		/boot		vfat		defaults,noatime	0 2
/dev/sda2		/		ext4		noatime			0 1
/swapfile 		none 		swap 		defaults 		0 0

# Network
Use NetworkManager, it is out of box.

# Use Backup4Config restore/install system configura files
cd Backup4config
./restore_config.sh system

# Add user and set passwd
passwd root
# 先创建用户,然后再恢复用户配置
useradd -m -G wheel,floppy,audio,cdrom,video,usb,users,portage <username>
passwd <username>

# Edit /etc/sudoers
EDITOR=vim visudo
## Uncomment to allow members of group wheel to execute any command
%wheel ALL=(ALL) ALL

# Swapfile https://wiki.archlinux.org/index.php/swap#Swap_file
fallocate -l 16G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

# ssh root登陆
sudo vim /etc/ssh/sshd_config
# comment `PermitRootLogin prohibit-password`
# and add `PermitRootLogin yes` below

# Use Backup4Config install system
./install system

配置bootloader

# Use Backup4config to edit /etc/default/grub
# bootloader使用grub:# bootloader使用grub:2
grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Gentoo
grub-mkconfig -o /boot/grub/grub.cfg

User configura

su petrus
# run below commands as user
# Use Backup4Config restore/install user configura files
cd Backup4config
./restore_config.sh user
# Use Backup4Config install vim, zsh and tmux plugin
./install user
# Open vim and type `:PlugInstall`
# Open tmux and press prefix + I (capital i, as in Install) to fetch the plugin.

Reboot

Reboot前先检查系统:

  • boot目录是否有相应文件
  • GRUB是否正确生成配置并显示内核等文件
  • fstab是否正确无误
rm /stage3-*.tar.*

umount -l /mnt/gentoo/dev{/shm,/pts,}
umount -R /mnt/gentoo

reboot

# 再次检查系统是否正常
# 查看wifi列表
nmcli device wifi list
# 连接wifi
nmcli device wifi connect <SSID> passworld <password>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment