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