给U盘装上Arch Linux

2020-10-26
Cover Image

本文最后更新于 天前,文中部分描述可能已经过时。

开始

虚拟机配置

由于是给U盘安装操作系统所以我们需要用到虚拟机,我用的实体系统是Ubuntu 20.04 LTS,虚拟机也只好选择Virtual Box(说实话模拟USB IO性能不咋样,配置上也遇到了不少问题

话不多说打开Virtual Box

  1. New新建虚拟机

  2. 给机器起个名字

  3. Type选择Linux

  4. Version选择Arch Linux (64-bit)

  5. Hard disk选择Do not add a virtual hard disk不用虚拟硬盘

  6. 把下载的安装镜像挂进去

  7. U盘插上

  8. 选择虚拟机 Settings->USB->Enable USB Controller->USB 3.0 (xHCI) Controller

  9. 启动安装介质

如果遇到无法选择USB Controller安装与Virtual box 版本相同Extensions,/sbin/vboxconfig重新构建内核(这个失败的话把创建vboxusers组把当前用户加到这个组里

1
2
3
$ sudo addgroup vboxusers
$ sudo addusers $(whoami) vboxusers
$ sudo /sbin/vboxconfig

进行U盘分区划分

启动虚拟机后进入Arch linux 终端界面 挂载USB Device

执行命令lsblk查看sdx是否已被挂载

1
# lsblk -l
1
2
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda 8:0 1 57.8G 0 disk

终端执行命令fdisk /dev/sda开始对U盘进行分区

创建GPT分区表

1
2
3
Command (m for help): g

Created a new GPT disklabel (GUID: DD664A3C-D3E5-EA4F-A3AD-9FE37AFAC3DE).

创建起始分区

1
2
3
4
5
6
7
8
9
10
11
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.

创建第二分区

1
2
3
4
5
6
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.

创建第三分区

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.

创建第四分区

1
2
3
4
5
6
7
8
9
10
11
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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'.

查看分区是否修改成功

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.

写入分区并退出

1
Command (m for help): wq

格式化分区文件系统

1
2
3
# mkfs.vfat -n EFI /dev/sda2
# mkfs.ext4 -L arch /dev/sda3
# mkfs.exfat /dev/sda4

准备安装系统

修改镜像源

备份源文件

1
# cp /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak

创建新镜像文件

1
# vim /etc/pacman.d/mirrorlist
1
2
3
4
5
6
## 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保存并退出

挂载系统分区

1
# mount /dev/sda3 /mnt

安装系统

通过pacstrap安装packages

1
# pacstrap /mnt base linux linux-firmware networkmanager vim man-db texinfo

配置系统

生成fstab

1
# genfstab -U /mnt /mnt/etc/fstab

Chroot

1
# arch-chroot /mnt

设置时区

1
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

设置时钟

1
# hwclock --systohc

本地化

设置LANG环境变量

1
# echo "LANG=en_US.UTF-8" > /etc/locale.conf

取消/etc/locale.genen_US.UTF-8 UTF-8注释

1
# vim /etc/locale.gen

网络配置

创建主机名

1
# echo -n "archlinux" > /etc/hostname

创建host文件

1
# vim /etc/hosts
1
2
3
127.0.0.1	localhost
::1 localhost
127.0.1.1 archlinux

配置密码

1
# passwd

配置grub

安装grub

1
# pacman -S grub

挂载sda2/boot/efi

1
# mount /dev/sda2 /boot/efi

将x86 EFI 模式的Grub安装到UEFI

1
# grub-install --target=x86_64-efi --efi-directory=/boot/efi --removable

将BIOS模式的Grub安装到/dev/sda

1
# grub-install --target=i386-pc /dev/sda

进入安装好的系统

  1. exit退出已经安装好的系统安装介质

  2. shutdown -h now关闭虚拟机

  3. 重启实体机进入选择引导界面引导U盘内的archlinux

  4. 输入用户名输入登陆密码进入系统

网络连接

启用Networkmanager

1
# systemctl enable NetworkManager

显示附近wifi

1
# nmcli device wifi list

连接wifi

1
# nmcli device wifi connect SSID password password

安装图形化界面

1
# pacman -S xorg sddm plasma noto-fonts mesa

安装声音驱动

1
# pacman -S alsa-utils pulseaudio pulseaudio-alsa pulseaudio-bluetooth bluez bluez-utils

启用图形化服务

1
2
# systemctl enable sddm.service
# systemctl set-default graphical.target

安装sudo

1
# pacman -S sudo

添加sudo至用户组

1
# groupadd sudo

添加用户

1
2
3
# useradd -m user
# usermod -aG audio,video,sudo user
# passwd user

至此arch linux安装完毕

输入reboot+Enter即可开始折腾~