-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart-vm.sh
More file actions
executable file
·52 lines (43 loc) · 1.48 KB
/
Copy pathstart-vm.sh
File metadata and controls
executable file
·52 lines (43 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# 获取脚本所在目录作为工作目录
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# 内核源码路径
KERNEL_DIR=$DIR/linux
# 磁盘镜像路径
DISK_IMG=$DIR/Arch-Linux-x86_64-basic.qcow2
SHARED_DIR=$DIR/shared_files
# 如果磁盘镜像不存在,则下载
if [ ! -f "$DISK_IMG" ]; then
echo "未找到磁盘镜像,正在下载..."
MIRROR_URL="https://mirror.zju.edu.cn/archlinux/images/latest/Arch-Linux-x86_64-basic.qcow2"
# 使用wget下载(支持断点续传)
if command -v wget &> /dev/null; then
wget -c -O "$DISK_IMG" "$MIRROR_URL"
# 如果wget不可用,尝试使用curl
elif command -v curl &> /dev/null; then
curl -C - -o "$DISK_IMG" "$MIRROR_URL"
else
echo "错误:需要wget或curl来下载镜像"
exit 1
fi
# 检查下载是否成功
if [ ! -f "$DISK_IMG" ]; then
echo "下载失败!请检查网络连接或手动下载镜像"
exit 1
fi
fi
# 确保共享目录存在
mkdir -p "$SHARED_DIR"
# 启动QEMU
qemu-system-x86_64 \
-m 4G \
-smp 4 \
-kernel "${KERNEL_DIR}/arch/x86/boot/bzImage" \
-drive file="${DISK_IMG}",format=qcow2,if=virtio \
-append "root=/dev/vda3 rw console=ttyS0 audit=0" \
-nographic \
-enable-kvm \
-fsdev local,id=fsdev0,path="${SHARED_DIR}",security_model=passthrough \
-device virtio-9p-pci,fsdev=fsdev0,mount_tag=host_share \
-netdev user,id=net0,hostfwd=tcp::2222-:22 \
-device virtio-net-pci,netdev=net0