$ qemu-img create -f qcow2 archlinux.cow 32G
建立 run.sh
如下
#!/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) 大小可依據個人需要做調整
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
root@archiso ~ # ip link set enp0s2 up
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
root@archiso ~ # timedatectl set-ntp true
/etc/makepkg.conf
可修改 MAKEFLAGS
加快套件編譯速度
#-- 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
啟用顏色、平行下載、彩蛋
# Misc options #UseSyslog Color #NoProgressBar CheckSpace #VerbosePkgLists ParallelDownloads = 10 ILoveCandy
/etc/pacman.d/mirrorlist
鏡像站列表,可加入下面幾組台灣的站點
或是直接從 /etc/pacman.conf
內作修改
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
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%
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
上,配置如下:
/boot
/
Tips: 也可以另外切一區 /home
,方便重灌備份。
可以用 cfdisk
工具方便切割磁碟:
root@archiso ~ # cfdisk /dev/sda
選擇 gpt 後繼續
建立第一個磁區
512M 留給 /boot
2G 的 SWAP
剩下就是根目錄 /
的
確認好後選擇 [Write]
將變更寫入硬碟
按下後要輸入 yes
才會確定寫入
成功寫入後下面會有提示,便可以離開此介面
也可以在 Command Line 確認切割結果:
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
root@archiso ~ # mkfs.vfat -F32 /dev/sda1
mkfs.fat 4.2 (2021-01-31)
root@archiso ~ # mkswap /dev/sda2
Setting up swapspace version 1, size = 2 GiB (2147479552 bytes)
no label, UUID=20454172-8b24-416d-8f2e-869be9e650dc
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
root@archiso ~ # mount /dev/sda3 /mnt
root@archiso ~ # mkdir /mnt/boot
root@archiso ~ # mount /dev/sda1 /mnt/boot
root@archiso ~ # swapon /dev/sda2
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
作為根目錄安裝系統root@archiso ~ # pacstrap /mnt base base-devel linux linux-firmware vim git
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
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 一次即可
pacstrap /mnt base base-devel linux linux-firmware vim git 14.67s user 5.94s system 102% cpu 20.013 total
root@archiso ~ # genfstab -U /mnt >> /mnt/etc/fstab
檢查 /
、 /boot
跟 SWAP 分區都在
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
[root@archiso /]# ln -sf /usr/share/zoneinfo/Asia/Taipei /etc/localtime
[root@archiso /]# hwclock --systohc
編輯 /etc/locale.gen
取消註解如下
#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
設定系統語言
[root@archiso /]# echo "LANG=en_US.UTF-8" > /etc/locale.conf
注意:相當不建議預設使用中文環境。
[root@archiso /]# locale-gen
Generating locales...
en_US.UTF-8... done
Generation complete.
這邊以 archbtw
作為示範
[root@archiso /]# echo "archbtw" > /etc/hostname
/etc/hosts
如下橫的三個欄位分別代表 IPAddress 、 Hostname 、 Alias
127.0.0.1 localhost
::1 localhost
127.0.0.1 archbtw.localdomain archbtw
固定 IP 要將 127.0.0.1
替換成 IP 位址
[root@archiso /]# pacman -S net-tools wpa_supplicant wireless_tools networkmanager
[root@archiso /]# systemctl enable NetworkManager
[root@archiso /]# passwd
New password:
Retype new password:
passwd: password updated successfully
[root@archiso /]# pacman -S efibootmgr grub
[root@archiso /]# ls /sys/firmware/efi
config_table efivars esrt fw_platform_size fw_vendor runtime runtime-map systab
[root@archiso /]# ls /sys/firmware/efi
ls: cannot access '/sys/firmware/efi': No such file or directory
[root@archiso /]# grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=grub
QEMU 要記得加個 --force
[root@archiso /]# grub-install --target=i386-pc /dev/sda --force
Installation finished. No error reported.
[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
[root@archiso /]# exit
exit
root@archiso ~ # umount /mnt/boot /mnt
root@archiso ~ # shutdown now
QEMU 將 -cdrom
那行拿掉重新執行即可
[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
[root@archbtw ~]# useradd -m user
[root@archbtw ~]# passwd user
New password:
Retype new password:
passwd: password updated successfully
[root@archbtw ~]# usermod user -aG wheel
/etc/sudoers
## Uncomment to allow members of group wheel to execute any command %wheel ALL=(ALL:ALL) ALL
:wq!
強制存檔離開虛擬機可略過此步驟
[root@archbtw ~]# pacman -S nvidia nvtop
[root@archbtw ~]# pacman -S mesa radeontop
[root@archbtw ~]# pacman -S mesa
Intel 11 代以上 CPU + NVIDIA 注意新的 Linux Kernel(v5.18+) 可能會有問題 ,開機參數後面要加 ibt=off
,或是用較舊的 Linux Kernel 。
下面僅用 Gnome 做示範
[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.
[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 按到底即可
[root@archbtw ~]# reboot
[user@archbtw ~]$ sudo pacman -S ibus ibus-chewing noto-fonts-cjk
編輯 /etc/environment
如下(需要 sudo 權限)
GTK_IM_MODULE=ibus
QT_IM_MODULE=ibus
XMODIFIERS=@im=ibus
[user@archbtw ~]$ reboot
新增 Other 裡面的 Chewing 並新增
下面用 yay 做示範,也可以用 其他 AUR Helpers
[user@archbtw ~]$ sudo pacman -S git
[user@archbtw ~]$ cd Desktop
[user@archbtw Desktop]$ git clone https://aur.archlinux.org/yay.git
[user@archbtw Desktop]$ cd yay
安裝 yay
[user@archbtw yay]$ makepkg -si
[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
[user@archbtw yay]$ yay -S google-chrome