This is a libvirt hook that will automatically mount your file systems in /mnt/$name This code makes a lot of assumptions, but can be quickly changed to meet your needs.
Running hooks to mount a remote file system after a libvirtd daemon sends in a started
hook doesn't work right away, since sshd
on the VM must
be started, and that doesn't happen as soon as libvirtd sends this hook.
Use the started
hook to launch a script that calls into a C program that immediately forks, and exists the parent. The C program
then calls execlp('qemu-start-wrapped')
;
- The name of your VM, which is passed to your hook from libvirtd has a resolved name. For example, virtual machine with name (domname)
dns
, can be resolved on your machine. This can be accomplished by simply editing your/etc/hosts
file.
To get started, Edit qemu-start-wrapped and replace ryan
and IdentityFile
with correct values
Ensure up SSH key validation on the virtual machine, password login is not supported
git clone https://github.com/rmccullagh/libvirt-automount
cd libvirt-automount
gcc -Wall -Wextra mount-sshfs.c -o mount-sshfs
sudo cp mount-ssfs /etc/libvirt/hooks/
sudo cp qemu /etc/libvirt/hooks
sudo cp qemu-start-wrapped /etc/libvirt/hooks
sudo systemctl restart libvirtd.service
You can tail -f /var/log/syslog
to see the messages written.