Skip to content

Commit 6d345b7

Browse files
HoshuChiufslongjin
andauthored
添加了qemu使用VNC作为图像输出的选项 (#222)
* 添加了qemu使用VNC作为图像输出的选项 * 设置vnc端口为5900 --------- Co-authored-by: longjin <[email protected]>
1 parent 2b771e3 commit 6d345b7

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,16 @@ write_diskimage-uefi:
7979
bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
8080
# 不编译,直接启动QEMU
8181
qemu:
82-
sh -c "cd tools && bash run-qemu.sh --bios=legacy && cd .."
82+
sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .."
8383
# 不编译,直接启动QEMU(UEFI)
8484
qemu-uefi:
85-
sh -c "cd tools && bash run-qemu.sh --bios=uefi && cd .."
85+
sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .."
86+
# 不编译,直接启动QEMU,使用VNC Display作为图像输出
87+
qemu-vnc:
88+
sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .."
89+
# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出
90+
qemu-uefi-vnc:
91+
sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .."
8692

8793
# 编译并写入磁盘镜像
8894
build:
@@ -107,6 +113,18 @@ run:
107113
$(MAKE) write_diskimage || exit 1
108114
$(MAKE) qemu
109115

116+
# uefi方式启动,使用VNC Display作为图像输出
117+
run-uefi-vnc:
118+
$(MAKE) all -j $(NPROCS)
119+
$(MAKE) write_diskimage-uefi || exit 1
120+
$(MAKE) qemu-uefi-vnc
121+
122+
# 编译并启动QEMU,使用VNC Display作为图像输出
123+
run-vnc:
124+
$(MAKE) all -j $(NPROCS)
125+
$(MAKE) write_diskimage || exit 1
126+
$(MAKE) qemu-vnc
127+
110128
# 在docker中编译,并启动QEMU
111129
run-docker:
112130
@echo "使用docker构建并运行"

tools/run-qemu.sh

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 进行启动前检查
22
flag_can_run=1
3-
ARGS=`getopt -o p -l bios: -- "$@"`
3+
ARGS=`getopt -o p -l bios:,display: -- "$@"`
44
eval set -- "${ARGS}"
55
echo "$@"
66
allflags=$(qemu-system-x86_64 -cpu help | awk '/flags/ {y=1; getline}; y {print}' | tr ' ' '\n' | grep -Ev "^$" | sed -r 's|^|+|' | tr '\n' ',' | sed -r "s|,$||")
@@ -36,22 +36,39 @@ QEMU_ARGUMENT="-d ${QEMU_DISK_IMAGE} -m ${QEMU_MEMORY} -smp ${QEMU_SMP} -boot or
3636
QEMU_ARGUMENT+="-s -S -cpu ${QEMU_CPU_FEATURES} -rtc ${QEMU_RTC_CLOCK} -serial ${QEMU_SERIAL} -drive ${QEMU_DRIVE} ${QEMU_DEVICES}"
3737

3838
if [ $flag_can_run -eq 1 ]; then
39+
while true;do
3940
case "$1" in
4041
--bios)
41-
case "$2" in
42+
case "$2" in
4243
uefi) #uefi启动新增ovmf.fd固件
43-
if [ ${ARCH} == x86_64 ] ;then
44-
sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
45-
elif [ ${ARCH} == i386 ] ;then
46-
sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
47-
fi
44+
BIOS_TYPE=uefi
4845
;;
4946
legacy)
50-
sudo ${QEMU} ${QEMU_ARGUMENT}
47+
BIOS_TYPE=lagacy
5148
;;
52-
esac
49+
esac;shift 2;;
50+
--display)
51+
case "$2" in
52+
vnc)
53+
QEMU_ARGUMENT+=" -display vnc=:5900"
54+
;;
55+
window)
56+
;;
57+
esac;shift 2;;
58+
*) break
59+
esac
60+
done
61+
62+
if [ ${BIOS_TYPE} == uefi ] ;then
63+
if [ ${ARCH} == x86_64 ] ;then
64+
sudo ${QEMU} -bios arch/x86_64/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
65+
elif [ ${ARCH} == i386 ] ;then
66+
sudo ${QEMU} -bios arch/i386/efi/OVMF-pure-efi.fd ${QEMU_ARGUMENT}
67+
fi
68+
else
69+
sudo ${QEMU} ${QEMU_ARGUMENT}
70+
fi
5371

54-
esac
5572
else
5673
echo "不满足运行条件"
5774
fi

0 commit comments

Comments
 (0)