[pve-devel] [PATCH container] lxc: fall back to 'unmanaged' when no OS detected

Arnout Engelen arnout at bzzt.net
Thu May 28 22:18:46 CEST 2020


This is useful when the uploaded CT does not contain a full OS. When the
autodetection detects an OS, that OS is returned. When it does not
successfully detect a supported OS, but /etc/os-release exists and has an ID
other than 'unmanaged', then the setup fails.

Signed-off-by: Arnout Engelen <arnout at bzzt.net>
---
 src/PVE/LXC/Setup.pm | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
index c738e64..6ebd465 100644
--- a/src/PVE/LXC/Setup.pm
+++ b/src/PVE/LXC/Setup.pm
@@ -70,8 +70,12 @@ my $autodetect_type = sub {
 	return "alpine";
     } elsif (-f  "$rootdir/etc/gentoo-release") {
 	return "gentoo";
+    } elsif (-f "$rootdir/etc/os-release") {
+	die "unable to detect OS distribution\n";
+    } else {
+	warn "/etc/os-release file not found and autodetection failed, falling back to 'unmanaged'\n";
+	return "unmanaged";
     }
-    die "unable to detect OS distribution\n";
 };
 
 sub new {
@@ -94,6 +98,11 @@ sub new {
 	    if $type ne $expected_type;
     }
 
+    if ($type eq 'unmanaged') {
+	$conf->{ostype} = $type;
+	return $self;
+    }
+
     my $plugin_class = $plugins->{$type} ||
 	"no such OS type '$type'\n";
 
-- 
2.26.2




More information about the pve-devel mailing list