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