Qemu - Installation of Qemu && Virt-manager && Virt-Viewer && Samba
for host Artix/runit and guest Windows 7
Written by Wim Stockman - on 10 December 2023
Introduction
- This is a small explanation how to setup a Qemu VM with bridge connection.
So you are able to talk from Host to Guest and vice versa.
- Setting up an SMB service for sharing files with the Win7
- Make the server discoverable with wsdd2
- and show the possibility of also using the good old NFS file sharing
between linux and Windows7
Install of the required package
- We need to install the packages:
pacman -S \ qemu-full \ libvirt-runit \ libvirt \ virt-manager \ virt-viewer \ samba \ samba-runit \ nfs-utils \ nfs-utils-runit
wsdd2 -> this is an aur package I use yay to install it
Setup the services
add your user to the libvirt group
sudo usermod -aG libvirt
enable the services
ln -s /etc/runit/sv/libvirtd /run/runit/service
ln -s /etc/runit/sv/libvirtlogd /run/runit/service
ln -s /etc/runit/sv/smbd /run/runit/service
Configure Samba
edit the file: /etc/samba/smb.conf
this is the minimum that should be in your smb.conf:
[global]
netbios name = $YOUR_PC_NAME
workgroup = WORKGROUP
[qemu-shared]
path = /home/$USERNAME/qemu-shared
browsable = yes
read only = no
this will create a shared writable folder for user with credentials
So we need to make a credentials.
smbpasswd
Create a password for your user.
So know you can login from windows with your username and the just set password.
Don't forget to reload your samba service
sv restart smbd
Setup bridge network connection
I want go into detail but this is what commands you need for it:
modprobe tun tap && \ ip link add br0 type bridge && \ ip tuntap add dev tap0 mode tap && \ ip link set dev eth0 master br0 && \ ip link set dev tap0 master br0 && \ ip link set dev br0 up && \ ip link set dev eth0 master br0 && \ ip address delete 10.0.0.31/24 dev eth0 && \ ip address add 10.0.0.100/24 dev br0 && \ ip route add default via 10.0.0.1 dev br0
Here we created a bridge connector br0
were tap0 is connected to the bridge and the bridge is connected to our physical network eth0
a good video about it you can find on youtube
or download from here:
Create our VM in Virt-manager.
Create a new VM add what you want but:
There is one thing special.
in the NIC section choose
br0 as bridge adapter and your good to go.
Start your VM from the cli
virsh -c qemu:///system start win7
Connect to your VM from cli
virt-viewer --connect qemu:///system win7
Everything in a script: startmyVM.sh
#!/bin/bash sudo ./qemu-bridge-script.sh sudo sv start smbd && \ sudo sv start virtlogd && \ sudo sv start libvirtd && \ virsh -c qemu:///system start win7 virt-viewer --connect qemu:///system win7 && \ sudo sv stop smbd sudo sv stop virtlogd sudo sv stop libvirtd
# Here is the qemu-bridge-script.sh
#!/bin/bash modprobe tun tap && \ ip link add br0 type bridge && \ ip tuntap add dev tap0 mode tap && \ ip link set dev eth0 master br0 && \ ip link set dev tap0 master br0 && \ ip link set dev br0 up && \ ip link set dev eth0 master br0 && \ ip address delete 10.0.0.31/24 dev eth0 && \ ip address add 10.0.0.100/24 dev br0 && \ ip route add default via 10.0.0.1 dev br0
I like to keep all the services just started when I need them.
That's why I stop them on exit of my Virt-Viewer.
In runit if you don't want to start some services on startup
you need to create a file down.
touch /run/runit/service/$yourservice/down
So we do this for Samba,virtlogd and libvirt
touch /run/runit/service/smbd/down
touch /run/runit/service/virtlogd/down
touch /run/runit/service/libvirtd/down
Setup of Wsdd2 Discovery/Name Service Daemon
if you want to be able to discover your host computer on the windows machine you also need to enabel wsdd2
Since this is an AURpackage we need to make our own runit file.
Create a directory wsdd2 in the folder:
sudo mkdir /etc/runit/sv/wsdd2
- create a file: "run" in the wsdd2 directory we just created
- Add this content:
#!/bin/sh [ ! -d /run/wsdd2 ] && mkdir -p /run/wsdd2 exec wsdd2
- create inside the wsdd2 directory 2 more directories
mkdir log
mkdir supervise
- link our service
ln -s /etc/runit/sv/wsdd2 /run/runit/service
- Do no start it on bootup
touch /run/runit/service/wsdd2/down
- To start it when needed
sv start wsdd2