@@ -10,10 +10,15 @@ FILE_SERVER_PORT="63336"
10
10
VMNAME=" kdev-$RANDOM "
11
11
ISONAME=$( basename ${ISOURL} )
12
12
LOGNAME=" kdev.log"
13
+ JOBS=` nproc`
13
14
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
17
22
18
23
fileserver=$( lsof -ti :${FILE_SERVER_PORT} )
19
24
if [ ! -z " ${fileserver} " ]; then
23
28
if [ -f rootfs.qcow2 ]; then
24
29
lsof rootfs.qcow2
25
30
if [ $? -eq 0 ]; then
26
- echo " rootfs.qcow2 is inuse"
31
+ echo " kdev: rootfs.qcow2 is inuse"
27
32
exit 1
28
33
fi
29
34
rm -f rootfs.qcow2
@@ -55,50 +60,59 @@ cleanup() {
55
60
kill -9 ${fileserver}
56
61
fi
57
62
umount -l mnt
58
-
59
63
}
60
64
trap cleanup EXIT
61
65
62
66
mkdir -p mnt
63
67
mount ${ISONAME} mnt
64
68
if [ $? -ne 0 ]; then
65
- echo " mount ${ISONAME} failed!"
66
- exit 1
69
+ echo " kdev: mount ${ISONAME} failed!"
70
+ exit 1
67
71
fi
68
72
69
73
ls -alh mnt/casper
70
74
if [ $? -ne 0 ]; then
71
- echo " casper does't exists in ${ISONAME} "
75
+ echo " kdev: casper does't exists in ${ISONAME} "
72
76
exit 1
73
77
fi
74
78
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 \
77
91
-name kdev-ubuntu2404 \
78
92
-machine virt \
79
93
-cpu max \
80
94
-drive file=/usr/share/AAVMF/AAVMF_CODE.fd,format=raw,if=pflash \
81
- -smp ` nproc ` \
95
+ -smp ${JOBS} \
82
96
-m 4096 \
83
97
-cdrom ${ISONAME} \
84
98
-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 \
86
100
-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 \
89
103
-append 'ds=nocloud-net;s=http://192.168.122.1:63336/ cloud-config-url=/dev/null autoinstall earlyprintk console=ttyS0,115200n8' \
90
104
-serial file:kdev.log \
91
105
-net nic \
92
106
-net user,net=192.168.122.0/24,host=192.168.122.1 \
93
107
-display curses
94
- # --daemonize
108
+ --daemonize"
95
109
96
110
if [ $? -ne 0 ] ; then
97
- echo " qemu exit with error"
111
+ echo " kdev: qemu exit with error"
98
112
exit 1
99
113
fi
100
114
101
- tail -f ${LOGNAME} &
115
+ tail -f ${LOGNAME}
102
116
103
117
while true ; do
104
118
ps aux| grep qemu-system-x86_64 | grep -v grep & > /dev/null
@@ -118,7 +132,7 @@ if [ $? -ne 0 ]; then
118
132
qemu-img snapshot -l rootfs.qcow2
119
133
ls -alh rootfs.qcow2
120
134
else
121
- echo " rootfs.qcow2 size too small, skip snapshot"
135
+ echo " kdev: rootfs.qcow2 size too small, skip snapshot"
122
136
fi
123
137
fi
124
138
0 commit comments