更新于 2024-08-05
文章来源:https://www.cnblogs.com/phoebus-ma/p/17452001.html
来源:https://forum.pine64.org/showthread.php?tid=18202
sudo qemu-img create -f qcow2 alpine-arm.sda.qcow2 100G
sudo qemu-system-aarch64 \
-machine virt -cpu cortex-a72 -smp 8,sockets=2,cores=2,threads=2 \
-m 2g -nographic \
-bios QEMU_EFI.fd \
-drive format=raw,readonly=on,file=alpine-aarch64.iso \
-drive file=alpine-arm.sda.qcow2,media=disk,if=virtio
-net nic -net user,hostfwd=tcp::2222-:22
sudo qemu-system-aarch64 \
-machine virt -cpu cortex-a72 -smp 8,sockets=2,cores=2,threads=2 \
-m 2g -nographic \
-bios QEMU_EFI.fd \
-drive file=alpine-arm.sda.qcow2,media=disk,if=virtio \
-net nic -net user,hostfwd=tcp::2222-:22
#-smp 8,sockets=2,cores=2,threads=2
apt install qemu-user-static qemu-system-aarch64 gcc-aarch64-linux-gnu systemd-container make libelf-dev bison
linux-6.1.26.tar.xz
[https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.1.26.tar.xz]
alpine-minirootfs-3.18.0-aarch64.tar.gz
[https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/aarch64/alpine-minirootfs-3.18.0-aarch64.tar.gz]
tar -zJf ./linux-6.1.26.tar.xz && cd linux-6.1.26 && \
make defconfig ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- && \
make -j8 ARCH=arm64 CROSS_COMPILE=aarch64-linux-gnu- && \
cd ..
dd if=/dev/zero of=alpine-base.ext4 bs=4096 count=128K && \
mkfs.ext4 alpine-base.ext4 && \
mount -t ext4 alpine-base.ext4 /mnt && \
tar -xf alpine-minirootfs-3.18.0-aarch64.tar.gz -C /mnt && \
cp /usr/bin/qemu-aarch64-static /mnt/usr/bin/ && \
cp /etc/resolv.conf /mnt/etc/ && \
systemd-nspawn -D /mnt
进入chroot环境,执行:
passwd
apk add alpine-base
exit
做如下修改:
vim /mnt/etc/inittab4
在其中添加如下内容:
ttyAMA0::respawn:/sbin/getty -L ttyAMA0 115200 vt100
安装内核模块:
cd linux-6.1.26/
make modules_install INSTALL_MOD_PATH=/mnt ARCH=arm64
cd ..
卸载文件系统:
umount /mnt
qemu-system-aarch64 \
-M virt \
-cpu cortex-a53 \
-smp 1 \
-m 512M \
-nographic \
-kernel linux-6.1.26/arch/arm64/boot/Image \
-append "rootwait root=/dev/vda rw console=ttyAMA0" \
-netdev user,id=eth0 \
-device virtio-net-device,netdev=eth0 \
-drive file=alpine-base.ext4,if=none,format=raw,id=hd0 \
-device virtio-blk-device,drive=hd0 \
-net nic -net user,hostfwd=tcp::2222-:22