[pve-devel] [PATCH container] close #1668: add Devuan support
Thomas Lamprecht
t.lamprecht at proxmox.com
Thu Feb 15 13:16:33 CET 2018
Add separate Plugin as the Debian Plugin will get more systemd
specific stuff in the future, while this here is as anti-systemd as
it gets, so make the split from the start.
Reuse the network parser from the Debian Plugin for now, to much code
to duplicate, and should stay backward compatible anyway.
Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
src/PVE/LXC/Setup.pm | 4 ++
src/PVE/LXC/Setup/Devuan.pm | 73 ++++++++++++++++++++++
src/PVE/LXC/Setup/Makefile | 2 +-
src/test/test-devuan-001/config | 4 ++
src/test/test-devuan-001/etc/devuan_version | 1 +
src/test/test-devuan-001/etc/hostname.exp | 1 +
src/test/test-devuan-001/etc/hosts.exp | 5 ++
.../test-devuan-001/etc/network/interfaces.exp | 18 ++++++
.../test-devuan-001/root/.ssh/authorized_keys.exp | 3 +
9 files changed, 110 insertions(+), 1 deletion(-)
create mode 100644 src/PVE/LXC/Setup/Devuan.pm
create mode 100644 src/test/test-devuan-001/config
create mode 100644 src/test/test-devuan-001/etc/devuan_version
create mode 100644 src/test/test-devuan-001/etc/hostname.exp
create mode 100644 src/test/test-devuan-001/etc/hosts.exp
create mode 100644 src/test/test-devuan-001/etc/network/interfaces.exp
create mode 100644 src/test/test-devuan-001/root/.ssh/authorized_keys.exp
diff --git a/src/PVE/LXC/Setup.pm b/src/PVE/LXC/Setup.pm
index 9b91539..ea0d415 100644
--- a/src/PVE/LXC/Setup.pm
+++ b/src/PVE/LXC/Setup.pm
@@ -13,9 +13,11 @@ use PVE::LXC::Setup::SUSE;
use PVE::LXC::Setup::ArchLinux;
use PVE::LXC::Setup::Alpine;
use PVE::LXC::Setup::Gentoo;
+use PVE::LXC::Setup::Devuan;
my $plugins = {
debian => 'PVE::LXC::Setup::Debian',
+ devuan => 'PVE::LXC::Setup::Devuan',
ubuntu => 'PVE::LXC::Setup::Ubuntu',
centos => 'PVE::LXC::Setup::CentOS',
fedora => 'PVE::LXC::Setup::Fedora',
@@ -51,6 +53,8 @@ my $autodetect_type = sub {
if (-f "$rootdir/etc/debian_version") {
return "debian";
+ } elsif (-f "$rootdir/etc/devuan_version") {
+ return "devuan";
} elsif (-f "$rootdir/etc/SuSE-brand" || -f "$rootdir/etc/SuSE-release") {
return "opensuse";
} elsif (-f "$rootdir/etc/fedora-release") {
diff --git a/src/PVE/LXC/Setup/Devuan.pm b/src/PVE/LXC/Setup/Devuan.pm
new file mode 100644
index 0000000..2f35de6
--- /dev/null
+++ b/src/PVE/LXC/Setup/Devuan.pm
@@ -0,0 +1,73 @@
+package PVE::LXC::Setup::Devuan;
+
+use strict;
+use warnings;
+
+use PVE::Tools qw($IPV6RE);
+use PVE::LXC;
+use PVE::Network;
+use File::Path;
+
+use PVE::LXC::Setup::Base;
+use PVE::LXC::Setup::Debian;
+
+use base qw(PVE::LXC::Setup::Debian);
+
+sub new {
+ my ($class, $conf, $rootdir) = @_;
+
+ my $version = PVE::Tools::file_read_firstline("$rootdir/etc/devuan_version");
+
+ die "unable to read version info\n" if !defined($version);
+
+ die "unsupported Devuan version '$version'\n"
+ if $version !~ /jessie|ascii/;
+
+ my $self = { conf => $conf, rootdir => $rootdir, version => $version };
+
+ $conf->{ostype} = "devuan";
+
+ return bless $self, $class;
+}
+
+# Devuan doesn't support the /dev/lxc/ subdirectory.
+sub devttydir {
+ return '';
+}
+
+sub setup_init {
+ my ($self, $conf) = @_;
+
+ my $filename = "/etc/inittab";
+ return if !$self->ct_file_exists($filename);
+
+ my $ttycount = PVE::LXC::Config->get_tty_count($conf);
+ my $inittab = $self->ct_file_get_contents($filename);
+
+ my @lines = grep {
+ # remove getty lines
+ !/^\s*\d+:\d*:[^:]*:.*getty/ &&
+ # remove power lines
+ !/^\s*p[fno0]:/
+ } split(/\n/, $inittab);
+
+ $inittab = join("\n", @lines) . "\n";
+
+ $inittab .= "p0::powerfail:/sbin/init 0\n";
+
+ for (my $id = 1; $id <= $ttycount; $id++) {
+ next if $id == 7; # reserved for X11
+ my $levels = ($id == 1) ? '2345' : '23';
+ $inittab .= "$id:$levels:respawn:/sbin/getty --noclear 38400 tty$id\n";
+ }
+
+ $self->ct_file_set_contents($filename, $inittab);
+}
+
+sub setup_network {
+ my ($self, $conf) = @_;
+
+ PVE::LXC::Setup::Debian::setup_network($self, $conf);
+}
+
+1;
diff --git a/src/PVE/LXC/Setup/Makefile b/src/PVE/LXC/Setup/Makefile
index f971e0b..df0faff 100644
--- a/src/PVE/LXC/Setup/Makefile
+++ b/src/PVE/LXC/Setup/Makefile
@@ -1,4 +1,4 @@
-SOURCES=Base.pm Debian.pm Ubuntu.pm CentOS.pm Fedora.pm SUSE.pm ArchLinux.pm Alpine.pm Gentoo.pm
+SOURCES=Base.pm Debian.pm Ubuntu.pm CentOS.pm Fedora.pm SUSE.pm ArchLinux.pm Alpine.pm Gentoo.pm Devuan.pm
.PHONY: install
install:
diff --git a/src/test/test-devuan-001/config b/src/test/test-devuan-001/config
new file mode 100644
index 0000000..5191092
--- /dev/null
+++ b/src/test/test-devuan-001/config
@@ -0,0 +1,4 @@
+hostname: test1
+net0: bridge=vmbr0,name=eth0,ip=1.2.3.4/24,gw=1.2.3.1
+net1: bridge=vmbr0,name=eth1,ip=10.2.3.4/24
+net2: bridge=vmbr0,name=eth2,ip=manual
diff --git a/src/test/test-devuan-001/etc/devuan_version b/src/test/test-devuan-001/etc/devuan_version
new file mode 100644
index 0000000..dc797ba
--- /dev/null
+++ b/src/test/test-devuan-001/etc/devuan_version
@@ -0,0 +1 @@
+jessie
diff --git a/src/test/test-devuan-001/etc/hostname.exp b/src/test/test-devuan-001/etc/hostname.exp
new file mode 100644
index 0000000..a5bce3f
--- /dev/null
+++ b/src/test/test-devuan-001/etc/hostname.exp
@@ -0,0 +1 @@
+test1
diff --git a/src/test/test-devuan-001/etc/hosts.exp b/src/test/test-devuan-001/etc/hosts.exp
new file mode 100644
index 0000000..01ac197
--- /dev/null
+++ b/src/test/test-devuan-001/etc/hosts.exp
@@ -0,0 +1,5 @@
+# --- BEGIN PVE ---
+127.0.0.1 localhost.localnet localhost
+::1 localhost.localnet localhost
+1.2.3.4 test1.proxmox.com test1
+# --- END PVE ---
diff --git a/src/test/test-devuan-001/etc/network/interfaces.exp b/src/test/test-devuan-001/etc/network/interfaces.exp
new file mode 100644
index 0000000..0c7dae1
--- /dev/null
+++ b/src/test/test-devuan-001/etc/network/interfaces.exp
@@ -0,0 +1,18 @@
+auto lo
+iface lo inet loopback
+iface lo inet6 loopback
+
+auto eth0
+iface eth0 inet static
+ address 1.2.3.4
+ netmask 255.255.255.0
+ gateway 1.2.3.1
+
+auto eth1
+iface eth1 inet static
+ address 10.2.3.4
+ netmask 255.255.255.0
+
+auto eth2
+iface eth2 inet manual
+
diff --git a/src/test/test-devuan-001/root/.ssh/authorized_keys.exp b/src/test/test-devuan-001/root/.ssh/authorized_keys.exp
new file mode 100644
index 0000000..1cb3ec3
--- /dev/null
+++ b/src/test/test-devuan-001/root/.ssh/authorized_keys.exp
@@ -0,0 +1,3 @@
+# --- BEGIN PVE ---
+ssh-rsa ABCDEFG ABC at DEF
+# --- END PVE ---
--
2.14.2
More information about the pve-devel
mailing list