QEMU虚拟机设置网卡模式为桥接,用xshell远程连接
启动脚本内容:
@echo off
:: 强制UTF-8编码
chcp 65001 >nul
setlocal enabledelayedexpansion:: 配置区域(请修改为实际路径)
set QEMU_PATH="E:\ARM\qemu\qemu-system-aarch64.exe"
set BIOS_FILE="E:\ARM\qemu\QEMU_EFI.fd"
set IMAGE_FILE="E:\ARM\qemu\qilin_arm64.img"
set MEM=8G
set CORES=8
set DISPLAY=sdl
set TAP=qemu-tap:: 检查文件存在性
if not exist %QEMU_PATH% (echo Error: QEMU not found - %QEMU_PATH%pauseexit /b 1
)
if not exist %BIOS_FILE% (echo Error: BIOS file not found - %BIOS_FILE%pauseexit /b 1
)
if not exist %IMAGE_FILE% (echo Error: Image file not found - %IMAGE_FILE%pauseexit /b 1
):: 检查TAP网卡
netsh interface show interface | findstr /i "%TAP%" >nul
if %errorlevel% neq 0 (echo Error: TAP adapter "%TAP%" not foundpauseexit /b 1
):: 显示启动信息(全英文,避免乱码)
echo ==============================================
echo Starting QEMU ARM VM (Bridge Mode)
echo Memory: %MEM% CPU Cores: %CORES%
echo Display: %DISPLAY% TAP Adapter: %TAP%
echo ==============================================
timeout /t 3 /nobreak >nul:: 启动QEMU(参数严格格式)
%QEMU_PATH% -m %MEM% ^-cpu cortex-a72 ^--accel tcg,thread=multi ^-M virt ^-bios %BIOS_FILE% ^-rtc base=localtime ^-display %DISPLAY% ^-device VGA ^-device nec-usb-xhci ^-device usb-tablet ^-device usb-kbd ^-drive if=none,file=%IMAGE_FILE%,id=hd0,format=raw,media=disk ^-device virtio-blk-pci,drive=hd0 ^-netdev tap,id=net0,ifname=%TAP%,script=no,downscript=no ^-device virtio-net-pci,netdev=net0 ^-smp %CORES%,sockets=1,cores=4,threads=2,maxcpus=%CORES%:: 检查结果
if %errorlevel% equ 0 (echo VM closed normally
) else (echo Start failed, ErrorCode: %errorlevel%pause
)endlocal