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