Arch Linux安装过程记录(VMware & UEFI & GPT)
参考文档
1.更新系统时间
root@archiso ~ # timedatectl set-ntp true
root@archiso ~ # timedatectl status
2.硬盘分区格式化
| 分区 | 大小 | 类型 | HEX code |
|---|---|---|---|
| boot (引导分区) | 1G | EFI | ef00 |
| swap (交换分区) | 2G | swap | 8200 |
| Linux x86-64 root (/) (根文件系统) | 80G | Ext4 | 8304 |
root@archiso ~ # lsblk
root@archiso ~ # gdisk /dev/sda
root@archiso ~ # fdisk -l
# 将 ESP(EFI system partition) 格式化为 FAT32 格式
root@archiso ~ # mkfs.fat -F32 /dev/sda1
root@archiso ~ # mkfs.ext4 /dev/sda2
root@archiso ~ # mkswap /dev/sda3
3.镜像源
# 阿里云
Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch
# 腾讯
Server = https://mirrors.cloud.tencent.com/archlinux/$repo/os/$arch
# 华为
Server = https://repo.huaweicloud.com/archlinux/$repo/os/$arch
# 清华
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
# 东软
Server = https://mirrors.neusoft.edu.cn/archlinux/$repo/os/$arch
# 哈工大
Server = https://mirrors.hit.edu.cn/archlinux/$repo/os/$arch
# 更新软件包缓存
root@archiso ~ # pacman -Syy
4.安装 base 系统
# 先挂载 根分区
root@archiso ~ # mount /dev/sda2 /mnt
root@archiso ~ # swapon /dev/sda3
# 设置镜像源
root@archiso ~ # vim /etc/pacman.d/mirrorlist
root@archiso ~ # pacman -Syy
# 挂载 ESP
root@archiso ~ # mkdir /mnt/efi
root@archiso ~ # mount /dev/sda1 /mnt/efi
ESP(EFI system partition)
Typical mount points
/efi
/boot
Tip:
/efi is a replacement[6] for the previously popular (and possibly still used by other Linux distributions) ESP mountpoint /boot/efi.
The /efi directory is not available by default, you will need to first create it with mkdir(1) before mounting the ESP to it.
root@archiso ~ # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 571.4M 1 loop /run/archiso/sfs/airootfs
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /mnt/efi
├─sda2 8:2 0 70G 0 part /mnt
└─sda3 8:3 0 2G 0 part [SWAP]
sr0 11:0 1 695.3M 0 rom /run/archiso/bootmnt
root@archiso ~ # pacstrap /mnt base linux vim nano net-tools openssh dhcpcd
root@archiso ~ # pacstrap /mnt man
常规硬件的固件软件包:linux-firmware
# 生成 fstab 文件
root@archiso ~ # genfstab -U /mnt >> /mnt/etc/fstab
5.配置系统
root@archiso ~ # arch-chroot /mnt
# 设置时区
[root@archiso /]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
# 生成 /etc/adjtime
[root@archiso /]# hwclock --systohc
# 本地化
[root@archiso /]# vim /etc/locale.gen
/etc/locale.gen
...
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8
...
[root@archiso /]# locale-gen
Generating locales...
en_US.UTF-8... done
zh_CN.UTF-8... done
Generation complete.
# 设置系统语言
[root@archiso /]# echo "LANG=zh_CN.UTF-8" > /etc/locale.conf
# 设置 主机名
[root@archiso /]# echo Arch > /etc/hostname
# 设置 root 密码
[root@archiso /]# passwd
# 添加普通用户
[root@archiso /]# useradd -m huaqi
[root@archiso /]# passwd huaqi
[root@archiso /]# pacman -S sudo vi
sudo : /etc/sudoers
要为某个用户可以执行所有命令,在配置文件中加入:
用户名 ALL=(ALL) ALL
[root@archiso /]# visudo
huaqi ALL=(ALL) ALL
6.安装引导程序 GRUB
[root@archiso /]# pacman -S grub efibootmgr
“GRUB” 是启动引导器
“efibootmgr” 被 GRUB 脚本用来将启动项写入 NVRAM
#---------------------------------------------------#
# 将 GRUB EFI 应用 grubx64.efi 安装到 esp/EFI/GRUB/
# 并将其模块安装到 /boot/grub/x86_64-efi/
# 注意:
# --efi-directory 和 --bootloader-id 是 GRUB UEFI 特有的。--efi-directory 替代了已经废弃的 --root-directory。
# 您可能注意到在 grub-install 命令中没有一个 <device_path> 选项,例如 /dev/sda。事实上即使提供了 <device_path>,也会被 GRUB 安装脚本忽略,因为 UEFI 启动加载器不使用 MBR 启动代码或启动扇区。
# 确保 grub-install 命令是在你想要用 GRUB 引导的那个系统上运行的。也就是说如果你是用安装介质启动进入了安装环境中,你需要在 chroot 之后再运行 grub-install。如果因为某些原因不得不在安装的系统之外运行 grub-install,在后面加上 --boot-directory= 选项来指定挂载 /boot 目录的路径,例如 --boot-directory=/mnt/boot
#---------------------------------------------------#
[root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
--efi-directory=/efi
/efi 为 ESP 的挂载点
如果 ESP 的挂载点为 /boot, 改为:
--efi-directory=/boot
# 生成主配置文件
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
[root@archiso /]# exit
root@archiso ~ # umount -R /mnt
root@archiso ~ # reboot
#---------------------------------------------------#
# ------------------grub 安装过程------------------- #
#---------------------------------------------------#
[root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/efi --bootloader-id=GRUB
Installing for x86_64-efi platform.
Installation finished. No error reported.
[root@archiso /]# ls /boot
grub initramfs-linux-fallback.img initramfs-linux.img vmlinuz-linux
[root@archiso /]# grub-mkconfig -o /boot/grub/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-linux
Found initrd image: /boot/initramfs-linux.img
Found fallback initrd image(s) in /boot: initramfs-linux-fallback.img
done
7.重启后设置
# 启动 sshd 和 dhcpcd 服务
[root@Arch ~]# systemctl start sshd dhcpcd
[root@Arch ~]# systemctl enable sshd dhcpcd
[root@Arch ~]# rm -rf /*
>>>(ε=ε=ε=┏(゜ロ゜;)┛)>>>哈哈哈>>>
浙公网安备 33010602011771号