以 arm64 MacOS 为例

下载必要文件

wget https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/noble/current/unpacked/noble-server-cloudimg-arm64-vmlinuz-generic -O vmlinuz # kernel
wget https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/noble/current/unpacked/noble-server-cloudimg-arm64-initrd-generic -O initrd # initrd
wget https://mirrors.ustc.edu.cn/ubuntu-cloud-images/server/noble/current/noble-server-cloudimg-arm64.tar.gz -O sys.tar.gz # disk image

tar -xf sys.tar.gz
mv vmlinuz vmlinux.gz
gunzip vmlinux.gz
mkfile -n 20G disk.img

安装系统

vftool \
  -k vmlinux \
  -i initrd \
  -c noble-server-cloudimg-arm64.img \
  -d disk.img \
  -m 2048 \
  -a "console=hvc0"

之后进入 initramfs

dd if=/dev/vda of=/dev/vdb bs=1024k
mkdir /mnt
mount /dev/vdb /mnt
chroot /mnt

touch /etc/cloud/cloud-init.disabled
echo 'root:pa5sw0rd' | chpasswd
echo "arika" >/etc/hostname
ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
ssh-keygen -f /etc/ssh/ssh_host_dsa_key -N '' -t dsa
ssh-keygen -f /etc/ssh/ssh_host_ed25519_key -N '' -t ed25519
cat <<EOF > /etc/netplan/01-dhcp.yaml 
network:
    renderer: networkd
    ethernets:
        enp0s1:
            dhcp4: no
            addresses: [192.168.64.10/24]
            gateway4: 192.168.64.1
            nameservers:
                addresses: [192.168.64.1]
    version: 2
EOF
sed -i "/^PasswordAuthentication/ c PasswordAuthentication yes" /etc/ssh/sshd_config

useradd -mG sudo jerrita
echo 'jerrita:jerrita' | chpasswd
chsh -s /bin/bash jerrita
exit
umount /mnt

系统启动

vftool \
  -k vmlinux \
  -i initrd \
  -d disk.img \
  -m 3072 \
  -p 4 \
  -a "console=hvc0 root=/dev/vda" \
  -t 0

Post Install

resize2fs /dev/vda
sed -i 's/http/https/g' /etc/apt/sources.list
sed -i 's/ports.ubuntu.com/mirrors.ustc.edu.cn/g' /etc/apt/sources.list
Last modification:August 5, 2024
如果觉得我的文章对你有用,请随意赞赏