Skip to Content
ArchLinux安装

本文经过多年多次修改, 较为零散, 部分内容可能过期, 姑且能让系统跑起来, 请酌情参考

Create: 2021-03-25

为安装 magicbook 2019 linux 版, 参考性内容已置于片尾, 请酌情参考

Update: 23-11-21
移除全部可选配置, 固定使用 systemd-boot, systemd-networkd, 配置 shell 为 zsh

Update: 25-05-06
恢复使用 networkmanager, 后使用机械革命无界 14x,可参考记一些 Linux 小随笔

Update: 25-05-14
跟随最新版本的安装指南更新部分步骤

请阅读全文后进行

命令行安装

配置网络连接

  • wifi
iwctl station wlan0 scan station wlan0 connect $wifi quit
  • 有线
dhcpcd

同步时间

timedatectl

格式化分区

$disk 指向要安装的磁盘

boot 分区现在推荐 1GB+

fdisk -l cfdisk /dev/$disk mkfs.fat -F32 /dev/$disk mkfs.ext4 /dev/$disk //挂载磁盘及boot mount /dev/$disk /mnt mkdir /mnt/boot mount /dev/$disk /mnt/boot

编辑镜像源

/etc/pacman.d/mirrorlist
Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch

安装内核及固件

  • 如使用 systemd-networkd, 可不安装 networkmanager, wifi 使用 iwd 进行连接
pacstrap -K /mnt base base-devel linux linux-firmware iwd vim openssh networkmanager

写入分区信息

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

切换到新系统

arch-chroot /mnt

设置时区及同步硬件时间, 如硬件时间不准可使用 NTP 同上

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime hwclock --systohc
//配置语言本地化, 终端环境推荐使用en_US.UTF-8, 图形化使用如下配置 vim /etc/locale.gen //zh_CN.UTF-8 locale-gen vim /etc/locale.conf //LANG=zh_CN.UTF-8

配置 hostname

echo "$hostname" > /etc/hostname

配置 hosts, myhostname 同自定义名称

/etc/hosts
127.0.0.1 localhost ::1 localhost

配置 DNS

/etc/resolv.conf
nameserver 223.5.5.5

更改 root 密码

passwd

配置系统引导

  • systemd-boot
bootctl --path=/boot install
/boot/loader/loader.conf
default arch timeout 4 console-mode max editor no

$为要执行的命令返回值, 请勿无脑粘贴, /dev 后请指向根目录所在

/boot/loader/entries/arch.conf
title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options root=PARTUUID=($blkid -s PARTUUID -o value /dev/sdx2) rw

创建恢复镜像

/boot/loader/entries/arch-fallback.conf
title Arch Linux (fallback) linux /vmlinuz-linux initrd /initramfs-linux-fallback.img options root=PARTUUID=($blkid -s PARTUUID -o value /dev/sdx2) rw

配置每次更新后自动更新 boot

mkdir /etc/pacman.d/hooks
/etc/pacman.d/hooks/95-systemd-boot.hook
[Trigger] Type = Package Operation = Upgrade Target = systemd [Action] Description = Gracefully upgrading systemd-boot... When = PostTransaction Exec = /usr/bin/systemctl restart systemd-boot-update.service

重启后继续配置

如重启后出现问题, 请根据错误信息自查 arch wiki

reboot

创建交换分区, 内存超过 16g 可不配置

dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress chmod 600 /swapfile mkswap /swapfile swapon /swapfile vim /etc/fstab /swapfile none swap defaults 0 0

添加普通用户并允许 sudo, 很多东西都不支持 root 启动捏, 请替换 username 为自定义名称

useradd -m -G wheel username passwd username

ln vim 到 vi, 允许 wheel 组 sudo

ln -s /usr/bin/vim /usr/bin/vi visudo // #%wheel ALL=(ALL)ALL reboot

连接网络

sudo systemctl enable NetworkManager sudo systemctl start NetworkManager
  • WIFI
nmcli device wifi list nmcli device wifi connect $wifi名 password $密码
  • 有线连接

NetworkManager 会自动 DHCP,手动配置 IP 请参照文档

参考内容

以下内容请自行参考是否使用

  • 安装图形化页面, 使用 KDE
sudo pacman -S plasma sddm sudo systemctl enable sddm
  • 安装 zsh 及中文化字体及我爱用的 ubuntu 字体
sudo pacman -S zsh zsh-completions zsh-autosuggestions wqy-microhei ttf-ubuntu-font-family
  • zsh 配置
chsh -s $(which zsh)
/etc/zsh/zshrc
autoload -Uz compinit && compinit zstyle :compinstall filename '$HOME/.zshrc' if [[ -r /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh ]]; then source /usr/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh fi HISTFILE=~/.zsh_history HISTSIZE=1000 SAVEHIST=1000 alias ls='ls --color=auto' alias grep='grep --color=auto' autoload -Uz colors && colors PS1="%B%{$fg[red]%}[%{$fg[yellow]%}%n%{$fg[green]%}@%{$fg[blue]%}%M %{$fg[magenta]%}%~%{$fg[red]%}]%{$reset_color%}$%b "
  • 安装 amd 显卡驱动
sudo pacman -S xf86-video-amdgpu vulkan-radeon mesa 32支持(steam) sudo pacman -S lib32-mesa lib32-vulkan-radeon
  • bashrc 优化及 archcn 源
~/.bashrc
alias ls='ls --color=auto' alias grep='grep --color=auto' PS1='\[\e[1;36m\][\u@\h \W]\$ \[\e[m\]'
/etc/pacman.d/mirrorlist
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
/etc/pacman.conf
[archlinuxcn] Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
pacman -S archlinuxcn-keyring