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