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