added Windows 11 template and OVMF TPM

This commit is contained in:
ich777
2021-09-27 18:49:27 +02:00
parent 729a884a97
commit 0a627d37fa
4 changed files with 78 additions and 10 deletions
+37 -8
View File
@@ -280,15 +280,32 @@
$loader = '';
if (!empty($domain['ovmf'])) {
if (!is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd')) {
// Create a new copy of OVMF VARS for this VM
mkdir('/etc/libvirt/qemu/nvram/', 0777, true);
copy('/usr/share/qemu/ovmf-x64/OVMF_VARS-pure-efi.fd', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd');
}
if ($domain['ovmf'] == 1) {
if (!is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd')) {
// Create a new copy of OVMF VARS for this VM
mkdir('/etc/libvirt/qemu/nvram/', 0777, true);
copy('/usr/share/qemu/ovmf-x64/OVMF_VARS-pure-efi.fd', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd');
}
$loader = "<loader readonly='yes' type='pflash'>/usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi.fd</loader>
<nvram>/etc/libvirt/qemu/nvram/".$uuid."_VARS-pure-efi.fd</nvram>";
}
if ($domain['ovmf'] == 2) {
if (!is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd')) {
// Create a new copy of OVMF VARS for this VM
mkdir('/etc/libvirt/qemu/nvram/', 0777, true);
copy('/usr/share/qemu/ovmf-x64/OVMF_VARS-pure-efi-tpm.fd', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd');
}
$loader = "<loader readonly='yes' type='pflash'>/usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi-tpm.fd</loader>
<nvram>/etc/libvirt/qemu/nvram/".$uuid."_VARS-pure-efi-tpm.fd</nvram>";
$swtpm = "<tpm model='tpm-tis'>
<backend type='emulator' version='2.0'/>
</tpm>";
}
}
$loader = "<loader readonly='yes' type='pflash'>/usr/share/qemu/ovmf-x64/OVMF_CODE-pure-efi.fd</loader>
<nvram>/etc/libvirt/qemu/nvram/".$uuid."_VARS-pure-efi.fd</nvram>";
}
$metadata = '';
if (!empty($template)) {
@@ -792,6 +809,7 @@
<channel type='unix'>
<target type='virtio' name='org.qemu.guest_agent.0'/>
</channel>
$swtpm
$memballoon
</devices>
</domain>";
@@ -1626,6 +1644,9 @@
if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd')) {
unlink('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd');
}
if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd')) {
unlink('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd');
}
$tmp = libvirt_domain_undefine($dom);
return ($tmp) ? $tmp : $this->_set_last_error();
@@ -1667,6 +1688,10 @@
rename('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd_backup');
return true;
}
if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd')) {
rename('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd_backup');
return true;
}
return false;
}
@@ -1677,6 +1702,10 @@
rename('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd_backup', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd');
return true;
}
if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd_backup')) {
rename('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd_backup', '/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd');
return true;
}
return false;
}
@@ -32,6 +32,24 @@
$arrAllTemplates = [
' Windows ' => '', /* Windows Header */
'Windows 11' => [
'form' => 'Custom.form.php',
'icon' => 'windows11.png',
'os' => 'windowstpm',
'overrides' => [
'domain' => [
'ovmf' => 2,
'mem' => 4096 * 1024,
'maxmem' => 4096 * 1024
],
'disk' => [
[
'size' => '64G'
]
]
]
],
'Windows 10' => [
'form' => 'Custom.form.php',
'icon' => 'windows.png',
@@ -1025,6 +1043,16 @@
$strUSBMode = 'usb3-qemu';
}
if (!empty($lv->domain_get_ovmf($res))) {
if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi.fd')) {
$strOVMF = '1';
} else if (is_file('/etc/libvirt/qemu/nvram/'.$uuid.'_VARS-pure-efi-tpm.fd')) {
$strOVMF = '2';
} else {
$strOVMF = '0';
}
}
return [
'template' => $arrTemplateValues,
'domain' => [
@@ -1044,7 +1072,7 @@
'hyperv' => ($lv->domain_get_feature($res, 'hyperv') ? 1 : 0),
'autostart' => ($lv->domain_get_autostart($res) ? 1 : 0),
'state' => $lv->domain_state_translate($dom['state']),
'ovmf' => ($lv->domain_get_ovmf($res) ? 1 : 0),
'ovmf' => $strOVMF,
'usbmode' => $strUSBMode
],
'media' => [