使用Btrfs快照安装Arch Linux
Anne655
・5 分钟阅读
前言
Arch Linux是一种通用的发行版,它以尖端的技术和灵活的配置而闻名。
前提条件
- 新创建的实例,
- 一些空闲时间和耐心,
准备
启动机器后,单击View Console
,并且启动系统,我们需要为环境设置root密码,以便可以从工作计算机访问它:
passwd
systemctl start sshd
关闭VNC窗口并通过ssh连接到机器:
ssh root@<your host ip here>
安装tmux以便我们可以在不稳定的连接中保持会话:
pacman -Sy tmux
如果在安装期间意外关闭连接,只需将ssh返回到计算机,并且运行:
tmux attach
安装
首先,让我们把磁盘分区。
lsblk
mkfs.btrfs -m single -L arch /dev/vda
mount -o compress=lzo /dev/vda /mnt
接下来是一个棘手的部分: 创建子卷。
cd /mnt
btrfs su cr @
btrfs su cr @boot
btrfs su cr @home
btrfs su cr @log
btrfs su cr @pkg
btrfs su cr @srv
btrfs su cr @tmp
然后,挂载subvolumes
cd /
umount /mnt
mount -o compress=lzo,subvol=@ /dev/vda /mnt
cd /mnt
mkdir -p {boot,home,srv,var/{log,cache/pacman/pkg,tmp}}
mount -o compress=lzo,subvol=@boot /dev/vda boot
mount -o compress=lzo,subvol=@home /dev/vda home
mount -o compress=lzo,subvol=@log /dev/vda var/log
mount -o compress=lzo,subvol=@pkg /dev/vda var/cache/pacman/pkg
mount -o compress=lzo,subvol=@srv /dev/vda srv
mount -o compress=lzo,subvol=@tmp /dev/vda var/tmp
安装基本系统。
pacstrap -i /mnt base base-devel snapper vim
配置系统。
genfstab -U /mnt >> /mnt/etc/fstab
arch-chroot /mnt
ln -s /usr/share/zoneinfo/Region/City /etc/localtime # Replace Region/City with your value
hwclock --systohc
vim /etc/locale.gen # Uncomment en_US.UTF-8 UTF-8 line
locale-gen
echo"LANG=en_US.UTF-8" > /etc/locale.conf
pacman -S networkmanager
echo"your-hostname" > /etc/hostname # Replace your-hostname with your value
vim /etc/hosts # Configure 127.0.0.1 and ::1 lines accordingly
systemctl enable NetworkManager.service
为将来的远程登录启用sshd 。
vim /etc/ssh/sshd_config # Set PermitRootLogin yes
systemctl enable sshd.service
注意,最佳实践是将公钥放入~/.ssh/authorized_keys
文件中,而不是为root启用密码登录。
配置initramfs以满足我们对btrfs的需求。
vim /etc/mkinitcpio.conf
查找MODULES="..."
并将btrfs
添加到列表中。 重新生成initramfs
mkinitcpio -p linux
设置root密码。
passwd
安装和配置引导装载程序。
pacman -S grub
grub-install /dev/vda
grub-mkconfig -o /boot/grub/grub.cfg
exit
reboot
再次连接服务器(可能在短时间后); 等待启动完成,注意服务器指纹已经更改,因此你可能需要更改known_hosts
文件:
vim ~/.ssh/known_hosts
ssh root@<your host ip here>
让我们配置snapper,它自动完成快照过程。
snapper -c root create-config /
编辑配置和更改 TIMELINE_LIMIT_{HOURLY,DAILY,WEEKLY,MONTHLY,YEARLY}
根据你的需要。
vim /etc/snapper/configs/root
启用SystemD计时器。
systemctl enable snapper-timeline.timer
systemctl start snapper-timeline.timer
systemctl enable snapper-cleanup.timer
systemctl start snapper-cleanup.timer
作业完成!
系统配置现已完成。使用btrfs自动快照系统享受你新的Arch Linux吧!