Arch Linux Installation Workshop === --- # 會場內 Wifi ## ssid: archlinux.tw ## password: since20130818 ---- # 下載 Arch Linux iso + [官方列表](https://archlinux.org/download/) + [archlinux.tw](http://mirror.archlinux.tw/ArchLinux/iso/2022.07.01/) + [交大鏡像](https://archlinux.cs.nycu.edu.tw/iso/2022.07.01/) ---- ## 建立一個虛擬機器 #### QEMU 或其他你熟悉的虛擬機器軟體皆可 ```shell $ qemu-img create -f qcow2 archlinux.cow 32G ``` ---- ## 將 Arch iso 放進虛擬機裡面開機 建立 `run.sh` 如下 ```shell #!/bin/sh qemu-system-x86_64 \ -drive file=archlinux.cow,format=qcow2 \ -smp $(nproc) \ -m 16G \ -M q35 \ -device intel-iommu \ -cpu host \ -enable-kvm \ -cdrom archlinux-2022.07.01-x86_64.iso ``` RAM(-m) 和 CPU(-smp) 大小可依據個人需要做調整 ---- ## 第一個選項進入安裝介面 ![](https://i.imgur.com/tzuaW2y.png) --- # 網路設定 ## 虛擬機基本上不需要下面步驟 ---- ## 網路設定 —— 網路介面 ```shell root@archiso ~ # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp0s2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff inet 10.0.2.15/24 metric 100 brd 10.0.2.255 scope global dynamic enp0s2 valid_lft 86283sec preferred_lft 86283sec inet6 fec0::3793:fa93:301c:7db3/64 scope site temporary dynamic valid_lft 86286sec preferred_lft 14286sec inet6 fec0::5054:ff:fe12:3456/64 scope site dynamic mngtmpaddr noprefixroute valid_lft 86286sec preferred_lft 14286sec inet6 fe80::5054:ff:fe12:3456/64 scope link valid_lft forever preferred_lft forever ``` ---- ## 網路設定 —— SETUP ```shell root@archiso ~ # ip link set enp0s2 up ``` ---- ## 網路設定 —— 測試 ```shell root@archiso ~ # ping archlinux.org PING archlinux.org (95.217.163.246) 56(84) bytes of data. 64 bytes from archlinux.org (95.217.163.246): icmp_seq=1 ttl=255 time=319 ms 64 bytes from archlinux.org (95.217.163.246): icmp_seq=2 ttl=255 time=329 ms 64 bytes from archlinux.org (95.217.163.246): icmp_seq=3 ttl=255 time=352 ms ^C --- archlinux.org ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 318.878/333.302/351.935/13.819 ms ``` ---- ## 網路設定 —— 時間 ```shell root@archiso ~ # timedatectl set-ntp true ``` --- ## pacman & makepkg 設定 ---- ## `/etc/makepkg.conf` 可修改 `MAKEFLAGS` 加快套件編譯速度 ```shell=49 #-- Make Flags: change this for DistCC/SMP systems MAKEFLAGS="-j$(nproc)" #-- Debugging flags DEBUG_CFLAGS="-g" DEBUG_CXXFLAGS="$DEBUG_CFLAGS" #DEBUG_RUSTFLAGS="-C debuginfo=2" ``` ---- ## `/etc/pacman.conf` 啟用顏色、平行下載、彩蛋 ```shell=31 # Misc options #UseSyslog Color #NoProgressBar CheckSpace #VerbosePkgLists ParallelDownloads = 10 ILoveCandy ``` ---- ## `/etc/pacman.d/mirrorlist` 鏡像站列表,可加入下面幾組台灣的站點 或是直接從 `/etc/pacman.conf` 內作修改 ```shell Server = https://archlinux.cs.nycu.edu.tw/$repo/os/$arch Server = https://mirror.archlinux.tw/ArchLinux/$repo/os/$arch Server = http://archlinux.ccns.ncku.edu.tw/archlinux/$repo/os/$arch Server = https://free.nchc.org.tw/arch/$repo/os/$arch ``` [Mirror Overview](https://archlinux.org/mirrors/) ---- ## 確認可以正常進行同步 ```shell root@archiso ~ # pacman -Syy :: Synchronizing package databases... core 157.8 KiB 877 KiB/s 00:00 [-----------------------------] 100% extra 1712.2 KiB 7.18 MiB/s 00:00 [-----------------------------] 100% community 6.7 MiB 20.4 MiB/s 00:00 [-----------------------------] 100% ``` --- # 硬碟分割、格式化 ---- ## 查看已安裝硬碟 ```shell root@archiso ~ # fdisk -l Disk /dev/sda: 32 GiB, 34359738368 bytes, 67108864 sectors Disk model: QEMU HARDDISK Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk /dev/loop0: 689.79 MiB, 723292160 bytes, 1412680 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 ``` ---- 本次將安裝在 `/dev/sda` 上,配置如下: + 512M 給 `/boot` + 2G 給 swap + 其餘給 `/` :::success Tips: 也可以另外切一區 `/home` ,方便重灌備份。 ::: ---- 可以用 `cfdisk` 工具方便切割磁碟: ```shell root@archiso ~ # cfdisk /dev/sda ``` 選擇 gpt 後繼續 ![](https://i.imgur.com/x2WGVA7.png) ---- 建立第一個磁區 ![](https://i.imgur.com/k0haaT9.png) ---- 512M 留給 `/boot` ![](https://i.imgur.com/5ip7PN0.png) ---- 2G 的 SWAP ![](https://i.imgur.com/wZKhDbt.png) ---- 剩下就是根目錄 `/` 的 ![](https://i.imgur.com/xJFpZn9.png) ---- 確認好後選擇 `[Write]` 將變更寫入硬碟 ![](https://i.imgur.com/8qQtvgI.png) ---- 按下後要輸入 `yes` 才會確定寫入 ![](https://i.imgur.com/CcFKhjz.png) ---- 成功寫入後下面會有提示,便可以離開此介面 ![](https://i.imgur.com/w0m5cV3.png) ---- 也可以在 Command Line 確認切割結果: ```shell root@archiso ~ # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 689.8M 1 loop /run/archiso/airootfs sda 8:0 0 32G 0 disk ├─sda1 8:1 0 512M 0 part ├─sda2 8:2 0 2G 0 part └─sda3 8:3 0 29.5G 0 part sr0 11:0 1 795.3M 0 rom /run/archiso/bootmnt ``` ---- ## 將 partition 做格式化 ```shell root@archiso ~ # mkfs.vfat -F32 /dev/sda1 mkfs.fat 4.2 (2021-01-31) ``` ```shell root@archiso ~ # mkswap /dev/sda2 Setting up swapspace version 1, size = 2 GiB (2147479552 bytes) no label, UUID=20454172-8b24-416d-8f2e-869be9e650dc ``` ```shell root@archiso ~ # mkfs.ext4 /dev/sda3 mke2fs 1.46.5 (30-Dec-2021) Discarding device blocks: done Creating filesystem with 7732736 4k blocks and 1933312 inodes Filesystem UUID: 44a05c6e-65fa-4743-bbb7-1c1bf7d97cd1 Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done ``` ---- ## 掛載分區 ```shell root@archiso ~ # mount /dev/sda3 /mnt root@archiso ~ # mkdir /mnt/boot root@archiso ~ # mount /dev/sda1 /mnt/boot root@archiso ~ # swapon /dev/sda2 ``` ---- ## 確認掛載情況 ```shell root@archiso ~ # lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 689.8M 1 loop /run/archiso/airootfs sda 8:0 0 32G 0 disk ├─sda1 8:1 0 512M 0 part /mnt/boot ├─sda2 8:2 0 2G 0 part [SWAP] └─sda3 8:3 0 29.5G 0 part /mnt sr0 11:0 1 795.3M 0 rom /run/archiso/bootmnt ``` --- # 安裝系統 ---- ## 以 `/mnt` 作為根目錄安裝系統 ```shell root@archiso ~ # pacstrap /mnt base base-devel linux linux-firmware vim git ``` ---- ## 若造遇類似 PGP 問題可以先更新 keyring ```shell error: libcap: signature from "David Runge <dvzrv@archlinux.org>" is marginal trust :: File /mnt/var/cache/pacman/pkg/libcap-2.65-1-x86_64.pkg.tar.zst is corrupted (invalid or corrupted package (PGP signature)). Do you want to delete it? [Y/n] error: failed to commit transaction (invalid or corrupted package) Errors occurred, no packages were upgraded. ==> ERROR: Failed to install packages to new root ``` ```shell root@archiso ~ # pacman -S archlinux-keyring resolving dependencies... looking for conflicting packages... Packages (1) archlinux-keyring-20220713-2 Total Download Size: 1.08 MiB Total Installed Size: 1.53 MiB Net Upgrade Size: 0.07 MiB :: Proceed with installation? [Y/n] :: Retrieving packages... archlinux-keyring-20220713... 1101.0 KiB 5.27 MiB/s 00:00 [--------------------------------] 100% (1/1) checking keys in keyring [--------------------------------] 100% (1/1) checking package integrity [--------------------------------] 100% (1/1) loading package files [--------------------------------] 100% (1/1) checking for file conflicts [--------------------------------] 100% (1/1) checking available disk space [--------------------------------] 100% :: Processing package changes... (1/1) upgrading archlinux-keyring [--------------------------------] 100% ==> Appending keys from archlinux.gpg... ==> Locally signing trusted keys in keyring... -> Locally signed 1 keys. ==> Importing owner trust values... gpg: setting ownertrust to 4 ==> Disabling revoked keys in keyring... -> Disabled 2 keys. ==> Updating trust database... gpg: marginals needed: 3 completes needed: 1 trust model: pgp gpg: depth: 0 valid: 1 signed: 6 trust: 0-, 0q, 0n, 0m, 0f, 1u gpg: depth: 1 valid: 6 signed: 93 trust: 0-, 0q, 0n, 6m, 0f, 0u gpg: depth: 2 valid: 70 signed: 30 trust: 70-, 0q, 0n, 0m, 0f, 0u gpg: next trustdb check due at 2022-08-09 ==> Updating trust database... gpg: next trustdb check due at 2022-08-09 :: Running post-transaction hooks... (1/1) Arming ConditionNeedsUpdate... ``` 接著重新 pacstrap 一次即可 ---- ## 安裝成功訊息如下 ```shell pacstrap /mnt base base-devel linux linux-firmware vim git 14.67s user 5.94s system 102% cpu 20.013 total ``` ---- ## 將磁碟分割表匯入 ```shell root@archiso ~ # genfstab -U /mnt >> /mnt/etc/fstab ``` 檢查 `/` 、 `/boot` 跟 SWAP 分區都在 ```shell root@archiso ~ # cat /mnt/etc/fstab # Static information about the filesystems. # See fstab(5) for details. # <file system> <dir> <type> <options> <dump> <pass> # /dev/sda3 UUID=44a05c6e-65fa-4743-bbb7-1c1bf7d97cd1 / ext4 rw,relatime 0 1 # /dev/sda1 UUID=219C-ECF2 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2 # /dev/sda2 UUID=20454172-8b24-416d-8f2e-869be9e650dc none swap defaults 0 0 ``` ---- ## 進入安裝好的系統 ```shell root@archiso ~ # arch-chroot /mnt [root@archiso /]# ``` 進入後記得重新做一次 [pacman & makepkg 設定](#3) --- # 時區、語系設定 ---- ## 台北時區 ```shell [root@archiso /]# ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime ``` ## 同步硬體時鐘 ```shell [root@archiso /]# hwclock --systohc ``` ---- ## 語言環境 編輯 `/etc/locale.gen` 取消註解如下 ```shell=175 #en_SG.UTF-8 UTF-8 #en_SG ISO-8859-1 en_US.UTF-8 UTF-8 #en_US ISO-8859-1 #en_ZA.UTF-8 UTF-8 ``` 設定系統語言 ```shell [root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf ``` :::danger 注意:相當不建議預設使用中文環境。 ::: ---- ## 產生 locale ```shell [root@archiso /]# locale-gen Generating locales... en_US.UTF-8... done Generation complete. ``` --- # 網路設定 ---- ## 設定主機名稱 這邊以 `archbtw` 作為示範 ```shell [root@archiso /]# echo "archbtw" > /etc/hostname ``` ---- ## 編輯 `/etc/hosts` 如下 橫的三個欄位分別代表 IPAddress 、 Hostname 、 Alias ```shell 127.0.0.1 localhost ::1 localhost 127.0.0.1 archbtw.localdomain archbtw ``` 固定 IP 要將 `127.0.0.1` 替換成 IP 位址 ---- ## 安裝網路相關套件 ```shell [root@archiso /]# pacman -S net-tools wpa_supplicant wireless_tools networkmanager ``` ## 啟用 NetworkManager ```shell [root@archiso /]# systemctl enable NetworkManager ``` --- # 準備開機環境 ---- ## 設定 root 密碼 ```shell [root@archiso /]# passwd New password: Retype new password: passwd: password updated successfully ``` ---- ## Bootloader —— GRUB ```shell [root@archiso /]# pacman -S efibootmgr grub ``` ## 確認是否支援 UEFI ### 支援 ```shell [root@archiso /]# ls /sys/firmware/efi config_table efivars esrt fw_platform_size fw_vendor runtime runtime-map systab ``` ### 不支援 ```shell [root@archiso /]# ls /sys/firmware/efi ls: cannot access '/sys/firmware/efi': No such file or directory ``` ---- ## 新增 GRUB 至開機選單 ### GPT/UEFI ```shell [root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub ``` ### BIOS/MBR QEMU 要記得加個 `--force` ```shell [root@archiso /]# grub-install --target=i386-pc /dev/sda --force ``` ### 安裝成功訊息如下 ```shell Installation finished. No error reported. ``` ---- ## 產生 grub config ```shell [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 Warning: os-prober will not be executed to detect other bootable partitions. System on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry. done ``` ---- ## 重新開機進入系統 ```shell [root@archiso /]# exit exit root@archiso ~ # umount /mnt/boot /mnt root@archiso ~ # shutdown now ``` QEMU 將 `-cdrom` 那行拿掉重新執行即可 --- # 第一次開機 ---- ## 選第一個進入系統 ![](https://i.imgur.com/5w0f1SF.png) ---- ## 登入 root 帳號 ![](https://i.imgur.com/FCRwQLy.png) ---- ## 確認網路正常運作 ```shell [root@archbtw ~]# ping archlinux.org PING archlinux.org (95.217.163.246) 56(84) bytes of data. 64 bytes from archlinux.org (95.217.163.246): icmp_seq=1 ttl=255 time=316 ms 64 bytes from archlinux.org (95.217.163.246): icmp_seq=2 ttl=255 time=313 ms 64 bytes from archlinux.org (95.217.163.246): icmp_seq=3 ttl=255 time=312 ms ^C --- archlinux.org ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms rtt min/avg/max/mdev = 311.925/313.554/315.739/1.605 ms ``` ---- ## 新建使用者 ```shell [root@archbtw ~]# useradd -m user ``` ## 設定使用者密碼 ```shell [root@archbtw ~]# passwd user New password: Retype new password: passwd: password updated successfully ``` ## 將使用者加入 wheel 群組 ```shell [root@archbtw ~]# usermod user -aG wheel ``` ---- ## 允許 wheel 組有 sudo 權限 ## 編輯 `/etc/sudoers` ```shell=84 ## Uncomment to allow members of group wheel to execute any command %wheel ALL=(ALL:ALL) ALL ``` ### vim 記得用 `:wq!` 強制存檔離開 --- # 桌面及中文環境 ---- ## 安裝顯示卡驅動 虛擬機可略過此步驟 ### NVIDIA ```shell [root@archbtw ~]# pacman -S nvidia nvtop ``` ### AMD ```shell [root@archbtw ~]# pacman -S mesa radeontop ``` ### INTEL ```shell [root@archbtw ~]# pacman -S mesa ``` ---- :::danger Intel 11 代以上 CPU + NVIDIA 注意新的 Linux Kernel(v5.18+) 可能會有[問題](https://wiki.archlinux.org/title/NVIDIA) ,開機參數後面要加 `ibt=off` ,或是用較舊的 Linux Kernel 。 ::: ---- ## 安裝桌面環境 下面僅用 Gnome 做示範 ### Gnome ```shell [root@archbtw ~]# pacman -S gnome gnome-extra gnome-tweaks [root@archbtw ~]# systemctl enable gdm Created symlink /etc/systemd/system/display-manager.service → /usr/lib/systemd/system/gdm.service. ``` ### KDE Plasma 5 ```shell [root@archbtw ~]# pacman -S plasma [root@archbtw ~]# systemctl enable sddm Created symlink /etc/systemd/system/display-manager.service → /usr/lib/systemd/system/sddm.service. ``` 安裝選項 Enter 按到底即可 ---- ## 重新開機進入桌面 ```shell [root@archbtw ~]# reboot ``` ![](https://i.imgur.com/TUWljoJ.png) ---- ## 安裝中文輸入法、字型 ```shell [user@archbtw ~]$ sudo pacman -S ibus ibus-chewing noto-fonts-cjk ``` ## 設定輸入引擎環境變數 編輯 `/etc/environment` 如下(需要 sudo 權限) ```shell GTK_IM_MODULE=ibus QT_IM_MODULE=ibus XMODIFIERS=@im=ibus ``` ## 重新開機進入桌面 ```shell [user@archbtw ~]$ reboot ``` ---- ## 找到設定 -> Keyboard -> Input Sources 新增 Other 裡面的 Chewing 並新增 ![](https://i.imgur.com/1R66zu3.png) ---- ## Preference 依據個人需要做調整 ![](https://i.imgur.com/zXhJcAP.jpg) ---- ## Preference(1/3) ![](https://i.imgur.com/r2T4Uk2.png) ---- ## Preference(2/3) ![](https://i.imgur.com/TMaXi49.png) ---- ## Preference(3/3) ![](https://i.imgur.com/FbFq9mU.png) --- # AUR Helper ---- ## 安裝 AUR Helper 下面用 yay 做示範,也可以用 [其他 AUR Helpers](https://wiki.archlinux.org/title/AUR_helpers) ```shell [user@archbtw ~]$ sudo pacman -S git ``` ```shell [user@archbtw ~]$ cd Desktop [user@archbtw Desktop]$ git clone https://aur.archlinux.org/yay.git [user@archbtw Desktop]$ cd yay ``` 安裝 yay ```shell [user@archbtw yay]$ makepkg -si ``` ---- ## 測試 yay 更新系統 ```shell [user@archbtw yay]$ yay -Syyu [sudo] password for user: :: Synchronizing package databases... core 157.8 KiB 1032 KiB/s 00:00 [--------------------------------] 100% extra 1712.2 KiB 8.36 MiB/s 00:00 [--------------------------------] 100% community 6.7 MiB 8.33 MiB/s 00:01 [--------------------------------] 100% :: Starting full system upgrade... there is nothing to do :: Searching databases for updates... :: Searching AUR for updates... there is nothing to do ``` ---- ## 現在可以安裝非官方包了 ```shell [user@archbtw yay]$ yay -S google-chrome ``` ---- ## 打開安裝好的 Chrome ![](https://i.imgur.com/3n0KgTh.png) ---- ## 到此 安裝結束 ### 歡迎加入 ![](https://i.imgur.com/PMI4rn8.png) ---- ## 最後切記 # 有問題先看 [ArchWiki](https://wiki.archlinux.org/) ---- ![](https://i.imgur.com/LvJ7PHn.png)
{"metaMigratedAt":"2023-06-17T05:31:39.551Z","metaMigratedFrom":"YAML","title":"Arch Linux Installation Workshop","breaks":true,"slideOptions":"{\"transition\":\"slide\"}","contributors":"[{\"id\":\"c74c9513-d06f-4364-9ff5-7d632f117e30\",\"add\":17473,\"del\":969}]"}
    966 views
   owned this note