给U盘装上Arch Linux
开始
虚拟机配置
由于是给 U 盘安装操作系统所以我们需要用到虚拟机,我用的实体系统是 Ubuntu 20.04 LTS,虚拟机也只好选择 Virtual Box(说实话模拟 USB IO 性能不咋样,配置上也遇到了不少问题
话不多说打开 Virtual Box
- New 新建虚拟机
- 给机器起个名字
- Type 选择 Linux
- Version 选择 Arch Linux (64-bit)
- Hard disk 选择 Do not add a virtual hard disk 不用虚拟硬盘
- 把下载的安装镜像挂进去
- U 盘插上
- 选择虚拟机 Settings->USB->Enable USB Controller->USB 3.0 (xHCI) Controller
- 启动安装介质
如果遇到无法选择 USB Controller 安装与 Virtual box 版本相同 Extensions,
/sbin/vboxconfig
重新构建内核(这个失败的话把创建vboxusers
组把当前用户加到这个组里
$ sudo addgroup vboxusers
$ sudo addusers $(whoami) vboxusers
$ sudo /sbin/vboxconfig
进行 U 盘分区划分
启动虚拟机后进入 Arch linux 终端界面 挂载 USB Device
执行命令lsblk
查看sdx
是否已被挂载
# lsblk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 1 57.8G 0 disk
终端执行命令fdisk /dev/sda
开始对 U 盘进行分区
创建 GPT 分区表
Command (m for help): g
Created a new GPT disklabel (GUID: DD664A3C-D3E5-EA4F-A3AD-9FE37AFAC3DE).
创建起始分区
Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-121110494, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-121110494, default 121110494): +1M
Created a new partition 1 of type 'Linux filesystem' and of size 1 MiB.
Partition #1 contains a exfat signature.
Do you want to remove the signature? [Y]es/[N]o: y
The signature will be removed by a write command.
创建第二分区
Command (m for help): n
Partition number (2-128, default 2):
First sector (4096-121110494, default 4096):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4096-121110494, default 121110494): +100M
Created a new partition 2 of type 'Linux filesystem' and of size 100 MiB.
创建第三分区
Command (m for help): n
Partition number (2-128, default 2):
First sector (4096-121110494, default 4096):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (4096-121110494, default 121110494): +100M
Created a new partition 2 of type 'Linux filesystem' and of size 100 MiB.
Command (m for help): n
Partition number (3-128, default 3):
First sector (208896-121110494, default 208896):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (208896-121110494, default 121110494): +32G
Created a new partition 3 of type 'Linux filesystem' and of size 32 GiB.
Partition #3 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: y
The signature will be removed by a write command.
创建第四分区
Command (m for help): n
Partition number (4-128, default 4):
First sector (67317760-121110494, default 67317760):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (67317760-121110494, default 121110494):
Created a new partition 4 of type 'Linux filesystem' and of size 25.7 GiB.
Partition #4 contains a exfat signature.
Do you want to remove the signature? [Y]es/[N]o: y
The signature will be removed by a write command.
设置分区类型
Part | size | Type |
---|---|---|
1 | 1MiB | 4 |
2 | 100MiB | 1 |
3 | 32GiB | 20 |
4 | Default | 11 |
Command (m for help): t
Partition number (1-4, default 4): 1
Partition type or alias (type L to list all): 4
Changed type of partition 'Linux filesystem' to 'BIOS boot'.
Command (m for help): t
Partition number (1-4, default 4): 2
Partition type or alias (type L to list all): 1
Changed type of partition 'Linux filesystem' to 'EFI System'.
Command (m for help): t
Partition number (1-4, default 4): 3
Partition type or alias (type L to list all): 20
Changed type of partition 'Linux filesystem' to 'Linux filesystem'.
Command (m for help): t
Partition number (1-4, default 4): 4
Partition type or alias (type L to list all): 11
Changed type of partition 'Linux filesystem' to 'Microsoft basic data'.
查看分区是否修改成功
Command (m for help): p
Disk /dev/sda: 57.75 GiB, 62008590336 bytes, 121110528 sectors
Disk model: DataTraveler 3.0
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: gpt
Disk identifier: DD664A3C-D3E5-EA4F-A3AD-9FE37AFAC3DE
Device Start End Sectors Size Type
/dev/sda1 2048 4095 2048 1M BIOS boot
/dev/sda2 4096 208895 204800 100M EFI System
/dev/sda3 208896 67317759 67108864 32G Linux filesystem
/dev/sda4 67317760 121110494 53792735 25.7G Microsoft basic data
Filesystem/RAID signature on partition 1 will be wiped.
Filesystem/RAID signature on partition 3 will be wiped.
Filesystem/RAID signature on partition 4 will be wiped.
写入分区并退出
Command (m for help): wq
格式化分区文件系统
# mkfs.vfat -n EFI /dev/sda2
# mkfs.ext4 -L arch /dev/sda3
# mkfs.exfat /dev/sda4
准备安装系统
修改镜像源
备份源文件
# cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
创建新镜像文件
# vim /etc/pacman.d/mirrorlist
## aliyun
Server = http://mirrors.aliyun.com/archlinux/$repo/os/$arch
## tsinghua
Server = https://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
## 163
Server = http://mirrors.163.com/archlinux/$repo/os/$arch
:wq
保存并退出
挂载系统分区
# mount /dev/sda3 /mnt
安装系统
通过 pacstrap 安装 packages
# pacstrap /mnt base linux linux-firmware networkmanager vim man-db texinfo
配置系统
生成 fstab
# genfstab -U /mnt /mnt/etc/fstab
Chroot
# arch-chroot /mnt
设置时区
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
设置时钟
# hwclock --systohc
本地化
设置 LANG 环境变量
# echo "LANG=en_US.UTF-8" > /etc/locale.conf
取消/etc/locale.gen
中en_US.UTF-8 UTF-8
注释
# vim /etc/locale.gen
网络配置
创建主机名
# echo -n "archlinux" > /etc/hostname
创建 host 文件
# vim /etc/hosts
127.0.0.1 localhost
::1 localhost
127.0.1.1 archlinux
配置密码
# passwd
配置 grub
安装 grub
# pacman -S grub
挂载sda2
到/boot/efi
# mount /dev/sda2 /boot/efi
将 x86 EFI 模式的 Grub 安装到 UEFI
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable
将 BIOS 模式的 Grub 安装到/dev/sda
# grub-install --target=i386-pc /dev/sda
进入安装好的系统
exit
退出已经安装好的系统安装介质shutdown -h now
关闭虚拟机重启实体机进入选择引导界面引导 U 盘内的 archlinux
输入用户名输入登陆密码进入系统
网络连接
启用 Networkmanager
# systemctl enable NetworkManager
显示附近 wifi
# nmcli device wifi list
连接 wifi
# nmcli device wifi connect SSID password password
安装图形化界面
# pacman -S xorg sddm plasma noto-fonts mesa
安装声音驱动
# pacman -S alsa-utils pulseaudio pulseaudio-alsa pulseaudio-bluetooth bluez bluez-utils
启用图形化服务
# systemctl enable sddm.service
# systemctl set-default graphical.target
安装 sudo
# pacman -S sudo
添加 sudo 至用户组
# groupadd sudo
添加用户
# useradd -m user
# usermod -aG audio,video,sudo user
# passwd user
至此 arch linux 安装完毕
输入reboot
+Enter
即可开始折腾~