技术解析
以 Oracle Cloud 环境为例,从现有 Linux 系统上安装 Archlinux [理论上可以无 VNC 实现]
以 Oracle Cloud 环境为例,启用一个 Oracle Linux 7.8 的实例,opc 登陆系统,sudo -i
切换为 root 用户。继续后续操作:
原系统
[[email protected] tmp]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
├─sda2 8:2 0 8G 0 part [SWAP]
├─sda3 8:3 0 38.4G 0 part /
└─sda1 8:1 0 200M 0 part /boot/efi
cd /tmp
wget https://mirrors.edge.kernel.org/archlinux/iso/latest/archlinux-bootstrap-2020.07.01-x86_64.tar.gz #下载最新 archlinux-bootstrap 压缩包
tar -xf archlinux-bootstrap-*.tar.gz
mount --bind /tmp/root.x86_64 /tmp/root.x86_64 #
vim /tmp/root.x86_64/etc/pacman.d/mirrorlist #
/tmp/root.x86_64/bin/arch-chroot /tmp/root.x86_64/ #第一层 chroot 命令
第一层 Chroot
#第一层 Chroot
export PS1='[email protected] #'
pacman-key --init
pacman-key --populate archlinux
pacman -Syy
mount /dev/sda3 /mnt
mount /dev/sda1 /mnt/boot/efi
[email protected] #lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 46.6G 0 disk
|-sda1 8:1 0 200M 0 part /mnt/boot/efi
|-sda2 8:2 0 8G 0 part [SWAP]
`-sda3 8:3 0 38.4G 0 part /mnt
cd /mnt
#!!!!!除了 boot 、tmp 、dev 、proc 、run 、sys 几个目录外的其他所有文件!!!!!
[email protected] #ls
bin boot dev etc home lib lib64 media mnt opt proc root run sbin srv sys tmp usr var
[email protected] #rm -rf bin etc home lib lib64 opt root sbin srv usr var
newroot=/mnt
mkdir -m 0755 -p "$newroot"/var/{cache/pacman/pkg,lib/pacman,log} "$newroot"/{dev,run,etc}
mkdir -m 1777 -p "$newroot"/tmp
mkdir -m 0555 -p "$newroot"/{sys,proc}
mount --bind "$newroot" "$newroot"
mount -t proc /proc "$newroot/proc"
mount --rbind /sys "$newroot/sys"
mount --rbind /run "$newroot/run"
mount --rbind /dev "$newroot/dev"
pacman -r "$newroot" --cachedir="$newroot/var/cache/pacman/pkg" -Sy base linux linux-firmware openssh xfsprogs sudo vi vim
cp -a /etc/pacman.d/gnupg "$newroot/etc/pacman.d/"
cp -a /etc/pacman.d/mirrorlist "$newroot/etc/pacman.d/"
genfstab -U /mnt >> /mnt/etc/fstab
chroot "$newroot"
第二层 Chroot #以快速配置为目标,不做其它额外配置
#第二层 Chroot
export PS1='[email protected] #'
#检查一下 /etc/fstab,看看 uuid,卷之类的有没有错误,我这边就重复生成了一个根目录的配置,要删除
mount /dev/sda1 /boot/efi
vim /etc/locale.gen
#添加 en_US.UTF-8 UTF-8
locale-gen
#新建 systemd 网络配置
vim /etc/systemd/network/20-wired.network
[email protected] #cat /etc/systemd/network/20-wired.network
[Match]
Name=ens3
[Network]
DHCP=ipv4
#配置 root 密码
passwd
#允许 root 远程 ssh 登陆
vim /etc/ssh/sshd_config #添加 PermitRootLogin yes
#添加 PermitRootLogin yes
#启用 DHCP 网络和 sshd
systemctl enable systemd-networkd
systemctl enable sshd
#以下引导内容视个人情况,理论上可以达到无 VNC 环境的覆盖安装原有的 Linux 系统
#编辑原来的 grub 配置增加 archlinux 启动项
grub-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
#我这边还要手动修改一下生成的 grub 配置文件
linux /vmlinuz-linux 改成
linuxefi /vmlinuz-linux
initrd /initramfs-linux 改成
initrdefi /initramfs-linux
接下来就可以爽快地玩 Arch 了
[[email protected] ~]# neofetch
-` [email protected]
.o+` --------------
`ooo/ OS: Arch Linux x86_64
`+oooo: Host: KVM/QEMU (Standard PC (i440FX + PIIX, 1996) pc-i440fx-2.9)
`+oooooo: Kernel: 5.7.7-arch1-1
-+oooooo+: Uptime: 6 mins
`/:-:++oooo+: Packages: 129 (pacman)
`/++++/+++++++: Shell: bash 5.0.17
`/++++++++++++++: Resolution: 1024x768
`/+++ooooooooooooo/` Terminal: /dev/pts/0
./ooosssso++osssssso+` CPU: AMD EPYC 7551 (2) @ 1.996GHz
.oossssso-````/ossssss+` GPU: 00:02.0 Vendor 1234 Device 1111
-osssssso. :ssssssso. Memory: 63MiB / 976MiB
:osssssss/ osssso+++.
/ossssssss/ +ssssooo/-
`/ossssso+/:- -:/+osssso+-
`+sso+:-` `.-/+oso:
`++:. `-/+/
.` `/
[[email protected] ~]#
refer: https://www.vnf.cc/2020/07/install-archlinux-from-linux/