Skip to content

Commit e7dedd2

Browse files
committed
vmupdate: Apply early fix for meminfo-writer SELinux label
The relevant package updates are supposed to fix the label anyway, but before that the template has too little memory to apply the update reliably (most of the time it works, but not always). Apply the label fix early to have more memory when installing updates. Script by Minimalist <suspectindustrie@protonmail.com> QubesOS/qubes-issues#9663
1 parent 4121dee commit e7dedd2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import subprocess
2+
3+
4+
def fix_meminfo_writer_label(os_data, log, **kwargs):
5+
"""
6+
Fix meminfo-writer SELinux label to make memory ballooning work again
7+
8+
# https://github.com/QubesOS/qubes-issues/issues/9663
9+
"""
10+
11+
if os_data["id"] == "fedora":
12+
meminfo_path = "/usr/sbin/meminfo-writer"
13+
expected_label = "qubes_meminfo_writer_exec_t"
14+
15+
label_changed = False
16+
try:
17+
output = subprocess.check_output(
18+
["ls", "-Z", meminfo_path], universal_newlines=True
19+
)
20+
if expected_label not in output:
21+
subprocess.check_call(["chcon", "-t", expected_label, meminfo_path])
22+
log.info(
23+
f"SELinux label for {meminfo_path} changed to '{expected_label}'"
24+
)
25+
label_changed = True
26+
except subprocess.CalledProcessError as e:
27+
log.error(f"Error processing {meminfo_path}: {e}")
28+
29+
if label_changed:
30+
try:
31+
subprocess.check_call(["systemctl", "restart", "qubes-meminfo-writer"])
32+
log.info("qubes-meminfo-writer service restarted")
33+
except subprocess.CalledProcessError as e:
34+
log.error(f"Error restarting qubes-meminfo-writer service: {e}")
35+

0 commit comments

Comments
 (0)