Ok, I have a ugly bruteforce proposal.
Trying a lot of different values for max-ram-below-4g.
- Clone your linux hvm (with your usb pci passthrough and 8G of ram) to a vm named “totest”
In dom0, copy the script “putain1.sh” and run it
(The goal of this script is to create a stubdom rootfs with configurable value for max-ram-below-4g)
putain1.sh :
#!/bin/bash
patch_rootfs(){
filename=${1?Filename is required}
cd ~/
sudo rm -R "patched_$filename"
mkdir "patched_$filename"
cp /usr/libexec/xen/boot/$filename "patched_$filename/$filename.gz"
cp /usr/libexec/xen/boot/$filename "$filename.original"
cd patched_$filename
gunzip $filename.gz
cpio -i -d -H newc --no-absolute-filenames < "$filename"
sudo rm $filename
grep -i "max-ram-below-4g" init && echo "!!ERROR!! The thing is already patched ! EXITING ! " >&2 && exit
patch_string=$(cat <<'EOF'
vm_name=$(xenstore-read "/local/domain/$domid/name")
if [ $(echo "$vm_name" | grep -iEc '^gpu_' ) -eq 1 ]; then
max_ram_below_4g=$(echo "$vm_name" | grep -iEo "_([0-9]*(n[0-9]*)?)._" | cut -d '_' -f 2)
if [[ -z "$max_ram_below_4g" ]];
then
max_ram_below_4g="2G"
fi
max_ram_below_4g=$(echo "$max_ram_below_4g" | sed 's/n/./g')
dm_args=$(echo "$dm_args" | sed -n '1h;2,$H;${g;s/\\(-machine\\nxenfv\\)/\\1,max-ram-below-4g='"$max_ram_below_4g"'/g;p}')
fi
\# $dm_args and $kernel
EOF
)
awk -v r="$patch_string" '{gsub(/^# \$dm_args and \$kernel/,r)}1' init > init2
mv init2 init
chmod +x init
find . -print0 | cpio --null -ov \
--format=newc | gzip -9 > ../$filename.patched
sudo cp ../$filename.patched /usr/libexec/xen/boot/$filename
cd ~/
}
grep -i "max-ram-below-4g" /usr/share/qubes/templates/libvirt/xen.xml && "!!ERROR!! xen.xml is patched ! EXITING ! " && exit
patch_rootfs "qemu-stubdom-linux-rootfs"
patch_rootfs "qemu-stubdom-linux-full-rootfs"
echo "stubdom have been patched."
Then in dom0 copy the file “putain2.sh” and run it.
The goal of this script is to try a lot of different value for max-ram-below-4g.
putain2 :
#!/bin/bash
VM_TO_TEST="totest"
data=$(qvm-prefs "$VM_TO_TEST")
echo "$data" | grep -E "^name" || echo "The VM $VM_TO_TEST doesn't exist. it will crash"
echo "$data" | grep -E "^virt_mode"
echo "$data" | grep -E "^maxmem"
echo "$data" | grep -E "^memory"
for i in "4G" "3.9G" "3.6G" "3.5G" "3.4G" "3.1G" "3G" "2.9G" "2.6G" "2.5G" "2.4G" "2.1G" "2G" "1.9G" "1.6G" "1.5G" "1.4G" "1.1G" "1G" "0.9G" "0.6G" "0.5G" "0.4G"
do
echo "testing $i"
newvm="gpu_""$i""_putain"
newvm=$(echo "$newvm" | sed "s/\./n/g")
echo "trying to create $newvm"
qvm-clone "$VM_TO_TEST" "$newvm"
# Depending on how slow your computer is you could need to increase the value '30' to something bigger
sleep 30 && qvm-shutdown --force "$newvm" 2> /dev/null > /dev/null &
qvm-run --pass-io "$newvm" "uname -a" && echo "SUCCESS! REPORT THIS: $newvm"
qvm-shutdown --force "$newvm"
# Depending on how slow your computer is you could need to increase the value '10' to something bigger
sleep 10
qvm-remove -f "$newvm"
done
I am interested in the output of thoses scripts.
“SUCCESS! REPORT THIS” being the one that interest you the most.
If you find no “SUCCESS! REPORT THIS” in the output of “putain2.sh” you can try to add additional value in the putain2.sh script (like testing every 100mb of ram “4G” “3.9G” “3.8G” “3.7G” … “0.2G” “0.1G” )