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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
Qemu
================
## Qemu Setup
apt install qemu-system-aarch64 qemu-efi-aarch64
## Create Image
qemu-img create -f qcow2 my_disk.qcow2 16G
## Shrink img
Normal systems:
qemu-img convert -O qcow2 input.qcow2 output.qcow2
Windoof:
sdelete -z C:
qemu-img convert -O qcow2 input.qcow output.qcow2
## amd64
# Choose whichever fits the need
&& HDAIMG="-hda path/to/maindisk.qcow2" \
&& MACHINE="-m size=4G -smp cores=2" \
&& BIOSDIR="path/to/Bios"
&& BIOSFILE="${BIOSDIR:?}/bios-256k.bin" \
&& FIXMOUSEALIGN="-device usb-ehci,id=usb,bus=pci.0,addr=0x4 -device usb-tablet" \
&& NETWORK="-net nic -net user" \
&& NETWORK="-device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp:127.0.0.1:10022-:22" \
&& HOSTSPECIFICOPTS="--enable-kvm" \
&& HOSTSPECIFICOPTS="-L ${BIOSDIR:?} -bios ${BIOSFILE:?}" \
Start with installation disk
&& CDROM="-cdrom path/to/installer.iso" \
&& qemu-system-x86_64 ${HOSTSPECIFICOPTS:?} ${MACHINE:?} -boot order=dc ${CDROM} ${HDAIMG:?} ${NETWORK:?} ${FIXMOUSEALIGN:?} \
Regular boot
&& qemu-system-x86_64 ${HOSTSPECIFICOPTS:?} ${MACHINE:?} -boot order=c ${HDAIMG:?} ${NETWORK:?} ${FIXMOUSEALIGN:?} \
## aarch64 (not working yet)
MAC='00:de:ad:de:ad:00'
DISK=my_disk.qcow2
cp /usr/share/AAVMF/AAVMF_CODE.fd ./flash1.img
qemu-system-aarch64 -m 1G -cpu cortex-a57 -M virt \
-pflash /usr/share/AAVMF/AAVMF_CODE.fd \
-pflash flash1.img \
-drive if=none,file=${DISK:?},id=hd0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-net-device,netdev=net0,mac=${MAC:?}
qemu-system-aarch64 -M virt -hda my_disk.qcow2 -cdrom debian.iso -boot c -m 1G
qemu-system-aarch64 -M virt -cpu cortex-a57 -m 1G -bios /usr/share/qemu-efi-aarch64/QEMU_EFI.fd -hda my_disk.qcow2 -cdrom ~/images/debian-12.0.0-arm64-DVD/debian-12.0.0-arm64-DVD-1.iso
## Shared host directory via CIFS/SMB
true `# SMB server debian` \
&& hostpath=/path/to/host/dir \
&& sharename=work \
&& apt install --no-install-recommends -y samba
&& printf '[%s]\npath = %s\npublic = no\nwriteable = yes\nguest ok = yes\nforce user = andreas\n' "${sharename:?}" "${hostpath:?}" | $SUDO tee -a /etc/samba/smb.conf >/dev/null \
&& $SUDO /etc/init.d/smbd restart \
&& true
TODO: SMB server windoof
DoesNotWork: "https://serverfault.com/questions/442664/virtualization-linux-kvm-qemu-host-windows-vm-guest-how-to-access-data-drive#comment479177_442678"
true `# SMB client debian` \
&& hostUsername=yourHostUser \
&& smbServer=10.0.2.2 \
&& sharename=work \
&& mountpoint=/mnt/${sharename:?} \
&& guestUid=$(id -u) \
&& guestGid=$(id -g) \
&& true \
&& $SUDO mkdir -p "${mountpoint:?}" \
&& $SUDO apt install --no-install-recommends -y cifs-utils psmisc \
&& $SUDO mount -t cifs -o username=${hostUsername:?},uid=${guestUid:?},gid=${guestGid:?} "//${smbServer:?}/${sharename:?}" "${mountpoint:?}" \
&& true
List smb shares (eg debugging)
smbclient -NL //10.0.2.2
## Shared host directory via NFS
For debian HOST install 'nfs-kernel-system', then:
vim /etc/exports
Example: "/path/to/share 127.0.0.1(rw,no_subtree_check,insecure)"
exportfs -a; /etc/init.d/nfs-kernel-server restart
For windoof HOST install WinNFSd, then:
WinNFSd.exe -addr 127.0.0.1 C:\path\to\share /path/to/share
In GUEST to access it do:
$SUDO apt install -y --no-install-recommends nfs-common
apk add rpcbind && /etc/init.d/rpcbind start
mkdir /mnt/host
$SUDO mount -t nfs -o vers=3 10.0.2.2:/path/to/share /mnt/host
Keep build result inside vm:
mkdir /tmp/build /mnt/host/build
mount --bind /tmp/build /mnt/host/build
## USB pass-through
NOTE: Couldn't yet test any of those commands.
### By physical port
-usb -device usb-host,hostbus=1,hostport=2
### By physical port via hub
-usb -device usb-host,hostbus=1,hostport=2.3
### By device
-usb -device usb-host,vendorid=123,productid=456
## Alpine PostInstall
true \
&& apk add openssh-server \
&& rc-update add sshd \
&& sed -i -E 's;^# *(PermitRootLogin).+$;\1 yes;' /etc/ssh/sshd_config \
&& sed -i -E 's;^# *(http://dl-cdn.alpinelinux.org/alpine/v[^/]+/community)$;\1;' /etc/apk/repositories \
&& mkdir /home/user && chown 1000:1000 /home/user && chmod 755 /home/user \
&& printf 'user:x:1000:1000:user:/home/user:/bin/ash\n' >> /etc/passwd \
&& printf 'user:x:1000:user\n' >> /etc/group \
&& printf 'user:12345\n' | chpasswd \
&& true
## Debian PostInstall
TODO: move this to a better place. Eg: debian/setup.txt or whatever.
true \
&& http_proxy= \
&& https_proxy= \
&& no_proxy=127.0.0.1,10.0.2.* \
&& SUDO= \
&& true \
&& if [ -n "$http_proxy" ]; then true \
&& (echo "Acquire::http::proxy \"${http_proxy}\";"
echo "Acquire::https::proxy \"${https_proxy}\";"
) | $SUDO tee /etc/apt/apt.conf.d/80proxy >/dev/null \
fi \
&& $SUDO apt update \
&& $SUDO apt install -y --no-install-recommends vim openssh-server net-tools curl \
&& $SUDO sed -i -E 's;^GRUB_TIMEOUT=5$;GRUB_TIMEOUT=1;' /etc/default/grub \
&& $SUDO update-grub \
&& true
## Qemu-Monitor in combo with VNC
--monitor stdio
--monitor telnet:127.0.0.1:55555,server,nowait
## Sources
- [apt via proxy](https://computingforgeeks.com/how-to-set-system-proxy-on-debian-linux/?expand_article=1)
- [Qemu ssh from host](https://wiki.qemu.org/Documentation/Networking)
- [shared host dir](https://superuser.com/a/628381/1123359)
- [NFS server for windoof](https://github.com/winnfsd/winnfsd)
- [NFS server for debian](https://vitux.com/debian_nfs_server/)
- [USB pass-through](https://unix.stackexchange.com/a/452946/292722)
- [qemu monitor via telnet](https://unix.stackexchange.com/a/426951/292722)
- [qemu monitor via stdio](https://unix.stackexchange.com/a/57835/292722)
|