自己尝试安装了archlinux在虚拟机里,记录安装过程,不过现在archlinux的WIKI是描述清晰的,直接查看和参考即可。
Pacman常用命令 pacman命令的常用说明:
1 2 3 4 5 6 7 8 9 10 [root@LiarLee ~]# pacman -Sg gnome 查看gnome软件包组下面的所有软件包 [root@LiarLee ~]# pacman -Qe openssh 查询已经安装的软件包 [root@LiarLee ~]# pacman -Qs openssh 正则查询软件包 [root@LiarLee ~]# pacman -Rs $(pacman -Qtdq) 递归删除孤立软件包 [root@LiarLee ~]# pacman -Ss 关键字:在仓库中搜索含关键字的包 [root@LiarLee ~]# pacman -Qs 关键字: 搜索已安装的包 [root@LiarLee ~]# pacman -Qi 包名:查看有关包的详尽信息 [root@LiarLee ~]# pacman -Ql 包名:列出该包的文件 [root@LiarLee ~]# pacman -Syyu 下载 和 更新本地的所有软件包 [root@LiarLee ~]# pacman -U /var/cache/pacman/pkg/linux-aarch64-6.8.9-1-aarch64.pkg.tar.xz 使用cache软件包进行降级(如果需要的话
Archlinux Installation Version 2.0 Update at 2024-05-12 12:39 关于 EC2 上面的步骤。 EC2 如何预期使用 metal 规格的实例是无法使用UEFI 的(x64) , 所以最后妥协了, 还是回到了BIOS。
船新版本 设置一下子时区
1 timedatectl set-timezone Asia/Shanghai
格式化磁盘, 划分分区 这次安装的分区划分是:
disk
mountpoint
description
filesystem type
/dev/vda1
/boot
uefi_partitation
xfs
/dev/vda2
/
archroot
btrfs
如果使用的是 Grub 的方式, 那么现在创建一个 1M 的分区用来写入grub 的 core.img, 并且 1M 的分区需要标记为 BIOS Boot, 才可以正常启动。
fdisk 或者 gpartd 什么的都行
格式化文件系统
1 2 mkfs.vfat -F 32 /dev/vda1 mkfs.btrfs -L archroot /dev/vda2
挂载btrfs root, 在其中创建子卷.
创建子卷
卸载 btrfs 的 root 卷
分别挂载创建的子卷 和 uefi 分区
1 2 3 mount -t btrfs -o subvol=@ /dev/vda2 /mnt mkdir -pv /mnt/boot mount /dev/vda1 /mnt/boot
检查下挂载的和分区什么的是不是符合预期.
配置livecd软件repo地址, 准备开始安装.
1 reflector --country='china' > /etc/pacman.d/mirrorlist
pacstrap 安装内核, 基本文件系统, 固件, 常用软件,大概能想起来的就这么多.
1 2 3 pacstrap -K /mnt base linux linux-firmware vim htop wget curl btrfs-progs fastfetch openssh sudo containerd nerdctl zstd ttf-jetbrains-mono-nerd tree ranger ncdu mtr fish eza util-linux fzf bat xfsprogs alacritty git pacstrap -K /mnt base linux linux-firmware vim htop wget curl btrfs-progs fastfetch openssh sudo containerd nerdctl zstd ttf-jetbrains-mono-nerd tree ranger ncdu mtr fish eza util-linux fzf bat git xfsprogs neovim grub cloud-init dnsmasq
生成fstab, 需要编辑一下 , 修改里面不合理的内容参数.
1 genfstab -U /mnt >> /mnt/etc/fstab
chroot 切换 根文件系统
编辑字符集, 文件里面写英语字符, 偷懒
1 2 3 4 5 vim /etc/locale.gen en_US.UTF-8 UTF-8 locale-gen
编辑 mkinitcpio 的配置文件, 按需改, 必须 ec2 可能会需要 ena 什么的….
1 2 vim /etc/mkinitcpio.conf mkinitcpio -P
更改一下root用户的密码.
系统配置 一些七七八八的命令和步骤, 方便复制。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 ╰─>$ passwd ╰─>$ useradd -m hayden ╰─>$ passwd hayden ╰─>$ chsh -s /usr/bin/fish root ╰─>$ chsh -s /usr/bin/fish hayden ╰─>$ visudo ╰─>$ vim /etc/mkinitcpio.conf ╰─>$ cat /etc/mkinitcpio.conf MODULES=(ena) COMPRESSION="zstd" MODULES_DECOMPRESS="yes" ╰─>$ mkinitcpio -P ╰─>$ lsinitcpio /boot/initramfs-linux.img | grep ena ╰─>$ lsinitcpio /boot/initramfs-linux.img | grep nvme ╰─>$ cat /boot/loader/entries/arch.conf title Hayden Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options root=UUID=4a203946-565e-4cce-b5db-fb149ca0f7c0 rootflags=defaults,rw,subvolid=5 console=ttyS0 earlyprintk=serial,ttyS0,keep ╰─>$ sync ╰─>$ grub-mkconfig -o /boot/grub/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-linux Found initrd image: /boot/initramfs-linux.img Adding boot menu entry for UEFI Firmware Settings ... done ╰─>$ sudo systemctl enable cloud-init sshd systemd-networkd systemd-resolved Created symlink '/etc/systemd/system/cloud-init.target.wants/cloud-init.service' → '/usr/lib/systemd/system/cloud-init.service' . Created symlink '/etc/systemd/system/multi-user.target.wants/sshd.service' → '/usr/lib/systemd/system/sshd.service' . Created symlink '/etc/systemd/system/dbus-org.freedesktop.network1.service' → '/usr/lib/systemd/system/systemd-networkd.service' . Created symlink '/etc/systemd/system/multi-user.target.wants/systemd-networkd.service' → '/usr/lib/systemd/system/systemd-networkd.service' . Created symlink '/etc/systemd/system/sockets.target.wants/systemd-networkd.socket' → '/usr/lib/systemd/system/systemd-networkd.socket' . Created symlink '/etc/systemd/system/sysinit.target.wants/systemd-network-generator.service' → '/usr/lib/systemd/system/systemd-network-generator.service' . Created symlink '/etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service' → '/usr/lib/systemd/system/systemd-networkd-wait-online.service' .
UEFI+GPT 安装 Bootloader, 我懒了, 直接用 systemd-boot 了, 挺好用的.
1 2 bootctl install systemctl enable systemd-boot-update.service
创建一个 bootloader 新的启动项.
1 2 3 4 5 6 vim /boot/loader/entries/arch.conf title Arch Linux linux /vmlinuz-linux initrd /initramfs-linux.img options root=UUID=2538f94c-df39-43e5-be97-8a2bc7cd2f44 rootflags=subvol=@ rw
检查启动配置文件是否存在异常.
开一些服务的自动启动
1 ╰─>$ systemctl enable sshd
1 2 3 4 5 6 7 ## BIOS+GPT ```bash grub-install /dev/nvme2n1 vim /etc/default/grub GRUB_TIMEOUT=1 GRUB_DISTRIBUTOR="Hayden's Arch" GRUB_CMDLINE_LINUX_DEFAULT="loglevel=3 console=ttyS0 earlyprintk=serial,ttyS0,keep transparent_hugepage=never"
检查没有问题了之后, 就可以退出chroot\卸载\重启了.
1 2 3 4 exit sync umount -R /mnt reboot
Archlinux Installation Version 1.0 1. 获取Archlinux镜像 从这个页面获取镜像: LINK HERE
2. 启动到Archlinux Live环境 在VMware中使用镜像文件直接引导Archlinux Live环境。
3. 设置Archlinux的键盘布局 默认为US键盘布局,此处未作修改。
4. 连接到Internet 使用ip link命令查看目前网卡的状态
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 root@archiso ~ # ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> dmtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000 link/ether 00:0c:29:5e:ea:d5 brd ff:ff:ff:ff:ff:ff root@archiso ~ # ifconfig ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.229.129 netmask 255.255.255.0 broadcast 192.168.229.255 inet6 fe80::9888:f57a:5c25:9cf9 prefixlen 64 scopeid 0x20<link> inet6 fd15:4ba5:5a2b:1008:6e02:ff6:feeb:c250 prefixlen 64 scopeid 0x0<global> ether 00:0c:29:5e:ea:d5 txqueuelen 1000 (Ethernet) RX packets 199 bytes 18652 (18.2 KiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 186 bytes 23144 (22.6 KiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536 inet 127.0.0.1 netmask 255.0.0.0 inet6 ::1 prefixlen 128 scopeid 0x10<host> loop txqueuelen 1000 (Local Loopback) RX packets 0 bytes 0 (0.0 B) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 0 bytes 0 (0.0 B) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 root@archiso ~ # ping baidu.com PING baidu.com (123.125.114.144) 56(84) bytes of data. 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=1 ttl=128 time=14.8 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=2 ttl=128 time=13.6 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=3 ttl=128 time=17.1 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=4 ttl=128 time=14.1 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=5 ttl=128 time=13.9 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=6 ttl=128 time=14.7 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=7 ttl=128 time=13.5 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=8 ttl=128 time=16.2 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=9 ttl=128 time=16.9 ms 64 bytes from 123.125.114.144 (123.125.114.144): icmp_seq=10 ttl=128 time=14.1 ms ^C --- baidu.com ping statistics --- 10 packets transmitted, 10 received, 0% packet loss, time 26ms rtt min/avg/max/mdev = 13.543/14.895/17.105/1.278 ms
网络连接到此为止无需配置,可以正常访问网络。
5. 更新系统时间,硬件时间同步 使用命令查看系统时间以及硬件时间,将同步的当前时间写入硬件:
1 2 3 4 5 6 7 8 9 10 root@archiso ~ # timedatectl status Local time: Wed 2019-04-24 08:55:39 UTC Universal time: Wed 2019-04-24 08:55:39 UTC RTC time: Wed 2019-04-24 08:55:40 Time zone: UTC (UTC, +0000) System clock synchronized: yes NTP service: active RTC in local TZ: no root@archiso ~ # timedatectl set-ntp true
6. 建立系统的硬盘分区 建立硬盘分区,我建立了两个分区,一个根分区和一个交换分区。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 root@archiso ~ # fdisk -l Disk /dev/sda: 50 GiB, 53687091200 bytes, 104857600 sectors Disk model: VMware Virtual S Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xba00941d Device Boot Start End Sectors Size Id Type /dev/sda1 2048 1050623 1048576 512M 82 Linux swap / Solaris /dev/sda2 1050624 104857599 103806976 49.5G 83 Linux Disk /dev/loop0: 491.2 MiB, 515084288 bytes, 1006024 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
7. 已经建立分区的格式化
格式化ext4分区
1 root@archiso ~ # mkfs.ext4 /dev/sda2
格式化swap分区
1 2 root@archiso ~ # mkswap /dev/sda1 # 将/dev/sda1格式化为swap分区 root@archiso ~ # swapon /dev/sda1 # 将/dev/sda1启用为swap分区
8. 挂载分区 使用系统挂载点/mnt,将/dev/sda2作为系统的根目录挂载到/mnt上。
1 root@archiso ~ # mount /dev/sda2 /mnt
9. 定义安装所需的Mirrorlist 10. 安装基础的Archlinux系统组件 部署安装linux的文件系统,安装系统基础组建的软件包。
1 [root@LiarLee /]# pacstrap /mnt base
11. 新系统的相关配置 1. Fstab 根据自己建立的分区自动生成系统的分区表。 1 2 3 4 5 6 7 8 9 10 11 [root@LiarLee /]# genfstab -U /mnt >> /mnt/etc/fstab # 生成新的fstab,写入安装硬盘的/etc/fstab [root@LiarLee ~]# cat /etc/fstab # 查看新的分区表 # Static Information about the Filesystems. # See fstab(5) for Details. # <file system> <dir> <type> <options> <dump> <pass> # /dev/sda2 UUID=3b61b364-b9eb-4e31-b65a-55fdcf09c614 / ext4 rw,relatime 0 1 # /dev/sda1 UUID=91987ac9-fa6b-4ac5-a9c5-014169dcf058 none swap defaults 0 0
2. Chroot 使用chroot命令切换根文件系统。
1 [root@LiarLee /]# arch-chroot /mnt
3. Timezone chroot命令相当于直接将当前的shell切换到了新安装的系统中。 设置新的系统的时间及同步硬件时间。
1 2 [root@LiarLee /]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime [root@LiarLee /]# hwclock --systohc
4. 本地设置 5. 网络设置 配置hostname以及本地解析hosts文件的解析条目。
1 2 3 4 5 6 7 [root@LiarLee /]# vim /etc/hostname YOUR_HOSTNAME.YOUR_DOMAIN [root@LiarLee /]# vim /etc/hosts 127.0.0.1 localhost ::1 localhost IP_ADDRESS YOUR_HOSTNAME.YOUR_DOMAIN YOUR_HOSTNAME
6. 生成initramfs 为新的系统生成ramfs。 ramfs的作用是,利用ramfs的文件系统,快速驱动周边的系统设备。在ramfs的使命结束后,自动chroot到新系统的文件系统中。
1 [root@LiarLee /]# mkinitcpio -p linux
7. 设置root密码 修改root密码。
1 [root@LiarLee /]# passwd
8. 安装grub2 这里pacman命令已经可以使用了,因此直接在这个安装grub2,这样才可以在后面正确的重启到新安装好的系统。
1 2 [root@LiarLee /]# pacman -S grub2 [root@LiarLee /]# grub-mkconfig
12. 重启引导新系统 将已经安装完成的那个根分区卸载,之后就可以重启了。
1 2 3 [root@LiarLee /]# umount -R /mnt # umount 接触挂载新的根文件系统 [root@LiarLee /]# fuser /mnt # fuser 查看占用文件系统的进程,如果确认的话可以直接-k结束所有占用的进程 [root@LiarLee /]# reboot # 重启
13. 安装图形化界面 1. 安装Xorg 安装如下的所有组件,重启就可以进入图形化环境了。 1. 运行错误 xterm:command not found [root@LiarLee /]# pacman -S xterm zlib 1. 运行报错 twm:command not found [root@LiarLee /]# pacman -S xorg-twm xorg-xclock 1. 安装鼠标驱动 [root@LiarLee /]# pacman -S xf86-input-mouse 1. 安装VMware图形驱动 [root@LiarLee /]# pacman -S xf86-video-vmware 1. 安装Xorg服务本体 [root@LiarLee /]# pacman -S xorg-server xorg-xinit 1. 安装Gnome桌面环境 [root@LiarLee /]# pacman -S gnome 1. 安装GDM - Gnome桌面管理工具,也可用其他替换 [root@LiarLee /]# pacman -S gdm
2. 安装图形化之后测试启动速度 systemd提供了命令检测启动的速度,包括内核启动速度以及用户空间的启动速度。
systemd-analyze
systemd-analyze blame
1 2 3 [root@LiarLee ~]# systemd-analyze Startup finished in 1.892s (kernel) + 1.182s (userspace) = 3.075s graphical.target reached after 1.182s in userspace
3. 刷新国内的镜像源 1 2 3 4 5 6 7 [root@LiarLee /]# cd /etc/pacman.d/ [root@LiarLee pacman.d]# mv mirrorlist mirrorlist.bak [root@LiarLee pacman.d]# wget -O /etc/pacman.d/mirrorlist https://www.archlinux.org/mirrorlist/?country=CN [root@LiarLee pacman.d]# mv mirrorlist mirrorlist.rank [root@LiarLee pacman.d]# rankmirrors mirrorlist.rank >> mirrorlist [root@LiarLee pacman.d]# sed 's/^Server/#Server/g' ./mirrorlist >> ./mirrorlist [root@LiarLee pacman.d]# s[root@LiarLee pacman.d]# spacman -Syyu
14. 自行编译内核操作 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@LiarLee /]# pacman -S base-devel bc xmlto kmod inetutils [root@LiarLee /]# useradd -d /home/admin -p admin admin [root@LiarLee /]# chown -R admin:admin /home/admin [root@LiarLee /]# mkdir /home/admin/mk-new-kernel/ [root@LiarLee /]# su - admin [root@LiarLee /]# cd /home/admin/mk-new-kernel/ [root@LiarLee /]# wget https://cdn.kernel.org/pub/linux/kernel/v5.x/linux-5.0.8.tar.xz [root@LiarLee /]# tar xvf linux-5.0.8.tar.xz [root@LiarLee /]# cd linux-5.0.8/ [root@LiarLee /]# make clean && make mrproper [root@LiarLee /]# make localmodconfig [root@LiarLee /]# make nconfig [root@LiarLee /]# make
15. 部分问题
重启之后没有DHCP获取IP地址的解决方法:
1 2 3 [root@LiarLee /]# systemctl enable dhcpcd [root@LiarLee /]# systemctl start dhcpcd [root@LiarLee /]# pacman -S net-tools
Wayland + Sway + Hyprland. (计划中, 等我闲的不行了…..