libvirt-automount
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.
Problem
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.
Solution
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');
Assumptions
- 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/hostsfile.
Quick start
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-automountcd libvirt-automountgcc -Wall -Wextra mount-sshfs.c -o mount-sshfssudo cp mount-ssfs /etc/libvirt/hooks/sudo cp qemu /etc/libvirt/hookssudo cp qemu-start-wrapped /etc/libvirt/hookssudo systemctl restart libvirtd.service
You can tail -f /var/log/syslog to see the messages written.