Skip to content

Commit 0ea52b5

Browse files
committed
setup qemu running in tmux
Signed-off-by: yifengyou <842056007@qq.com>
1 parent 41a6cce commit 0ea52b5

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

iso/ubuntu-24.04.1-live-server-arm64.iso/build-vm.sh

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ FILE_SERVER_PORT="63336"
1010
VMNAME="kdev-$RANDOM"
1111
ISONAME=$(basename ${ISOURL})
1212
LOGNAME="kdev.log"
13+
JOBS=`nproc`
1314

14-
15-
sudo apt-get install -y qemu-system-arm qemu-efi-aarch64 qemu-utils \
16-
ipxe-qemu
15+
sudo apt-get install -y \
16+
tmux \
17+
qemu-system-arm \
18+
qemu-system-gui \
19+
qemu-efi-aarch64 \
20+
qemu-utils \
21+
ipxe-qemu
1722

1823
fileserver=$(lsof -ti :${FILE_SERVER_PORT})
1924
if [ ! -z "${fileserver}" ]; then
@@ -23,7 +28,7 @@ fi
2328
if [ -f rootfs.qcow2 ]; then
2429
lsof rootfs.qcow2
2530
if [ $? -eq 0 ]; then
26-
echo "rootfs.qcow2 is inuse"
31+
echo "kdev: rootfs.qcow2 is inuse"
2732
exit 1
2833
fi
2934
rm -f rootfs.qcow2
@@ -55,50 +60,59 @@ cleanup() {
5560
kill -9 ${fileserver}
5661
fi
5762
umount -l mnt
58-
5963
}
6064
trap cleanup EXIT
6165

6266
mkdir -p mnt
6367
mount ${ISONAME} mnt
6468
if [ $? -ne 0 ]; then
65-
echo "mount ${ISONAME} failed!"
66-
exit 1
69+
echo "kdev: mount ${ISONAME} failed!"
70+
exit 1
6771
fi
6872

6973
ls -alh mnt/casper
7074
if [ $? -ne 0 ]; then
71-
echo "casper does't exists in ${ISONAME}"
75+
echo "kdev: casper does't exists in ${ISONAME}"
7276
exit 1
7377
fi
7478

75-
set -x
76-
qemu-system-aarch64 \
79+
if [ ! -f mnt/casper/vmlinuz ] ; then
80+
echo "casper/vmlinuz does't exists!"
81+
exit 1
82+
fi
83+
84+
if [ ! -f mnt/casper/initrd ] ; then
85+
echo "casper/initrd does't exists!"
86+
exit 1
87+
fi
88+
89+
tmux new-session -d -s qemu \
90+
"qemu-system-aarch64 \
7791
-name kdev-ubuntu2404 \
7892
-machine virt \
7993
-cpu max \
8094
-drive file=/usr/share/AAVMF/AAVMF_CODE.fd,format=raw,if=pflash \
81-
-smp `nproc` \
95+
-smp ${JOBS} \
8296
-m 4096 \
8397
-cdrom ${ISONAME} \
8498
-device virtio-scsi-pci,id=scsi \
85-
-drive file=`pwd`/rootfs.qcow2,format=qcow2,if=virtio \
99+
-drive file=rootfs.qcow2,format=qcow2,if=virtio \
86100
-boot order=dc \
87-
-kernel `pwd`/mnt/casper/vmlinuz \
88-
-initrd `pwd`/mnt/casper/initrd \
101+
-kernel mnt/casper/vmlinuz \
102+
-initrd mnt/casper/initrd \
89103
-append 'ds=nocloud-net;s=http://192.168.122.1:63336/ cloud-config-url=/dev/null autoinstall earlyprintk console=ttyS0,115200n8' \
90104
-serial file:kdev.log \
91105
-net nic \
92106
-net user,net=192.168.122.0/24,host=192.168.122.1 \
93107
-display curses
94-
# --daemonize
108+
--daemonize"
95109

96110
if [ $? -ne 0 ] ; then
97-
echo "qemu exit with error"
111+
echo "kdev: qemu exit with error"
98112
exit 1
99113
fi
100114

101-
tail -f ${LOGNAME} &
115+
tail -f ${LOGNAME}
102116

103117
while true ; do
104118
ps aux|grep qemu-system-x86_64 |grep -v grep &> /dev/null
@@ -118,7 +132,7 @@ if [ $? -ne 0 ]; then
118132
qemu-img snapshot -l rootfs.qcow2
119133
ls -alh rootfs.qcow2
120134
else
121-
echo "rootfs.qcow2 size too small, skip snapshot"
135+
echo "kdev: rootfs.qcow2 size too small, skip snapshot"
122136
fi
123137
fi
124138

0 commit comments

Comments
 (0)