跳过正文

安装ArchLinux+Windows双系统

·1447 字·3 分钟
折り紙 紫藤
作者
折り紙 紫藤
Prosper

最近看到Hyprland桌面比较漂亮,刚好手里有一本运行Windows已经比较卡顿的Intel核显本,于是尝试着在这本上面安装了ArchLinux和Windows的双系统。由于Arch安装过程中存在一些问题,因此将安装过程统一的做记述。

安装目标
#

  • ArchLinux和Windows双系统;
  • 使用grub作为引导;
  • 支持SecureBoot;
  • 安装常用包管理器yay。

前期准备
#

将EFI引导分区扩容到400MB左右。

archlinux官网中下载最新的分发版,使用rufus和一个空U盘烧录一个启动镜像。

之后将镜像插入电脑,重启,进入BIOS设置并关闭Secure Boot(Archlinux分发版不支持在SecureBoot下安装)

之后通过U盘选择启动进入系统,如果电脑内包含NVIDIA显卡则在引导界面按E,在末尾加入nouveau.modeset=0来禁用开源驱动,在使用ctrl+x退出。

连接WiFi:
#

iwctl
device list
station <wlan> scan
station <wlan> get-networks
station <wlan> connect <wifi>
exit

ping -c 5 archlinux.org

# optional, change the mirror source
reflector --country China --save /etc/pacman.d/mirrorlist
systemctl stop reflector

timedatectl status

分区
#

进行分区(需要事先划分出一块空白区域)(示例使用了btrfs和ext4两种分区,这里使用btrfs):

# 查看硬盘空间
lsblk
fdisk -l

# 确定需要安装的硬盘,假设其为nvme0n1
# 分区
cfdisk /dev/nvme0n1
# 将目标区域划分为新块并保存,假设为nvme0n1p4

# 格式化
mkfs.btrfs -L Arch /dev/nvme0n1p4

# 挂载分区
mount /dev/nvme0n1p4 /mnt

# 创建必要子卷
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@log
btrfs subvolume create /mnt/@cache
btrfs subvolume create /mnt/@swap

# 挂载子卷
umount /mnt

mount -o noatime,compress=zstd,subvol=@ /dev/nvme0n1p4 /mnt

mkdir -p /mnt/{boot,home,.snapshots,var/log,var/cache,swap}

mount -o noatime,compress=zstd,subvol=@home /dev/nvme0n1p4 /mnt/home
mount -o noatime,compress=zstd,subvol=@snapshots /dev/nvme0n1p4 /mnt/.snapshots
mount -o noatime,compress=zstd,subvol=@log /dev/nvme0n1p4 /mnt/var/log
mount -o noatime,compress=zstd,subvol=@cache /dev/nvme0n1p4 /mnt/var/cache

mount /dev/nvme1n1p1 /mnt/boot # 将 /dev/nvme1n1p1 替换为 Windows EFI 启动分区所在分区

# 挂载swap子卷和创建swap交换文件
mount -o subvol=@swap /dev/nvme0n1p4 /mnt/swap

chattr +C /mnt/swap
fallocate -l 16G /mnt/swap/swapfile
chmod 600 /mnt/swap/swapfile
mkswap /mnt/swap/swapfile
swapon /mnt/swap/swapfile

安装必要组件
#

pacstrap -K /mnt base base-devel linux linux-headers linux-firmware vim btrfs-progs ntfs-3g grub efibootmgr os-prober networkmanager sudo

根据你的电脑所使用的 CPU,安装 intel-ucodeamd-ucode,也可以安装 nano 用作文本编辑器

如果不使用 Btrfs 文件系统,可以不用安装 btrfs-progs

安装后配置
#

生成fstab文件

genfstab -U /mnt > /mnt/etc/fstab

确保swapfile条目为/path/to/swapfile none swap defaults 0 0

进入系统

arch-chroot /mnt

并设置时区

编辑 /etc/locale.gen,取消注释 en_US.UTF-8 UTF-8zh_CN.UTF-8 UTF-8,然后执行 locale-gen 生成 locale 信息

创建 /etc/locale.conf 文件

echo "LANG=en_US.UTF-8" > /etc/locale.conf

安装中文字体

pacman -S noto-fonts-cjk ttf-sarasa-gothic

配置主机名字

echo "<host>" > /etc/hostname

启用NetworkManager

systemctl enable NetworkManager

设置root用户密码

passwd

安装GRUB

grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=Arch

让 GRUB 找到 Windows,首先确保安装了 os-prober,然后编辑 /etc/default/grub 文件,找到 GRUB_DSIABLE_OS_PROBER=false 这一行,取消注释

生成 GRUB 配置文件

grub-mkconfig -o /boot/grub/grub.cfg

exit退出系统,reboot重启系统,应当能够开启grub引导菜单并正确启动arch系统。使用root用户登录。

创建普通用户

useradd -m -c "<用户全名>" -G wheel <用户名>
passwd <用户名> # 设置密码

配置 sudo并确保安装 sudo 并允许 wheel 组成员使用

EDITOR=vim visudo

找到 # %wheel ALL=(ALL:ALL) ALL 这一行,取消注释

之后是安装GUI,根据自己的爱好选择。

支持SecureBoot
#

Arch需要自己设置引导程序,方法非常多,在官方维基中有很多方法。这里我使用sbctl方法。

首先将固件设置为安全模式,进入BIOS设置后在BIOS启动设置附近应有相关内容。之后启动arch。

# 查看状态
sbctl status
# 应为三个x

# 创建密钥并注册
sbctl create-keys

sbctl enroll-keys -m -f

sbctl status # 应为一个v

# 重新安装grub
grub-install --target=x86_64-efi --efi-directory=esp --bootloader-id=GRUB --modules="tpm" --disable-shim-lock

# 签名
sbctl verify
sbctl verify | sed -E 's|^.* (/.+) is not signed$|sbctl sign -s "\1"|e'

sbctl status # 应为两个v

打开安全启动,重启系统,应该能够正常启动,运行sbctl status应该为三个v。

安装yay
#

yay是arch的另一个重要的包管理器。

git clone https://aur.archlinux.org/yay.git
export GO111MODULE=on
export GOPROXY=https://goproxy.cn
cd yay
makepkg -si