Press "Enter" to skip to content

虚拟机使用EFI/GPT引导安装archlinux

一、vmware虚拟机设置

1、选择客户机操作系统:其他 Linux 5.x 或更高版本内核 64 位
2、网络类型选择:NAT
3、磁盘大小:16G
4、编辑虚拟机设置/选项/高级,固件类型选择:UEFI
5、为方便操作,开机进入 root@archiso ~ # 后,查看IP,修改root密码,然用终端工具连接。
root@archiso ~ # ip addr
2: ens33: mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet 192.168.106.131/24 metric 100 brd 192.168.106.255 scope global dynamic ens33
root@archiso ~ # passwd

二、分区

1、分区规划
root@archiso ~ # fdisk -l
Disk /dev/sda: 16 GiB, 17179869184 bytes, 33554432 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

分区 挂载点 大小 用途
/dev/sda1 /mnt/boot 512M EFI
/dev/arch/root /mnt 10G 根路径
/dev/arch/root /mnt/home 剩余的 家目录
/dev/arch/root SWAP 2G 交换分区

2、/dev/sda1做为启动分区
root@archiso ~ # fdisk /dev/sda
Welcome to fdisk (util-linux 2.37.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x9d271c3c.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-33554431, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-33554431, default 33554431): +512M
Created a new partition 1 of type ‘Linux’ and of size 512 MiB.

3、/dev/sda2使用lvm管理
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (1050624-33554431, default 1050624):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (1050624-33554431, default 33554431):
Created a new partition 2 of type ‘Linux’ and of size 15.5 GiB.
Command (m for help): w

创建物理卷(pv)

pvcreate /dev/sda2

创建卷组(vg)

vgcreate arch /dev/sda2

创建逻辑卷(lv)

lvcreate -n swap –size 2G arch
lvcreate -n root –size 10G arch
lvcreate -n home -l 100%FREE arch

4、格式化分区

mkfs.fat -F32 /dev/sda1
mkfs.xfs /dev/arch/root
mkfs.xfs /dev/arch/home

swap分区

mkswap /dev/arch/swap
swapon /dev/arch/swap

5、挂载分区
挂载根目录

mount /dev/arch/root /mnt

创建 /mnt/home 挂载点并挂载

mkdir /mnt/home
mount /dev/arch/home /mnt/home

创建 EFI 挂载点并挂载

mkdir -p /mnt/boot
mount /dev/sda1 /mnt/boot

检查分区

lsblk /dev/sda

NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 16G 0 disk
├─sda1 8:1 0 512M 0 part /mnt/boot
└─sda2 8:2 0 15.5G 0 part
├─arch-swap 253:0 0 2G 0 lvm [SWAP]
├─arch-root 253:1 0 10G 0 lvm /mnt
└─arch-home 253:2 0 3.5G 0 lvm /mnt/home

三、配置镜像源和安装基本包

1、配置清华、浙大源:

vim /etc/pacman.d/mirrorlist

Server = http://mirrors.tuna.tsinghua.edu.cn/archlinux/$repo/os/$arch
Server = http://mirrors.zju.edu.cn/archlinux/$repo/os/$arch

2、安装基本包

pacstrap /mnt base base-devel linux linux-firmware dhcpcd lvm2 xfsprogs

四、配置Fstab

root@archiso ~ # genfstab -L /mnt >> /mnt/etc/fstab
root@archiso ~ # cat /mnt/etc/fstab

/dev/mapper/arch-root UUID=3c29e5ad-1196-439d-949d-b17a4c714c2b

/dev/mapper/arch-root / xfs rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota 0 1

/dev/mapper/arch-home UUID=ab11e7e2-a462-4133-831f-c761e9029162

/dev/mapper/arch-home /home xfs rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota 0 2

/dev/sda1 UUID=7E15-B1DE

/dev/sda1 /boot vfat rw,relatime,fmask=0022,dmask=0022,codepage=437,iocharset=ascii,shortname=mixed,utf8,errors=remount-ro 0 2

/dev/mapper/arch-swap UUID=1588e8e3-88ca-4e20-8e9a-3f97420bc56a

/dev/mapper/arch-swap none swap defaults 0 0

五、基础配置

1、切换到新系统中
root@archiso ~ # arch-chroot /mnt
[root@archiso /]# pwd
/
[root@archiso /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/arch-root 10G 2.3G 7.7G 23% /
/dev/mapper/arch-home 3.5G 58M 3.5G 2% /home
/dev/sda1 511M 50M 462M 10% /boot
udev 429M 0 429M 0% /dev
shm 470M 0 470M 0% /dev/shm
run 470M 163M 307M 35% /run
tmp 470M 0 470M 0% /tmp

2、提前安装必须软件包

pacman -S vim dialog wpa_supplicant ntfs-3g networkmanager netctl

3、设置时区

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock –systohc

4、语言设置
去掉行首的#号,保存并退出

vim /etc/locale.gen

zh_CN.GB18030 GB18030
zh_CN.GBK GBK
zh_CN.UTF-8 UTF-8
zh_CN GB2312

然后运行以下命令

locale-gen

创建 locale.conf 文件

echo ‘LANG=zh_CN.UTF-8’ > /etc/locale.conf

5、网络配置
(1)设置主机名
echo arch-pc > /etc/hostname

vim /etc/hosts

127.0.0.1 localhost
127.0.0.1 arch-pc
::1 localhost
::1 arch-pc

(2)使用dhcp

pacman -S dhcpcd

配置开机启动

systemctl enable dhcpcd

6、lvm配置
如果根路径是lvm文件系统,需要进行一些配置,修改 /etc/mkinitcpio.conf 文件,在 HOOKS 块中 在 block 和 filesystems 之间增加 lvm2

vim /etc/mkinitcpio.conf

HOOKS=(base udev autodetect modconf block lvm2 filesystems keyboard fsck)

运行以下命令:

mkinitcpio -P

7、配置root密码

passwd

8、安装Intel-ucode(使用Intel CPU安装)

pacman -S intel-ucode

9、引导加载程序
(1)首先安装os-prober和ntfs-3g这两个包,它可以配合Grub检测已经存在的系统,自动设置启动选项。

pacman -S os-prober ntfs-3g

(2)EFI/GPT引导方式(本次实践对应引导方式)
安装grub与efibootmgr两个包:

pacman -S grub efibootmgr

部署grub:

grub-install –target=x86_64-efi –efi-directory=/boot –bootloader-id=grub

生成配置文件:

grub-mkconfig -o /boot/grub/grub.cfg

10、重启
(1)输入 exit 或 使用 Ctrl+d 退出 chroot 环境:

exit

exit
arch-chroot /mnt 32.58s user 10.32s system 2% cpu 27:41.76 total

(2)使用以下命令手动卸载所有分区

umount -R /mnt

(3)关机
shutdown -h now

(4)移除虚拟机ISO,重启虚拟机查看是否安装成功:
Arch Linux 5.14.12-arch1-1(tty1)
arch-pc login:

(5)为方便操作,安装sshd服务:

pacman –S openssh
systemctl start sshd
systemctl enable sshd

允许远程root登录

vim /etc/ssh/sshd_config

PermitRootLogin yes

systemctl restart sshd

Be First to Comment

发表评论

您的电子邮箱地址不会被公开。