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