]> git.proxmox.com Git - pve-container.git/blame - src/PVE/LXC/Setup/Ubuntu.pm
setup: support upcoming Debian, Devuan and Ubuntu releases
[pve-container.git] / src / PVE / LXC / Setup / Ubuntu.pm
CommitLineData
7af97ad5 1package PVE::LXC::Setup::Ubuntu;
a8e58e9c
DM
2
3use strict;
4use warnings;
179b842e 5
a8e58e9c
DM
6use PVE::Tools;
7use PVE::LXC;
8use File::Path;
9
7af97ad5 10use PVE::LXC::Setup::Debian;
a8e58e9c 11
7af97ad5 12use base qw(PVE::LXC::Setup::Debian);
a8e58e9c 13
91bf89e1 14my $known_versions = {
db37c91c 15 '23.10' => 1, # mantic
fb99f925 16 '23.04' => 1, # lunar
c0db1ab9 17 '22.10' => 1, # kinetic
db37c91c 18 '22.04' => 1, # jammy LTS
c501e4ce 19 '21.10' => 1, # impish
79f8ceed
TL
20 '21.04' => 1, # hirsute
21 '20.10' => 1, # groovy
eb03cc11 22 '20.04' => 1, # focal LTS
5c5d57f0 23 '19.10' => 1, # eoan
98fdb6b9 24 '19.04' => 1, # disco
7b8cab25 25 '18.10' => 1, # cosmic
a89aed4b 26 '18.04' => 1, # bionic LTS
5fc8ad5f 27 '17.10' => 1, # artful
d9d448fa 28 '17.04' => 1, # zesty
bd4082c1 29 '16.10' => 1, # yakkety
a89aed4b 30 '16.04' => 1, # xenial LTS
90c85c7d 31 '15.10' => 1, # wily
91bf89e1
DM
32 '15.04' => 1, # vivid
33 '14.04' => 1, # trusty LTS
34 '12.04' => 1, # precise LTS
35};
36
a8e58e9c
DM
37sub new {
38 my ($class, $conf, $rootdir) = @_;
39
40 my $lsb_fn = "$rootdir/etc/lsb-release";
41 my $lsbinfo = PVE::Tools::file_get_contents($lsb_fn);
42
43 die "got unknown DISTRIB_ID\n" if $lsbinfo !~ m/^DISTRIB_ID=Ubuntu$/mi;
96f6f684 44
a8e58e9c
DM
45 my $version;
46 if ($lsbinfo =~ m/^DISTRIB_RELEASE=(\d+\.\d+)$/mi) {
47 $version = $1;
48 }
96f6f684 49
a8e58e9c 50 die "unable to read version info\n" if !defined($version);
96f6f684 51
40dee029
DM
52 die "unsupported Ubuntu version '$version'\n"
53 if !$known_versions->{$version};
a8e58e9c
DM
54
55 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
56
27916659 57 $conf->{ostype} = "ubuntu";
a8e58e9c
DM
58
59 return bless $self, $class;
60}
61
62sub template_fixup {
63 my ($self, $conf) = @_;
64
91bf89e1 65 my $version = $self->{version};
73a7a0e8
DC
66
67 if ($version >= '17.10') {
68 # enable systemd-networkd
69 $self->ct_mkdir('/etc/systemd/system/multi-user.target.wants');
70 $self->ct_mkdir('/etc/systemd/system/socket.target.wants');
71 $self->ct_symlink('/lib/systemd/system/systemd-networkd.service',
72 '/etc/systemd/system/multi-user.target.wants/systemd-networkd.service');
73 $self->ct_symlink('/lib/systemd/system/systemd-networkd.socket',
74 '/etc/systemd/system/socket.target.wants/systemd-networkd.socket');
75
76 # unlink default netplan lxc config
77 $self->ct_unlink('/etc/netplan/10-lxc.yaml');
78 }
79
45ebd6c7 80 if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') {
a8e58e9c 81 # edit /etc/securetty (enable login on console)
b7cd927f 82 $self->setup_securetty($conf, qw(pts/0));
a8e58e9c 83 }
91bf89e1
DM
84
85 if ($version eq '12.04') {
86 # suppress log level output for udev
2063d380
WB
87 my $filename = '/etc/udev/udev.conf';
88 my $data = $self->ct_file_get_contents($filename);
91bf89e1 89 $data =~ s/=\"err\"/=0/m;
2063d380 90 $self->ct_file_set_contents($filename, $data);
91bf89e1 91 }
a8e58e9c
DM
92}
93
94sub setup_init {
95 my ($self, $conf) = @_;
96
c40a11f2 97 my $version = $self->{version};
a8e58e9c 98
6e273acd 99 if ($version >= '16.10') {
5e84bdc8 100 $self->setup_container_getty_service($conf);
45ebd6c7 101 }
96f6f684 102
c40a11f2 103 if ($version eq '12.04' || $version eq '14.04') {
1b4cf758 104 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
c40a11f2 105 for (my $i = 1; $i < 7; $i++) {
2063d380 106 my $filename = "/etc/init/tty$i.conf";
c40a11f2
DM
107 if ($i <= $ttycount) {
108 my $tty_conf = <<__EOD__;
109# tty$i - getty
110#
111# This service maintains a getty on tty$i from the point the system is
112# started until it is shut down again.
113
114start on stopped rc RUNLEVEL=[2345] and (
115 not-container or
116 container CONTAINER=lxc or
117 container CONTAINER=lxc-libvirt)
118
119stop on runlevel [!2345]
120
121respawn
122exec /sbin/getty -8 38400 tty$i
123__EOD__
2063d380 124 $self->ct_file_set_contents($filename, $tty_conf);
c40a11f2
DM
125 } else {
126 for (my $i = $ttycount + 1; $i < 7; $i++) {
2063d380 127 $self->ct_unlink($filename);
c40a11f2
DM
128 }
129 }
130 }
131 }
a8e58e9c
DM
132}
133
73a7a0e8
DC
134sub setup_network {
135 my ($self, $conf) = @_;
136
137 if ($self->{version} >= '17.10') {
138 $self->setup_systemd_networkd($conf);
139 } else {
140 $self->SUPER::setup_network($conf);
141 }
142}
143
a8e58e9c 1441;