ArchLinux MBR方式部署

Linux   2025-11-04 11:31   5   0  

设置网络

root@archiso ~ # cat /etc/systemd/network/20-ethernet.network 
[Match]
Name=ens18

[Network]
Address=172.30.81.20/16
Gateway=172.30.0.1
DNS=223.5.5.5
DNS=223.6.6.6
root@archiso ~ # systemctl restart systemd-networkd
root@archiso ~ # passwd root
New password:
Retype new password:
passwd: password updated successfully
root@archiso ~ #

设置磁盘

root@archiso ~ # fdisk /dev/sda

Welcome to fdisk (util-linux 2.41.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): o
Created a new DOS (MBR) disklabel with disk identifier 0x2da2a890.

Command (m for help): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x2da2a890

Command (m for help): n
Partition type
  p   primary (0 primary, 0 extended, 4 free)
  e   extended (container for logical partitions)
Select (default p):

Using default response p.
Partition number (1-4, default 1):
First sector (2048-209715199, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-209715199, default 209715199):

Created a new partition 1 of type 'Linux' and of size 100 GiB.
Partition #1 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): p
Disk /dev/sda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x2da2a890

Device     Boot Start       End   Sectors  Size Id Type
/dev/sda1        2048 209715199 209713152  100G 83 Linux

Filesystem/RAID signature on partition 1 will be wiped.

Command (m for help): wq
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@archiso ~ # mkfs.ext4 /dev/sda1
mke2fs 1.47.3 (8-Jul-2025)
Discarding device blocks: done                            
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: d3789a36-f95d-4ae0-ad10-634e78d59cc6
Superblock backups stored on blocks:
       32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
       4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (131072 blocks): done
Writing superblocks and filesystem accounting information: done  

root@archiso ~ # mount /dev/sda1 /mnt

设置镜像源

root@archiso ~ # cat /etc/pacman.d/mirrorlist
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch
Server = https://mirrors.aliyun.com/archlinux/$repo/os/$arch
root@archiso ~ # pacman -Sy
:: Synchronizing package databases...
core                                                                                      117.9 KiB   404 KiB/s 00:00 [########################################################################] 100%
extra                                                                                       7.9 MiB  3.14 MiB/s 00:03 [########################################################################] 100%
root@archiso ~ #

安装系统软件

root@archiso ~ # pacstrap /mnt linux linux-firmware linux-headers base base-devel vim bash-completion net-tools netctl

生成文件系统表文件

genfstab -U /mnt >> /mnt/etc/fstab

进入系统

arch-chroot /mnt

设置时间

# 更改时区为亚洲上海
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
hwclock --systohc
timedatectl status

生成系统字体

vim /etc/locale.gen 
##将这两项取消注释
en_US.UTF-8 UTF-8
zh_CN.UTF-8 UTF-8

修改后使用命令生成字体

locale-gen

修改系统字体

vim /etc/locale.conf
# 添加
LANG=en_US.UTF-8

更改主机名

vim /etc/hostsname

添加本机hosts

vim /etc/hosts

更改root密码

passwd

安装启动引导程序 GRUB

# 安装 grub
[root@archiso /]# pacman -S grub
# 传统的 BIOS 启动
[root@archiso /]# grub-install --target=i386-pc /dev/sda
Installing for i386-pc platform.
Installation finished. No error reported.
# 生成 grub.cfg
[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.
Systems on them will not be added to the GRUB boot configuration.
Check GRUB_DISABLE_OS_PROBER documentation entry.
Adding boot menu entry for UEFI Firmware Settings ...
done

重启

# 退出安装的系统
exit

# 取消/mnt目录的所有挂载
umount /mnt

# 重启
reboot

系统初始化

[root@archlinux ~]# cat /etc/systemd/network/ethernet.network 
[Match]
Name=ens18

[Network]
Address=172.30.81.20/16
Gateway=172.30.0.1

[root@archlinux ~]# cat /etc/resolv.conf
# Resolver configuration file.
# See resolv.conf(5) for details.
nameserver 223.5.5.5
nameserver 223.6.6.6

[root@archlinux ~]# pacman -S openssh
[root@archlinux ~]# systemctl enable sshd

[root@archlinux ~]# vim /etc/ssh/sshd_config
# 确保这三项是yes
PermitRootLogin yes
PubkeyAuthentication yes
PasswordAuthentication yes



下一篇
没有了
博客评论
还没有人评论,赶紧抢个沙发~
发表评论
说明:请文明发言,共建和谐网络,您的个人信息不会被公开显示。