#Disk1
UUID=3f3564db-7df4-40af-d067-33ed2c049b65 /s/disk1 reiserfs auto,noatime,users,exec 0 2
UUID=a4e9a4fc-ef0a-962d-3cf2-a6fdfa35a00b /s/disk2 ext3 auto,noatime,users,exec 0 2
---
File /rw/config/rc.local creates mount points and adds UUIDs
#!/bin/bash
mkdir -m 770 -p /s/disk1
mkdir -m 770 -p /s/disk2
cat /rw/config/fstab >> /etc/fstab
Then in dom0 we have similar script:
#!/bin/bash
qvm-start storage
list=`qvm-block -l | grep -v attached`
awk '
BEGIN{
attach["HDID"]="dummy";
attach["ST320ABC"]="dummy";
}
{
if( ($1 ~ /sd.$/) && ($4 > 0) && attach[$2]){
print "Attaching",$1,$2;
system("qvm-block -a storage " $1);
}
}
' <<< "$list"
qvm-run storage 'sudo mount -a'
----
attach[] contains the names of white-listed devices to be attached to storage - this is 2nd column of table output by qvm-block command.
After devices are assigned to storageVM, auto-mount is executed in the VM.
I have similar script that unmounts and detaches devices from the storageVM.
Currently I have to find suitable place and time to run that script. Suggestions are welcomed.
Tomhet
> If you want to call it automatically at VM startup, you can create qrexec service for that
Cool, this was my first idea, but I was unable to implement it.
Q1: If taking this way I'll need to have opposite (umount & detach) operation at VM shutdown (to avoid refreshing block devices).
Where should I attach (in appVm) the opposite shutdown script (injected by rc.local)?
Q2: If taking the opposite way (dom0-initiated process), how/where should attach/mount script be called from?
- systemd service that depends on some (which) qubes service?
- /etc/init.d/rc.local (not sure if necessary qubes stuff will be already available)
- something else
thanks,
Tomhet
P.S. An alternative could be event listeners for qubes events 'onVmStartComplete'/'beforeVmShutdown', if such exist & I knew python.
Hi Marek,
Mounting as you advised works like charm when doing it via Qubes VM Manager:
"qrexec-client-vm dom0 storage.block.attach" from rc.local of appvm.
But when setting 'storage' VM to auto-start I find such things in the log (and no storage is attached:
----
125626-Jun 12 18:27:11 dom0 qvm-start[2666]: Waiting for VM's qrexec agent......connected
125709-Jun 12 18:27:11 dom0 systemd[1]: Started Start Qubes VM storage.
125774:Jun 12 18:27:12 dom0 storage.block.attach-storage[3328]: *** Running this tool as root is strongly discouraged, this will lead you in permissions problems.
125930:Jun 12 18:27:12 dom0 storage.block.attach-storage[3328]: Retry as unprivileged user.
126015:Jun 12 18:27:12 dom0 storage.block.attach-storage[3328]: ... or use --force-root to continue anyway.
126116-Jun 12 18:27:13 dom0 qvm-start[2668]: Waiting for VM's qrexec agent......connected
126199-Jun 12 18:27:13 dom0 systemd[1]: Started Start Qubes VM sys-whonix.
----
Obviously this is the appvm->dom0 call.
Calling "qrexec-client-vm dom0 storage.block.attach" as "user" does not help.
I'm not sure which "this tool" is (called command) and how can I run it as non-root (or with --force option) during dom0 boot time.
Any ideas how to workaround it?
thanks,
Tom
In Qubes Manager's VM context menu 'Shutdown VM' seems to do equivalent of 'virsh shutdown VM', i.e. power button press. I'd like to catch it, so my shutdown script is executed also via Qubes Manager shutdown.
In /var/lib/qubes/vm-templates/storage/storage.conf I have " <on_poweroff>destroy</on_poweroff>".
This file is re-generated on vm start. Where is value for "on_poweroff" taken from (so I can set it to "shutdown")?
Seems /etc/sysconfig/libvirt-guests is not the right place.
regards,
tom
I spend over 20 hours fighting with systemd (depending on shutdown target, all or some qubes targets, doing PreStart=- but nothing worked) and in desperation I tried nasty hack of replacing /usr/sbin/shutdown with my script, but it was not called when shutting down from qubes manager.
Here's final service:
---------
[Unit]
Description=Detach block devices
After=qubes-dvm.service qubes-mount-dirs.service qubes-qrexec-agent.service
[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=/bin/true
ExecStop=-/usr/local/bin/detach-devices.sh
KillMode=none
TimeoutSec=65
[Install]
WantedBy=multi-user.target
-----------
In detach-devices.sh I put two 'sleep 5' commands around 'umount' to be sure future commands for stopping Samba / NFS will have time to complete and it works.
Great! Much thanks!