-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathws
More file actions
executable file
·108 lines (92 loc) · 2.86 KB
/
Copy pathws
File metadata and controls
executable file
·108 lines (92 loc) · 2.86 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env bash
set -x -e
#SPICE_PORT=5924
guest=windows
mac=fe:dc:ba:99:88:03
tap=tap-${guest}
netid=${guest}nic
#dir="$(dirname $(realpath $0))/"
dir=${HOME}/qemu/$guest/
partition=/dev/sda6
# Check permissions
if [[ "$UID" != "0" ]]; then
echo "Need Root Permissions" 2>/dev/null
exit 1
fi
if [[ "$1" == "stop" ]]; then
# stop virtual RAID disk
mdadm --stop --scan
losetup --detach-all
exit 0
fi
modprobe loop
modprobe linear
if [[ ! -e "$dir" ]]; then
FIRST_RUN=1
mkdir -p $dir
[ -f "${dir}/efi1" ] || dd if=/dev/zero of="${dir}/efi1" bs=1M count=100
[ -f "${dir}/efi2" ] || dd if=/dev/zero of="${dir}/efi2" bs=1M count=1
[ -f "${dir}/ovmf_vars_x64.bin" ] || cp /usr/share/edk2-ovmf/x64/OVMF_VARS.fd "${dir}/ovmf_vars_x64.bin"
chown $SUDO_USER:$SUDO_USER "${dir}/efi1"
chown $SUDO_USER:$SUDO_USER "${dir}/efi2"
chown $SUDO_USER:$SUDO_USER "${dir}/ovmf_vars_x64.bin"
fi
### Disk config ###
# setup virtual RAID disk
efi1lo=$(losetup -f ${dir}/efi1 --show)
efi2lo=$(losetup -f ${dir}/efi2 --show)
mdadm --build --verbose /dev/md0 --chunk=512 --level=linear --raid-devices=3 $efi1lo $partition $efi2lo
sleep 1
chown $SUDO_USER:$SUDO_USER /dev/md0
if [[ -n "$FIRST_RUN" ]]; then
sudo parted --script /dev/md0 -- \
unit s \
mktable gpt \
mkpart primary fat32 2048s 204799s \
mkpart primary ntfs 204800s -2049s \
set 1 boot on \
set 1 esp on \
set 2 msftdata on \
name 1 EFI \
name 2 $guest
sudo mkfs.msdos -F 32 -n EFI /dev/md0p1
sudo mkfs.ntfs -f -Q -L $guest /dev/md0p2
fi
# create network tap device
/etc/qemu-ifup $tap
# export QEMU_AUDIO_DRV=alsa
# export QEMU_ALSA_DAC_DEV=pulse
# export QEMU_ALSA_ADC_DEV=pulse
export SDL_VIDEO_X11_DGAMOUSE=0
qemu-system-x86_64 \
-drive if=pflash,format=raw,readonly=on,file=/usr/share/edk2-ovmf/x64/OVMF_CODE.fd \
-drive if=pflash,format=raw,file=${dir}/ovmf_vars_x64.bin \
-drive file=/dev/md0,media=disk,format=raw,snapshot=off,cache=none \
-pidfile /tmp/qemu-${guest}.pid \
-name $guest \
-enable-kvm \
-cpu host \
-m 2G \
-k fr \
-netdev tap,ifname=$tap,script=no,downscript=no,id=$netid,vhost=on -device virtio-net,netdev=$netid,mac=$mac \
-net nic \
-device virtio-serial \
-usb \
-usbdevice tablet \
-chroot /mnt/Others -runas $SUDO_USER \
"$@"
# -display sdl -alt-grab \
# -vga qxl \
# -chardev spicevmc,id=vdagent,name=vdagent \
# -device virtserialport,chardev=vdagent,name=com.redhat.spice.0 \
# -net user,smb=/mnt/Others \
# -drive file=/dev/md0,media=disk,format=raw,if=virtio,snapshot=off,cache=none \
# -device intel-hda,id=sound0 -device hda-duplex,id=sound0-codec0,bus=sound0.0,cad=0 \
# -vga virtio \
# -chroot ~/qemu/windows -runas $SUDO_USER \
# -netdev user,id=$netid,hostname=windowshost -device virtio-net,netdev=$netid \
# -spice port=${SPICE_PORT},disable-ticketing \
# -daemonize \
rm /tmp/qemu-${guest}.pid
/etc/qemu-ifdown $tap
# exec spicec --title Windows -h 127.0.0.1 -p ${SPICE_PORT}