]> git.proxmox.com Git - pve-manager.git/blame - PVE/CLI/pve7to8.pm
pve7to8: add check for systemd-boot presence where needed
[pve-manager.git] / PVE / CLI / pve7to8.pm
CommitLineData
a98193c2
TL
1package PVE::CLI::pve7to8;
2
3use strict;
4use warnings;
5
eed1e93e
TL
6use Cwd ();
7
a98193c2
TL
8use PVE::API2::APT;
9use PVE::API2::Ceph;
10use PVE::API2::LXC;
11use PVE::API2::Qemu;
12use PVE::API2::Certificates;
13use PVE::API2::Cluster::Ceph;
14
15use PVE::AccessControl;
16use PVE::Ceph::Tools;
17use PVE::Cluster;
18use PVE::Corosync;
19use PVE::INotify;
20use PVE::JSONSchema;
21use PVE::NodeConfig;
22use PVE::RPCEnvironment;
23use PVE::Storage;
24use PVE::Storage::Plugin;
eed1e93e 25use PVE::Tools qw(run_command split_list file_get_contents);
a98193c2
TL
26use PVE::QemuConfig;
27use PVE::QemuServer;
28use PVE::VZDump::Common;
29use PVE::LXC;
30use PVE::LXC::Config;
31use PVE::LXC::Setup;
32
33use Term::ANSIColor;
34
35use PVE::CLIHandler;
36
37use base qw(PVE::CLIHandler);
38
39my $nodename = PVE::INotify::nodename();
40
eed1e93e
TL
41my $upgraded = 0; # set in check_pve_packages
42
a98193c2
TL
43sub setup_environment {
44 PVE::RPCEnvironment->setup_default_cli_env();
45}
46
47my ($min_pve_major, $min_pve_minor, $min_pve_pkgrel) = (7, 4, 1);
48
49my $ceph_release2code = {
50 '12' => 'Luminous',
51 '13' => 'Mimic',
52 '14' => 'Nautilus',
53 '15' => 'Octopus',
54 '16' => 'Pacific',
55 '17' => 'Quincy',
56 '18' => 'Reef',
57};
58my $ceph_supported_release = 17; # the version we support for upgrading (i.e., available on both)
59my $ceph_supported_code_name = $ceph_release2code->{"$ceph_supported_release"}
60 or die "inconsistent source code, could not map expected ceph version to code name!";
61
62my $forced_legacy_cgroup = 0;
63
64my $counters = {
65 pass => 0,
66 skip => 0,
67 warn => 0,
68 fail => 0,
69};
70
71my $log_line = sub {
72 my ($level, $line) = @_;
73
74 $counters->{$level}++ if defined($level) && defined($counters->{$level});
75
76 print uc($level), ': ' if defined($level);
77 print "$line\n";
78};
79
80sub log_pass {
81 print color('green');
82 $log_line->('pass', @_);
83 print color('reset');
84}
85
86sub log_info {
87 $log_line->('info', @_);
88}
89sub log_skip {
90 $log_line->('skip', @_);
91}
92sub log_warn {
93 print color('yellow');
94 $log_line->('warn', @_);
95 print color('reset');
96}
97sub log_fail {
98 print color('bold red');
99 $log_line->('fail', @_);
100 print color('reset');
101}
102
103my $print_header_first = 1;
104sub print_header {
105 my ($h) = @_;
106 print "\n" if !$print_header_first;
107 print "= $h =\n\n";
108 $print_header_first = 0;
109}
110
111my $get_systemd_unit_state = sub {
112 my ($unit, $surpress_stderr) = @_;
113
114 my $state;
115 my $filter_output = sub {
116 $state = shift;
117 chomp $state;
118 };
119
120 my %extra = (outfunc => $filter_output, noerr => 1);
121 $extra{errfunc} = sub { } if $surpress_stderr;
122
123 eval {
124 run_command(['systemctl', 'is-enabled', "$unit"], %extra);
125 return if !defined($state);
126 run_command(['systemctl', 'is-active', "$unit"], %extra);
127 };
128
129 return $state // 'unknown';
130};
131my $log_systemd_unit_state = sub {
132 my ($unit, $no_fail_on_inactive) = @_;
133
134 my $log_method = \&log_warn;
135
136 my $state = $get_systemd_unit_state->($unit);
137 if ($state eq 'active') {
138 $log_method = \&log_pass;
139 } elsif ($state eq 'inactive') {
140 $log_method = $no_fail_on_inactive ? \&log_warn : \&log_fail;
141 } elsif ($state eq 'failed') {
142 $log_method = \&log_fail;
143 }
144
145 $log_method->("systemd unit '$unit' is in state '$state'");
146};
147
148my $versions;
149my $get_pkg = sub {
150 my ($pkg) = @_;
151
152 $versions = eval { PVE::API2::APT->versions({ node => $nodename }) } if !defined($versions);
153
154 if (!defined($versions)) {
155 my $msg = "unable to retrieve package version information";
156 $msg .= "- $@" if $@;
157 log_fail("$msg");
158 return undef;
159 }
160
161 my $pkgs = [ grep { $_->{Package} eq $pkg } @$versions ];
162 if (!defined $pkgs || $pkgs == 0) {
163 log_fail("unable to determine installed $pkg version.");
164 return undef;
165 } else {
166 return $pkgs->[0];
167 }
168};
169
170sub check_pve_packages {
171 print_header("CHECKING VERSION INFORMATION FOR PVE PACKAGES");
172
173 print "Checking for package updates..\n";
174 my $updates = eval { PVE::API2::APT->list_updates({ node => $nodename }); };
175 if (!defined($updates)) {
176 log_warn("$@") if $@;
177 log_fail("unable to retrieve list of package updates!");
178 } elsif (@$updates > 0) {
179 my $pkgs = join(', ', map { $_->{Package} } @$updates);
180 log_warn("updates for the following packages are available:\n $pkgs");
181 } else {
eed1e93e 182 log_pass("all packages up-to-date");
a98193c2
TL
183 }
184
185 print "\nChecking proxmox-ve package version..\n";
186 if (defined(my $proxmox_ve = $get_pkg->('proxmox-ve'))) {
45d1707c 187 # TODO: update to native version for pve8to9
a98193c2
TL
188 my $min_pve_ver = "$min_pve_major.$min_pve_minor-$min_pve_pkgrel";
189
45d1707c 190 my ($maj, $min, $pkgrel) = $proxmox_ve->{OldVersion} =~ m/^(\d+)\.(\d+)[.-](\d+)/;
a98193c2 191
a98193c2
TL
192 if ($maj > $min_pve_major) {
193 log_pass("already upgraded to Proxmox VE " . ($min_pve_major + 1));
194 $upgraded = 1;
195 } elsif ($maj >= $min_pve_major && $min >= $min_pve_minor && $pkgrel >= $min_pve_pkgrel) {
196 log_pass("proxmox-ve package has version >= $min_pve_ver");
197 } else {
198 log_fail("proxmox-ve package is too old, please upgrade to >= $min_pve_ver!");
199 }
200
201 my ($krunning, $kinstalled) = (qr/6\.(?:2|5)/, 'pve-kernel-6.2');
202 if (!$upgraded) {
203 # we got a few that avoided 5.15 in cluster with mixed CPUs, so allow older too
204 ($krunning, $kinstalled) = (qr/(?:5\.(?:13|15)|6\.2)/, 'pve-kernel-5.15');
205 }
206
207 print "\nChecking running kernel version..\n";
208 my $kernel_ver = $proxmox_ve->{RunningKernel};
209 if (!defined($kernel_ver)) {
210 log_fail("unable to determine running kernel version.");
211 } elsif ($kernel_ver =~ /^$krunning/) {
212 if ($upgraded) {
213 log_pass("running new kernel '$kernel_ver' after upgrade.");
214 } else {
215 log_pass("running kernel '$kernel_ver' is considered suitable for upgrade.");
216 }
217 } elsif ($get_pkg->($kinstalled)) {
218 # with 6.2 kernel being available in both we might want to fine-tune the check?
219 log_warn("a suitable kernel ($kinstalled) is intalled, but an unsuitable ($kernel_ver) is booted, missing reboot?!");
220 } else {
221 log_warn("unexpected running and installed kernel '$kernel_ver'.");
222 }
223
224 if ($upgraded && $kernel_ver =~ /^$krunning/) {
225 my $outdated_kernel_meta_pkgs = [];
226 for my $kernel_meta_version ('5.4', '5.11', '5.13', '5.15') {
227 my $pkg = "pve-kernel-${kernel_meta_version}";
228 if ($get_pkg->($pkg)) {
229 push @$outdated_kernel_meta_pkgs, $pkg;
230 }
231 }
232 if (scalar(@$outdated_kernel_meta_pkgs) > 0) {
233 log_info(
234 "Found outdated kernel meta-packages, taking up extra space on boot partitions.\n"
235 ." After a successful upgrade, you can remove them using this command:\n"
236 ." apt remove " . join(' ', $outdated_kernel_meta_pkgs->@*)
237 );
238 }
239 }
240 } else {
241 log_fail("proxmox-ve package not found!");
242 }
243}
244
245
246sub check_storage_health {
247 print_header("CHECKING CONFIGURED STORAGES");
248 my $cfg = PVE::Storage::config();
249
250 my $ctime = time();
251
252 my $info = PVE::Storage::storage_info($cfg);
253
254 foreach my $storeid (sort keys %$info) {
255 my $d = $info->{$storeid};
256 if ($d->{enabled}) {
257 if ($d->{active}) {
258 log_pass("storage '$storeid' enabled and active.");
259 } else {
260 log_warn("storage '$storeid' enabled but not active!");
261 }
262 } else {
263 log_skip("storage '$storeid' disabled.");
264 }
265 }
266
267 check_storage_content();
eed1e93e
TL
268 eval { check_storage_content_dirs() };
269 log_fail("failed to check storage content directories - $@") if $@;
a98193c2
TL
270}
271
272sub check_cluster_corosync {
273 print_header("CHECKING CLUSTER HEALTH/SETTINGS");
274
275 if (!PVE::Corosync::check_conf_exists(1)) {
276 log_skip("standalone node.");
277 return;
278 }
279
280 $log_systemd_unit_state->('pve-cluster.service');
281 $log_systemd_unit_state->('corosync.service');
282
283 if (PVE::Cluster::check_cfs_quorum(1)) {
284 log_pass("Cluster Filesystem is quorate.");
285 } else {
286 log_fail("Cluster Filesystem readonly, lost quorum?!");
287 }
288
289 my $conf = PVE::Cluster::cfs_read_file('corosync.conf');
290 my $conf_nodelist = PVE::Corosync::nodelist($conf);
291 my $node_votes = 0;
292
293 print "\nAnalzying quorum settings and state..\n";
294 if (!defined($conf_nodelist)) {
295 log_fail("unable to retrieve nodelist from corosync.conf");
296 } else {
297 if (grep { $conf_nodelist->{$_}->{quorum_votes} != 1 } keys %$conf_nodelist) {
298 log_warn("non-default quorum_votes distribution detected!");
299 }
300 map { $node_votes += $conf_nodelist->{$_}->{quorum_votes} // 0 } keys %$conf_nodelist;
301 }
302
303 my ($expected_votes, $total_votes);
304 my $filter_output = sub {
305 my $line = shift;
306 ($expected_votes) = $line =~ /^Expected votes:\s*(\d+)\s*$/
307 if !defined($expected_votes);
308 ($total_votes) = $line =~ /^Total votes:\s*(\d+)\s*$/
309 if !defined($total_votes);
310 };
311 eval {
312 run_command(['corosync-quorumtool', '-s'], outfunc => $filter_output, noerr => 1);
313 };
314
315 if (!defined($expected_votes)) {
316 log_fail("unable to get expected number of votes, assuming 0.");
317 $expected_votes = 0;
318 }
319 if (!defined($total_votes)) {
320 log_fail("unable to get expected number of votes, assuming 0.");
321 $total_votes = 0;
322 }
323
324 my $cfs_nodelist = PVE::Cluster::get_clinfo()->{nodelist};
325 my $offline_nodes = grep { $cfs_nodelist->{$_}->{online} != 1 } keys %$cfs_nodelist;
326 if ($offline_nodes > 0) {
327 log_fail("$offline_nodes nodes are offline!");
328 }
329
330 my $qdevice_votes = 0;
331 if (my $qdevice_setup = $conf->{main}->{quorum}->{device}) {
332 $qdevice_votes = $qdevice_setup->{votes} // 1;
333 }
334
335 log_info("configured votes - nodes: $node_votes");
336 log_info("configured votes - qdevice: $qdevice_votes");
337 log_info("current expected votes: $expected_votes");
338 log_info("current total votes: $total_votes");
339
340 log_warn("expected votes set to non-standard value '$expected_votes'.")
341 if $expected_votes != $node_votes + $qdevice_votes;
342 log_warn("total votes < expected votes: $total_votes/$expected_votes!")
343 if $total_votes < $expected_votes;
344
345 my $conf_nodelist_count = scalar(keys %$conf_nodelist);
346 my $cfs_nodelist_count = scalar(keys %$cfs_nodelist);
347 log_warn("cluster consists of less than three quorum-providing nodes!")
348 if $conf_nodelist_count < 3 && $conf_nodelist_count + $qdevice_votes < 3;
349
350 log_fail("corosync.conf ($conf_nodelist_count) and pmxcfs ($cfs_nodelist_count) don't agree about size of nodelist.")
351 if $conf_nodelist_count != $cfs_nodelist_count;
352
353 print "\nChecking nodelist entries..\n";
354 my $nodelist_pass = 1;
355 for my $cs_node (sort keys %$conf_nodelist) {
356 my $entry = $conf_nodelist->{$cs_node};
357 if (!defined($entry->{name})) {
358 $nodelist_pass = 0;
359 log_fail("$cs_node: no name entry in corosync.conf.");
360 }
361 if (!defined($entry->{nodeid})) {
362 $nodelist_pass = 0;
363 log_fail("$cs_node: no nodeid configured in corosync.conf.");
364 }
365 my $gotLinks = 0;
366 for my $link (0..7) {
367 $gotLinks++ if defined($entry->{"ring${link}_addr"});
368 }
369 if ($gotLinks <= 0) {
370 $nodelist_pass = 0;
371 log_fail("$cs_node: no ringX_addr (0 <= X <= 7) link defined in corosync.conf.");
372 }
373
374 my $verify_ring_ip = sub {
375 my $key = shift;
376 if (defined(my $ring = $entry->{$key})) {
377 my ($resolved_ip, undef) = PVE::Corosync::resolve_hostname_like_corosync($ring, $conf);
378 if (defined($resolved_ip)) {
379 if ($resolved_ip ne $ring) {
380 $nodelist_pass = 0;
381 log_warn(
382 "$cs_node: $key '$ring' resolves to '$resolved_ip'.\n"
383 ." Consider replacing it with the currently resolved IP address."
384 );
385 }
386 } else {
387 $nodelist_pass = 0;
388 log_fail(
389 "$cs_node: unable to resolve $key '$ring' to an IP address according to Corosync's"
390 ." resolve strategy - cluster will potentially fail with Corosync 3.x/kronosnet!"
391 );
392 }
393 }
394 };
395 for my $link (0..7) {
396 $verify_ring_ip->("ring${link}_addr");
397 }
398 }
399 log_pass("nodelist settings OK") if $nodelist_pass;
400
401 print "\nChecking totem settings..\n";
402 my $totem = $conf->{main}->{totem};
403 my $totem_pass = 1;
404
405 my $transport = $totem->{transport};
406 if (defined($transport)) {
407 if ($transport ne 'knet') {
408 $totem_pass = 0;
409 log_fail("Corosync transport explicitly set to '$transport' instead of implicit default!");
410 }
411 }
412
413 # TODO: are those values still up-to-date?
414 if ((!defined($totem->{secauth}) || $totem->{secauth} ne 'on') && (!defined($totem->{crypto_cipher}) || $totem->{crypto_cipher} eq 'none')) {
415 $totem_pass = 0;
416 log_fail("Corosync authentication/encryption is not explicitly enabled (secauth / crypto_cipher / crypto_hash)!");
417 } elsif (defined($totem->{crypto_cipher}) && $totem->{crypto_cipher} eq '3des') {
418 $totem_pass = 0;
419 log_fail("Corosync encryption cipher set to '3des', no longer supported in Corosync 3.x!"); # FIXME: can be removed?
420 }
421
422 log_pass("totem settings OK") if $totem_pass;
423 print "\n";
424 log_info("run 'pvecm status' to get detailed cluster status..");
425
426 if (defined(my $corosync = $get_pkg->('corosync'))) {
427 if ($corosync->{OldVersion} =~ m/^2\./) {
428 log_fail("\ncorosync 2.x installed, cluster-wide upgrade to 3.x needed!");
429 } elsif ($corosync->{OldVersion} !~ m/^3\./) {
430 log_fail("\nunexpected corosync version installed: $corosync->{OldVersion}!");
431 }
432 }
433}
434
435sub check_ceph {
436 print_header("CHECKING HYPER-CONVERGED CEPH STATUS");
437
438 if (PVE::Ceph::Tools::check_ceph_inited(1)) {
439 log_info("hyper-converged ceph setup detected!");
440 } else {
441 log_skip("no hyper-converged ceph setup detected!");
442 return;
443 }
444
445 log_info("getting Ceph status/health information..");
446 my $ceph_status = eval { PVE::API2::Ceph->status({ node => $nodename }); };
447 my $noout = eval { PVE::API2::Cluster::Ceph->get_flag({ flag => "noout" }); };
448 if ($@) {
449 log_fail("failed to get 'noout' flag status - $@");
450 }
451
452 my $noout_wanted = 1;
453
454 if (!$ceph_status || !$ceph_status->{health}) {
455 log_fail("unable to determine Ceph status!");
456 } else {
457 my $ceph_health = $ceph_status->{health}->{status};
458 if (!$ceph_health) {
459 log_fail("unable to determine Ceph health!");
460 } elsif ($ceph_health eq 'HEALTH_OK') {
461 log_pass("Ceph health reported as 'HEALTH_OK'.");
462 } elsif ($ceph_health eq 'HEALTH_WARN' && $noout && (keys %{$ceph_status->{health}->{checks}} == 1)) {
463 log_pass("Ceph health reported as 'HEALTH_WARN' with a single failing check and 'noout' flag set.");
464 } else {
465 log_warn(
466 "Ceph health reported as '$ceph_health'.\n Use the PVE dashboard or 'ceph -s'"
467 ." to determine the specific issues and try to resolve them."
468 );
469 }
470 }
471
472 # TODO: check OSD min-required version, if to low it breaks stuff!
473
eed1e93e 474 log_info("checking local Ceph version..");
a98193c2
TL
475 if (my $release = eval { PVE::Ceph::Tools::get_local_version(1) }) {
476 my $code_name = $ceph_release2code->{"$release"} || 'unknown';
477 if ($release == $ceph_supported_release) {
478 log_pass("found expected Ceph $ceph_supported_release $ceph_supported_code_name release.")
479 } elsif ($release > $ceph_supported_release) {
480 log_warn(
481 "found newer Ceph release $release $code_name as the expected $ceph_supported_release"
482 ." $ceph_supported_code_name, installed third party repos?!"
483 )
484 } else {
485 log_fail(
486 "Hyper-converged Ceph $release $code_name is to old for upgrade!\n"
487 ." Upgrade Ceph first to $ceph_supported_code_name following our how-to:\n"
488 ." <https://pve.proxmox.com/wiki/Category:Ceph_Upgrade>"
489 );
490 }
491 } else {
492 log_fail("unable to determine local Ceph version!");
493 }
494
495 log_info("getting Ceph daemon versions..");
496 my $ceph_versions = eval { PVE::Ceph::Tools::get_cluster_versions(undef, 1); };
497 if (!$ceph_versions) {
498 log_fail("unable to determine Ceph daemon versions!");
499 } else {
500 my $services = [
501 { 'key' => 'mon', 'name' => 'monitor' },
502 { 'key' => 'mgr', 'name' => 'manager' },
503 { 'key' => 'mds', 'name' => 'MDS' },
504 { 'key' => 'osd', 'name' => 'OSD' },
505 ];
506
eed1e93e
TL
507 my $ceph_versions_simple = {};
508 my $ceph_versions_commits = {};
509 for my $type (keys %$ceph_versions) {
510 for my $full_version (keys $ceph_versions->{$type}->%*) {
511 if ($full_version =~ m/^(.*) \((.*)\).*\(.*\)$/) {
512 # String is in the form of
513 # ceph version 17.2.6 (810db68029296377607028a6c6da1ec06f5a2b27) quincy (stable)
514 # only check the first part, e.g. 'ceph version 17.2.6', the commit hash can
515 # be different
516 $ceph_versions_simple->{$type}->{$1} = 1;
517 $ceph_versions_commits->{$type}->{$2} = 1;
518 }
519 }
520 }
521
a98193c2
TL
522 foreach my $service (@$services) {
523 my ($name, $key) = $service->@{'name', 'key'};
eed1e93e 524 if (my $service_versions = $ceph_versions_simple->{$key}) {
a98193c2
TL
525 if (keys %$service_versions == 0) {
526 log_skip("no running instances detected for daemon type $name.");
527 } elsif (keys %$service_versions == 1) {
528 log_pass("single running version detected for daemon type $name.");
529 } else {
530 log_warn("multiple running versions detected for daemon type $name!");
531 }
532 } else {
533 log_skip("unable to determine versions of running Ceph $name instances.");
534 }
eed1e93e
TL
535 my $service_commits = $ceph_versions_commits->{$key};
536 log_info("different builds of same version detected for an $name. Are you in the middle of the upgrade?")
537 if $service_commits && keys %$service_commits > 1;
a98193c2
TL
538 }
539
540 my $overall_versions = $ceph_versions->{overall};
541 if (!$overall_versions) {
542 log_warn("unable to determine overall Ceph daemon versions!");
543 } elsif (keys %$overall_versions == 1) {
544 log_pass("single running overall version detected for all Ceph daemon types.");
1f8f0272 545 # TODO: needs to be set to 1 in the stable branch each time! - find better solution?
a98193c2 546 $noout_wanted = 0; # off post-upgrade, on pre-upgrade
eed1e93e 547 } elsif (keys $ceph_versions_simple->{overall}->%* != 1) {
a98193c2
TL
548 log_warn("overall version mismatch detected, check 'ceph versions' output for details!");
549 }
550 }
551
552 if ($noout) {
553 if ($noout_wanted) {
554 log_pass("'noout' flag set to prevent rebalancing during cluster-wide upgrades.");
555 } else {
556 log_warn("'noout' flag set, Ceph cluster upgrade seems finished.");
557 }
558 } elsif ($noout_wanted) {
559 log_warn("'noout' flag not set - recommended to prevent rebalancing during upgrades.");
560 }
561
562 log_info("checking Ceph config..");
563 my $conf = PVE::Cluster::cfs_read_file('ceph.conf');
564 if (%$conf) {
565 my $global = $conf->{global};
566
567 my $global_monhost = $global->{mon_host} // $global->{"mon host"} // $global->{"mon-host"};
568 if (!defined($global_monhost)) {
569 log_warn(
570 "No 'mon_host' entry found in ceph config.\n It's recommended to add mon_host with"
571 ." all monitor addresses (without ports) to the global section."
572 );
573 }
574
575 my $ipv6 = $global->{ms_bind_ipv6} // $global->{"ms bind ipv6"} // $global->{"ms-bind-ipv6"};
576 if ($ipv6) {
577 my $ipv4 = $global->{ms_bind_ipv4} // $global->{"ms bind ipv4"} // $global->{"ms-bind-ipv4"};
578 if ($ipv6 eq 'true' && (!defined($ipv4) || $ipv4 ne 'false')) {
579 log_warn(
580 "'ms_bind_ipv6' is enabled but 'ms_bind_ipv4' is not disabled.\n Make sure to"
581 ." disable 'ms_bind_ipv4' for ipv6 only clusters, or add an ipv4 network to public/cluster network."
582 );
583 }
584 }
585
586 if (defined($global->{keyring})) {
587 log_warn(
588 "[global] config section contains 'keyring' option, which will prevent services from"
589 ." starting with Nautilus.\n Move 'keyring' option to [client] section instead."
590 );
591 }
592
593 } else {
594 log_warn("Empty ceph config found");
595 }
596
597 my $local_ceph_ver = PVE::Ceph::Tools::get_local_version(1);
598 if (defined($local_ceph_ver)) {
599 if ($local_ceph_ver <= 14) {
600 log_fail("local Ceph version too low, at least Octopus required..");
601 }
602 } else {
603 log_fail("unable to determine local Ceph version.");
604 }
605}
606
607sub check_backup_retention_settings {
608 log_info("Checking backup retention settings..");
609
610 my $pass = 1;
611
a98193c2
TL
612 my $maxfiles_msg = "parameter 'maxfiles' is deprecated with PVE 7.x and will be removed in a " .
613 "future version, use 'prune-backups' instead.";
614
615 eval {
616 my $confdesc = PVE::VZDump::Common::get_confdesc();
daf74a20
FE
617 # vzdump.conf by itself doesn't need to honor any 'requires'
618 delete $confdesc->{$_}->{requires} for keys $confdesc->%*;
a98193c2
TL
619
620 my $fn = "/etc/vzdump.conf";
621 my $raw = PVE::Tools::file_get_contents($fn);
622
623 my $conf_schema = { type => 'object', properties => $confdesc, };
624 my $param = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
625
626 if (defined($param->{maxfiles})) {
627 $pass = 0;
628 log_warn("$fn - $maxfiles_msg");
629 }
a98193c2
TL
630 };
631 if (my $err = $@) {
632 $pass = 0;
633 log_warn("unable to parse node's VZDump configuration - $err");
634 }
635
636 my $storage_cfg = PVE::Storage::config();
637
638 for my $storeid (keys $storage_cfg->{ids}->%*) {
639 my $scfg = $storage_cfg->{ids}->{$storeid};
640
641 if (defined($scfg->{maxfiles})) {
642 $pass = 0;
643 log_warn("storage '$storeid' - $maxfiles_msg");
644 }
a98193c2
TL
645 }
646
647 eval {
648 my $vzdump_cron = PVE::Cluster::cfs_read_file('vzdump.cron');
649
650 # only warn once, there might be many jobs...
651 if (scalar(grep { defined($_->{maxfiles}) } $vzdump_cron->{jobs}->@*)) {
652 $pass = 0;
653 log_warn("/etc/pve/vzdump.cron - $maxfiles_msg");
654 }
655 };
656 if (my $err = $@) {
657 $pass = 0;
658 log_warn("unable to parse node's VZDump configuration - $err");
659 }
660
eed1e93e 661 log_pass("no backup retention problems found.") if $pass;
a98193c2
TL
662}
663
664sub check_cifs_credential_location {
665 log_info("checking CIFS credential location..");
666
667 my $regex = qr/^(.*)\.cred$/;
668
669 my $found;
670
671 PVE::Tools::dir_glob_foreach('/etc/pve/priv/', $regex, sub {
672 my ($filename) = @_;
673
674 my ($basename) = $filename =~ $regex;
675
676 log_warn(
677 "CIFS credentials '/etc/pve/priv/$filename' will be moved to"
678 ." '/etc/pve/priv/storage/$basename.pw' during the update"
679 );
680
681 $found = 1;
682 });
683
684 log_pass("no CIFS credentials at outdated location found.") if !$found;
685}
686
687sub check_custom_pool_roles {
eed1e93e 688 log_info("Checking custom role IDs for clashes with new 'PVE' namespace..");
a98193c2
TL
689
690 if (! -f "/etc/pve/user.cfg") {
691 log_skip("user.cfg does not exist");
692 return;
693 }
694
695 my $raw = eval { PVE::Tools::file_get_contents('/etc/pve/user.cfg'); };
696 if ($@) {
697 log_fail("Failed to read '/etc/pve/user.cfg' - $@");
698 return;
699 }
700
701 my $roles = {};
702 while ($raw =~ /^\s*(.+?)\s*$/gm) {
703 my $line = $1;
704 my @data;
705
706 foreach my $d (split (/:/, $line)) {
707 $d =~ s/^\s+//;
708 $d =~ s/\s+$//;
709 push @data, $d
710 }
711
712 my $et = shift @data;
713 next if $et ne 'role';
714
715 my ($role, $privlist) = @data;
716 if (!PVE::AccessControl::verify_rolename($role, 1)) {
717 warn "user config - ignore role '$role' - invalid characters in role name\n";
718 next;
719 }
720
721 $roles->{$role} = {} if !$roles->{$role};
722 foreach my $priv (split_list($privlist)) {
723 $roles->{$role}->{$priv} = 1;
724 }
725 }
726
eed1e93e
TL
727 my ($custom_roles, $pve_namespace_clashes) = (0, 0);
728 for my $role (sort keys %{$roles}) {
a98193c2 729 next if PVE::AccessControl::role_is_special($role);
eed1e93e 730 $custom_roles++;
a98193c2 731
eed1e93e
TL
732 if ($role =~ /^PVE/i) {
733 log_warn("custom role '$role' clashes with 'PVE' namespace for built-in roles");
734 $pve_namespace_clashes++;
735 }
736 }
737 if ($pve_namespace_clashes > 0) {
738 log_fail("$pve_namespace_clashes custom role(s) will clash with 'PVE' namespace for built-in roles enforced in Proxmox VE 8");
739 } elsif ($custom_roles > 0) {
740 log_pass("none of the $custom_roles custom roles will clash with newly enforced 'PVE' namespace")
741 } else {
742 log_pass("no custom roles defined, so no clash with 'PVE' role ID namespace enforced in Proxmox VE 8")
a98193c2
TL
743 }
744}
745
746my sub check_max_length {
747 my ($raw, $max_length, $warning) = @_;
748 log_warn($warning) if defined($raw) && length($raw) > $max_length;
749}
750
751sub check_node_and_guest_configurations {
eed1e93e 752 log_info("Checking node and guest description/note length..");
a98193c2
TL
753
754 my @affected_nodes = grep {
755 my $desc = PVE::NodeConfig::load_config($_)->{desc};
756 defined($desc) && length($desc) > 64 * 1024
757 } PVE::Cluster::get_nodelist();
758
759 if (scalar(@affected_nodes) > 0) {
760 log_warn("Node config description of the following nodes too long for new limit of 64 KiB:\n "
761 . join(', ', @affected_nodes));
762 } else {
763 log_pass("All node config descriptions fit in the new limit of 64 KiB");
764 }
765
766 my $affected_guests_long_desc = [];
767 my $affected_cts_cgroup_keys = [];
768
769 my $cts = PVE::LXC::config_list();
770 for my $vmid (sort { $a <=> $b } keys %$cts) {
771 my $conf = PVE::LXC::Config->load_config($vmid);
772
773 my $desc = $conf->{description};
774 push @$affected_guests_long_desc, "CT $vmid" if defined($desc) && length($desc) > 8 * 1024;
775
776 my $lxc_raw_conf = $conf->{lxc};
777 push @$affected_cts_cgroup_keys, "CT $vmid" if (grep (@$_[0] =~ /^lxc\.cgroup\./, @$lxc_raw_conf));
778 }
779 my $vms = PVE::QemuServer::config_list();
780 for my $vmid (sort { $a <=> $b } keys %$vms) {
781 my $desc = PVE::QemuConfig->load_config($vmid)->{description};
782 push @$affected_guests_long_desc, "VM $vmid" if defined($desc) && length($desc) > 8 * 1024;
783 }
784 if (scalar($affected_guests_long_desc->@*) > 0) {
785 log_warn("Guest config description of the following virtual-guests too long for new limit of 64 KiB:\n"
786 ." " . join(", ", $affected_guests_long_desc->@*));
787 } else {
788 log_pass("All guest config descriptions fit in the new limit of 8 KiB");
789 }
790
791 log_info("Checking container configs for deprecated lxc.cgroup entries");
792
793 if (scalar($affected_cts_cgroup_keys->@*) > 0) {
794 if ($forced_legacy_cgroup) {
795 log_pass("Found legacy 'lxc.cgroup' keys, but system explicitly configured for legacy hybrid cgroup hierarchy.");
796 } else {
797 log_warn("The following CTs have 'lxc.cgroup' keys configured, which will be ignored in the new default unified cgroupv2:\n"
798 ." " . join(", ", $affected_cts_cgroup_keys->@*) ."\n"
799 ." Often it can be enough to change to the new 'lxc.cgroup2' prefix after the upgrade to Proxmox VE 7.x");
800 }
801 } else {
802 log_pass("No legacy 'lxc.cgroup' keys found.");
803 }
804}
805
806sub check_storage_content {
807 log_info("Checking storage content type configuration..");
808
809 my $found;
810 my $pass = 1;
811
812 my $storage_cfg = PVE::Storage::config();
813
814 for my $storeid (sort keys $storage_cfg->{ids}->%*) {
815 my $scfg = $storage_cfg->{ids}->{$storeid};
816
817 next if $scfg->{shared};
818 next if !PVE::Storage::storage_check_enabled($storage_cfg, $storeid, undef, 1);
819
820 my $valid_content = PVE::Storage::Plugin::valid_content_types($scfg->{type});
821
822 if (scalar(keys $scfg->{content}->%*) == 0 && !$valid_content->{none}) {
823 $pass = 0;
824 log_fail("storage '$storeid' does not support configured content type 'none'");
825 delete $scfg->{content}->{none}; # scan for guest images below
826 }
827
828 next if $scfg->{content}->{images};
829 next if $scfg->{content}->{rootdir};
830
eed1e93e 831 # Skip 'iscsi(direct)' (and foreign plugins with potentially similar behavior) with 'none',
a98193c2
TL
832 # because that means "use LUNs directly" and vdisk_list() in PVE 6.x still lists those.
833 # It's enough to *not* skip 'dir', because it is the only other storage that supports 'none'
834 # and 'images' or 'rootdir', hence being potentially misconfigured.
835 next if $scfg->{type} ne 'dir' && $scfg->{content}->{none};
836
837 eval { PVE::Storage::activate_storage($storage_cfg, $storeid) };
838 if (my $err = $@) {
839 log_warn("activating '$storeid' failed - $err");
840 next;
841 }
842
843 my $res = eval { PVE::Storage::vdisk_list($storage_cfg, $storeid); };
844 if (my $err = $@) {
845 log_warn("listing images on '$storeid' failed - $err");
846 next;
847 }
848 my @volids = map { $_->{volid} } $res->{$storeid}->@*;
849
850 my $number = scalar(@volids);
851 if ($number > 0) {
852 log_info(
853 "storage '$storeid' - neither content type 'images' nor 'rootdir' configured, but"
854 ."found $number guest volume(s)"
855 );
856 }
857 }
858
859 my $check_volid = sub {
860 my ($volid, $vmid, $vmtype, $reference) = @_;
861
862 my $guesttext = $vmtype eq 'qemu' ? 'VM' : 'CT';
863 my $prefix = "$guesttext $vmid - volume '$volid' ($reference)";
864
865 my ($storeid) = PVE::Storage::parse_volume_id($volid, 1);
866 return if !defined($storeid);
867
868 my $scfg = $storage_cfg->{ids}->{$storeid};
869 if (!$scfg) {
870 $pass = 0;
871 log_warn("$prefix - storage does not exist!");
872 return;
873 }
874
875 # cannot use parse_volname for containers, as it can return 'images'
876 # but containers cannot have ISO images attached, so assume 'rootdir'
877 my $vtype = 'rootdir';
878 if ($vmtype eq 'qemu') {
879 ($vtype) = eval { PVE::Storage::parse_volname($storage_cfg, $volid); };
880 return if $@;
881 }
882
883 if (!$scfg->{content}->{$vtype}) {
884 $found = 1;
885 $pass = 0;
886 log_warn("$prefix - storage does not have content type '$vtype' configured.");
887 }
888 };
889
890 my $cts = PVE::LXC::config_list();
891 for my $vmid (sort { $a <=> $b } keys %$cts) {
892 my $conf = PVE::LXC::Config->load_config($vmid);
893
894 my $volhash = {};
895
896 my $check = sub {
897 my ($ms, $mountpoint, $reference) = @_;
898
899 my $volid = $mountpoint->{volume};
900 return if !$volid || $mountpoint->{type} ne 'volume';
901
902 return if $volhash->{$volid}; # volume might be referenced multiple times
903
904 $volhash->{$volid} = 1;
905
906 $check_volid->($volid, $vmid, 'lxc', $reference);
907 };
908
909 my $opts = { include_unused => 1 };
910 PVE::LXC::Config->foreach_volume_full($conf, $opts, $check, 'in config');
911 for my $snapname (keys $conf->{snapshots}->%*) {
912 my $snap = $conf->{snapshots}->{$snapname};
913 PVE::LXC::Config->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'");
914 }
915 }
916
917 my $vms = PVE::QemuServer::config_list();
918 for my $vmid (sort { $a <=> $b } keys %$vms) {
919 my $conf = PVE::QemuConfig->load_config($vmid);
920
921 my $volhash = {};
922
923 my $check = sub {
924 my ($key, $drive, $reference) = @_;
925
926 my $volid = $drive->{file};
927 return if $volid =~ m|^/|;
928 return if $volhash->{$volid}; # volume might be referenced multiple times
929
930 $volhash->{$volid} = 1;
931 $check_volid->($volid, $vmid, 'qemu', $reference);
932 };
933
934 my $opts = {
935 extra_keys => ['vmstate'],
936 include_unused => 1,
937 };
938 # startup from a suspended state works even without 'images' content type on the
939 # state storage, so do not check 'vmstate' for $conf
940 PVE::QemuConfig->foreach_volume_full($conf, { include_unused => 1 }, $check, 'in config');
941 for my $snapname (keys $conf->{snapshots}->%*) {
942 my $snap = $conf->{snapshots}->{$snapname};
943 PVE::QemuConfig->foreach_volume_full($snap, $opts, $check, "in snapshot '$snapname'");
944 }
945 }
946
947 if ($found) {
948 log_warn("Proxmox VE enforces stricter content type checks since 7.0. The guests above " .
949 "might not work until the storage configuration is fixed.");
950 }
951
952 if ($pass) {
eed1e93e
TL
953 log_pass("no storage content problems found");
954 }
955}
956
957sub check_storage_content_dirs {
958 my $storage_cfg = PVE::Storage::config();
959
960 # check that content dirs are pairwise inequal
961 my $any_problematic = 0;
962 for my $storeid (sort keys $storage_cfg->{ids}->%*) {
963 my $scfg = $storage_cfg->{ids}->{$storeid};
964
965 next if !PVE::Storage::storage_check_enabled($storage_cfg, $storeid, undef, 1);
966 next if !$scfg->{path} || !$scfg->{content};
967
968 eval { PVE::Storage::activate_storage($storage_cfg, $storeid) };
969 if (my $err = $@) {
970 log_warn("activating '$storeid' failed - $err");
971 next;
972 }
973
974 my $resolved_subdirs = {};
975 my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
976 for my $vtype (keys $scfg->{content}->%*) {
977 my $abs_subdir = Cwd::abs_path($plugin->get_subdir($scfg, $vtype));
2a7f4f71 978 next if !defined($abs_subdir);
eed1e93e
TL
979 push $resolved_subdirs->{$abs_subdir}->@*, $vtype;
980 }
981 for my $subdir (keys $resolved_subdirs->%*) {
982 if (scalar($resolved_subdirs->{$subdir}->@*) > 1) {
983 my $types = join(", ", $resolved_subdirs->{$subdir}->@*);
984 log_warn("storage '$storeid' uses directory $subdir for multiple content types ($types).");
985 $any_problematic = 1;
986 }
987 }
988 }
989 if ($any_problematic) {
990 log_fail("re-using directory for multiple content types (see above) is no longer supported in Proxmox VE 8!")
991 } else {
992 log_pass("no storage re-uses a directory for multiple content types.")
a98193c2
TL
993 }
994}
995
996sub check_containers_cgroup_compat {
997 if ($forced_legacy_cgroup) {
998 log_warn("System explicitly configured for legacy hybrid cgroup hierarchy.\n"
eed1e93e 999 ." NOTE: support for the hybrid cgroup hierarchy will be removed in future Proxmox VE 9 (~ 2025)."
a98193c2
TL
1000 );
1001 }
1002
1003 my $supports_cgroupv2 = sub {
1004 my ($conf, $rootdir, $ctid) = @_;
1005
1006 my $get_systemd_version = sub {
1007 my ($self) = @_;
1008
1009 my $sd_lib_dir = -d "/lib/systemd" ? "/lib/systemd" : "/usr/lib/systemd";
1010 my $libsd = PVE::Tools::dir_glob_regex($sd_lib_dir, "libsystemd-shared-.+\.so");
1011 if (defined($libsd) && $libsd =~ /libsystemd-shared-(\d+)\.so/) {
1012 return $1;
1013 }
1014
1015 return undef;
1016 };
1017
1018 my $unified_cgroupv2_support = sub {
1019 my ($self) = @_;
1020
1021 # https://www.freedesktop.org/software/systemd/man/systemd.html
1022 # systemd is installed as symlink to /sbin/init
1023 my $systemd = CORE::readlink('/sbin/init');
1024
1025 # assume non-systemd init will run with unified cgroupv2
1026 if (!defined($systemd) || $systemd !~ m@/systemd$@) {
1027 return 1;
1028 }
1029
1030 # systemd version 232 (e.g. debian stretch) supports the unified hierarchy
1031 my $sdver = $get_systemd_version->();
1032 if (!defined($sdver) || $sdver < 232) {
1033 return 0;
1034 }
1035
1036 return 1;
1037 };
1038
1039 my $ostype = $conf->{ostype};
1040 if (!defined($ostype)) {
1041 log_warn("Found CT ($ctid) without 'ostype' set!");
1042 } elsif ($ostype eq 'devuan' || $ostype eq 'alpine') {
1043 return 1; # no systemd, no cgroup problems
1044 }
1045
1046 my $lxc_setup = PVE::LXC::Setup->new($conf, $rootdir);
1047 return $lxc_setup->protected_call($unified_cgroupv2_support);
1048 };
1049
1050 my $log_problem = sub {
1051 my ($ctid) = @_;
1052 my $extra = $forced_legacy_cgroup ? '' : " or set systemd.unified_cgroup_hierarchy=0 in the Proxmox VE hosts' kernel cmdline";
1053 log_warn(
1054 "Found at least one CT ($ctid) which does not support running in a unified cgroup v2 layout\n"
1055 ." Consider upgrading the Containers distro${extra}! Skipping further CT compat checks."
1056 );
1057 };
1058
1059 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
1060 if ($@) {
1061 log_warn("Failed to retrieve information about this node's CTs - $@");
1062 return;
1063 }
1064
1065 if (!defined($cts) || !scalar(@$cts)) {
1066 log_skip("No containers on node detected.");
1067 return;
1068 }
1069
1070 my @running_cts = sort { $a <=> $b } grep { $_->{status} eq 'running' } @$cts;
1071 my @offline_cts = sort { $a <=> $b } grep { $_->{status} ne 'running' } @$cts;
1072
1073 for my $ct (@running_cts) {
1074 my $ctid = $ct->{vmid};
1075 my $pid = eval { PVE::LXC::find_lxc_pid($ctid) };
1076 if (my $err = $@) {
1077 log_warn("Failed to get PID for running CT $ctid - $err");
1078 next;
1079 }
1080 my $rootdir = "/proc/$pid/root";
1081 my $conf = PVE::LXC::Config->load_config($ctid);
1082
1083 my $ret = eval { $supports_cgroupv2->($conf, $rootdir, $ctid) };
1084 if (my $err = $@) {
1085 log_warn("Failed to get cgroup support status for CT $ctid - $err");
1086 next;
1087 }
1088 if (!$ret) {
1089 $log_problem->($ctid);
1090 return;
1091 }
1092 }
1093
1094 my $storage_cfg = PVE::Storage::config();
1095 for my $ct (@offline_cts) {
1096 my $ctid = $ct->{vmid};
1097 my ($conf, $rootdir, $ret);
1098 eval {
1099 $conf = PVE::LXC::Config->load_config($ctid);
1100 $rootdir = PVE::LXC::mount_all($ctid, $storage_cfg, $conf);
1101 $ret = $supports_cgroupv2->($conf, $rootdir, $ctid);
1102 };
1103 if (my $err = $@) {
1104 log_warn("Failed to load config and mount CT $ctid - $err");
1105 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
1106 next;
1107 }
1108 if (!$ret) {
1109 $log_problem->($ctid);
1110 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
1111 last;
1112 }
1113
1114 eval { PVE::LXC::umount_all($ctid, $storage_cfg, $conf) };
1115 }
1116};
1117
eed1e93e
TL
1118sub check_lxcfs_fuse_version {
1119 log_info("Checking if LXCFS is running with FUSE3 library, if already upgraded..");
1120 if (!$upgraded) {
1121 log_skip("not yet upgraded, no need to check the FUSE library version LXCFS uses");
1122 return;
1123 }
1124
1125 my $lxcfs_pid = eval { file_get_contents('/run/lxcfs.pid') };
1126 if (my $err = $@) {
1127 log_fail("failed to get LXCFS pid - $err");
1128 return;
1129 }
1130 chomp $lxcfs_pid;
1131
1132 my $lxcfs_maps = eval { file_get_contents("/proc/${lxcfs_pid}/maps") };
1133 if (my $err = $@) {
1134 log_fail("failed to get LXCFS maps - $err");
1135 return;
1136 }
1137
1138 if ($lxcfs_maps =~ /\/libfuse.so.2/s) {
1139 log_warn("systems seems to be upgraded but LXCFS is still running with FUSE 2 library, not yet rebooted?")
1140 } elsif ($lxcfs_maps =~ /\/libfuse3.so.3/s) {
1141 log_pass("systems seems to be upgraded and LXCFS is running with FUSE 3 library")
1142 }
1143 return;
1144}
1145
a98193c2
TL
1146sub check_apt_repos {
1147 log_info("Checking if the suite for the Debian security repository is correct..");
1148
1149 my $found = 0;
1150
1151 my $dir = '/etc/apt/sources.list.d';
1152 my $in_dir = 0;
1153
1154 # TODO: check that (original) debian and Proxmox VE mirrors are present.
1155
1156 my $check_file = sub {
1157 my ($file) = @_;
1158
1159 $file = "${dir}/${file}" if $in_dir;
1160
1161 my $raw = eval { PVE::Tools::file_get_contents($file) };
1162 return if !defined($raw);
1163 my @lines = split(/\n/, $raw);
1164
1165 my $number = 0;
1166 for my $line (@lines) {
1167 $number++;
1168
1169 next if length($line) == 0; # split would result in undef then...
1170
1171 ($line) = split(/#/, $line);
1172
1173 next if $line !~ m/^deb[[:space:]]/; # is case sensitive
1174
1175 my $suite;
1176
1177 # catch any of
1178 # https://deb.debian.org/debian-security
1179 # http://security.debian.org/debian-security
1180 # http://security.debian.org/
1181 if ($line =~ m|https?://deb\.debian\.org/debian-security/?\s+(\S*)|i) {
1182 $suite = $1;
1183 } elsif ($line =~ m|https?://security\.debian\.org(?:.*?)\s+(\S*)|i) {
1184 $suite = $1;
1185 } else {
1186 next;
1187 }
1188
1189 $found = 1;
1190
1191 my $where = "in ${file}:${number}";
1192 # TODO: is this useful (for some other checks)?
1193 }
1194 };
1195
1196 $check_file->("/etc/apt/sources.list");
1197
1198 $in_dir = 1;
1199
1200 PVE::Tools::dir_glob_foreach($dir, '^.*\.list$', $check_file);
1201
1202 if (!$found) {
eed1e93e 1203 # only warn, it might be defined in a .sources file or in a way not caaught above
a98193c2
TL
1204 log_warn("No Debian security repository detected in /etc/apt/sources.list and " .
1205 "/etc/apt/sources.list.d/*.list");
1206 }
1207}
1208
1209sub check_time_sync {
1210 my $unit_active = sub { return $get_systemd_unit_state->($_[0], 1) eq 'active' ? $_[0] : undef };
1211
1212 log_info("Checking for supported & active NTP service..");
1213 if ($unit_active->('systemd-timesyncd.service')) {
1214 log_warn(
1215 "systemd-timesyncd is not the best choice for time-keeping on servers, due to only applying"
eed1e93e 1216 ." updates on boot.\n While not necessary for the upgrade it's recommended to use one of:\n"
a98193c2
TL
1217 ." * chrony (Default in new Proxmox VE installations)\n * ntpsec\n * openntpd\n"
1218 );
1219 } elsif ($unit_active->('ntp.service')) {
1220 log_info("Debian deprecated and removed the ntp package for Bookworm, but the system"
1221 ." will automatically migrate to the 'ntpsec' replacement package on upgrade.");
1222 } elsif (my $active_ntp = ($unit_active->('chrony.service') || $unit_active->('openntpd.service') || $unit_active->('ntpsec.service'))) {
1223 log_pass("Detected active time synchronisation unit '$active_ntp'");
1224 } else {
1225 log_warn(
1226 "No (active) time synchronisation daemon (NTP) detected, but synchronized systems are important,"
1227 ." especially for cluster and/or ceph!"
1228 );
1229 }
1230}
1231
35069cdb
SI
1232sub check_bootloader {
1233 log_info("Checking bootloader configuration...");
1234 if (!$upgraded) {
1235 log_skip("not yet upgraded, no need to check the presence of systemd-boot");
1236 return;
1237 }
1238
1239 if (! -f "/etc/kernel/proxmox-boot-uuids") {
1240 log_skip("proxmox-boot-tool not used for bootloader configuration");
1241 return;
1242 }
1243
1244 if (! -d "/sys/firmware/efi") {
1245 log_skip("System booted in legacy-mode - no need for systemd-boot");
1246 return;
1247 }
1248
1249 if ( -f "/usr/share/doc/systemd-boot/changelog.Debian.gz") {
1250 log_pass("systemd-boot is installed");
1251 } else {
1252 log_warn(
1253 "proxmox-boot-tool is used for bootloader configuration in uefi mode"
1254 . "but the separate systemd-boot package, existing in Debian Bookworm is not installed"
1255 . "initializing new ESPs will not work until the package is installed"
1256 );
1257 }
1258}
1259
a98193c2
TL
1260sub check_misc {
1261 print_header("MISCELLANEOUS CHECKS");
1262 my $ssh_config = eval { PVE::Tools::file_get_contents('/root/.ssh/config') };
1263 if (defined($ssh_config)) {
1264 log_fail("Unsupported SSH Cipher configured for root in /root/.ssh/config: $1")
1265 if $ssh_config =~ /^Ciphers .*(blowfish|arcfour|3des).*$/m;
1266 } else {
1267 log_skip("No SSH config file found.");
1268 }
1269
1270 log_info("Checking common daemon services..");
1271 $log_systemd_unit_state->('pveproxy.service');
1272 $log_systemd_unit_state->('pvedaemon.service');
1273 $log_systemd_unit_state->('pvescheduler.service');
1274 $log_systemd_unit_state->('pvestatd.service');
1275
1276 check_time_sync();
1277
1278 my $root_free = PVE::Tools::df('/', 10);
1279 log_warn("Less than 5 GB free space on root file system.")
1280 if defined($root_free) && $root_free->{avail} < 5 * 1000*1000*1000;
1281
1282 log_info("Checking for running guests..");
1283 my $running_guests = 0;
1284
1285 my $vms = eval { PVE::API2::Qemu->vmlist({ node => $nodename }) };
1286 log_warn("Failed to retrieve information about this node's VMs - $@") if $@;
1287 $running_guests += grep { $_->{status} eq 'running' } @$vms if defined($vms);
1288
1289 my $cts = eval { PVE::API2::LXC->vmlist({ node => $nodename }) };
1290 log_warn("Failed to retrieve information about this node's CTs - $@") if $@;
1291 $running_guests += grep { $_->{status} eq 'running' } @$cts if defined($cts);
1292
1293 if ($running_guests > 0) {
1294 log_warn("$running_guests running guest(s) detected - consider migrating or stopping them.")
1295 } else {
1296 log_pass("no running guest detected.")
1297 }
1298
1299 log_info("Checking if the local node's hostname '$nodename' is resolvable..");
1300 my $local_ip = eval { PVE::Network::get_ip_from_hostname($nodename) };
1301 if ($@) {
1302 log_warn("Failed to resolve hostname '$nodename' to IP - $@");
1303 } else {
1304 log_info("Checking if resolved IP is configured on local node..");
1305 my $cidr = Net::IP::ip_is_ipv6($local_ip) ? "$local_ip/128" : "$local_ip/32";
1306 my $configured_ips = PVE::Network::get_local_ip_from_cidr($cidr);
1307 my $ip_count = scalar(@$configured_ips);
1308
1309 if ($ip_count <= 0) {
1310 log_fail("Resolved node IP '$local_ip' not configured or active for '$nodename'");
1311 } elsif ($ip_count > 1) {
1312 log_warn("Resolved node IP '$local_ip' active on multiple ($ip_count) interfaces!");
1313 } else {
1314 log_pass("Resolved node IP '$local_ip' configured and active on single interface.");
1315 }
1316 }
1317
1318 log_info("Check node certificate's RSA key size");
1319 my $certs = PVE::API2::Certificates->info({ node => $nodename });
1320 my $certs_check = {
1321 'rsaEncryption' => {
1322 minsize => 2048,
1323 name => 'RSA',
1324 },
1325 'id-ecPublicKey' => {
1326 minsize => 224,
1327 name => 'ECC',
1328 },
1329 };
1330
1331 my $certs_check_failed = 0;
1332 foreach my $cert (@$certs) {
1333 my ($type, $size, $fn) = $cert->@{qw(public-key-type public-key-bits filename)};
1334
1335 if (!defined($type) || !defined($size)) {
1336 log_warn("'$fn': cannot check certificate, failed to get it's type or size!");
1337 }
1338
1339 my $check = $certs_check->{$type};
1340 if (!defined($check)) {
1341 log_warn("'$fn': certificate's public key type '$type' unknown!");
1342 next;
1343 }
1344
1345 if ($size < $check->{minsize}) {
1346 log_fail("'$fn', certificate's $check->{name} public key size is less than 2048 bit");
1347 $certs_check_failed = 1;
1348 } else {
1349 log_pass("Certificate '$fn' passed Debian Busters (and newer) security level for TLS connections ($size >= 2048)");
1350 }
1351 }
1352
1353 check_backup_retention_settings();
1354 check_cifs_credential_location();
1355 check_custom_pool_roles();
eed1e93e 1356 check_lxcfs_fuse_version();
a98193c2
TL
1357 check_node_and_guest_configurations();
1358 check_apt_repos();
35069cdb 1359 check_bootloader();
a98193c2
TL
1360}
1361
1362my sub colored_if {
1363 my ($str, $color, $condition) = @_;
1364 return "". ($condition ? colored($str, $color) : $str);
1365}
1366
1367__PACKAGE__->register_method ({
1368 name => 'checklist',
1369 path => 'checklist',
1370 method => 'GET',
1371 description => 'Check (pre-/post-)upgrade conditions.',
1372 parameters => {
1373 additionalProperties => 0,
1374 properties => {
1375 full => {
1376 description => 'perform additional, expensive checks.',
1377 type => 'boolean',
1378 optional => 1,
1379 default => 0,
1380 },
1381 },
1382 },
1383 returns => { type => 'null' },
1384 code => sub {
1385 my ($param) = @_;
1386
1387 my $kernel_cli = PVE::Tools::file_get_contents('/proc/cmdline');
1388 if ($kernel_cli =~ /systemd.unified_cgroup_hierarchy=0/){
1389 $forced_legacy_cgroup = 1;
1390 }
1391
1392 check_pve_packages();
1393 check_cluster_corosync();
1394 check_ceph();
1395 check_storage_health();
1396 check_misc();
1397
1398 if ($param->{full}) {
1399 check_containers_cgroup_compat();
1400 } else {
1401 log_skip("NOTE: Expensive checks, like CT cgroupv2 compat, not performed without '--full' parameter");
1402 }
1403
1404 print_header("SUMMARY");
1405
1406 my $total = 0;
1407 $total += $_ for values %$counters;
1408
1409 print "TOTAL: $total\n";
1410 print colored("PASSED: $counters->{pass}\n", 'green');
1411 print "SKIPPED: $counters->{skip}\n";
1412 print colored_if("WARNINGS: $counters->{warn}\n", 'yellow', $counters->{warn} > 0);
1413 print colored_if("FAILURES: $counters->{fail}\n", 'bold red', $counters->{fail} > 0);
1414
1415 if ($counters->{warn} > 0 || $counters->{fail} > 0) {
1416 my $color = $counters->{fail} > 0 ? 'bold red' : 'yellow';
1417 print colored("\nATTENTION: Please check the output for detailed information!\n", $color);
1418 print colored("Try to solve the problems one at a time and then run this checklist tool again.\n", $color) if $counters->{fail} > 0;
1419 }
1420
1421 return undef;
1422 }});
1423
1424our $cmddef = [ __PACKAGE__, 'checklist', [], {}];
1425
14261;