]>
Commit | Line | Data |
---|---|---|
7af97ad5 | 1 | package PVE::LXC::Setup::Ubuntu; |
a8e58e9c DM |
2 | |
3 | use strict; | |
4 | use warnings; | |
5 | use Data::Dumper; | |
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 = { |
f4f2bd03 | 15 | '18.04' => 1, # bionic |
5fc8ad5f | 16 | '17.10' => 1, # artful |
d9d448fa | 17 | '17.04' => 1, # zesty |
bd4082c1 | 18 | '16.10' => 1, # yakkety |
1c5e428d | 19 | '16.04' => 1, # xenial |
90c85c7d | 20 | '15.10' => 1, # wily |
91bf89e1 DM |
21 | '15.04' => 1, # vivid |
22 | '14.04' => 1, # trusty LTS | |
23 | '12.04' => 1, # precise LTS | |
24 | }; | |
25 | ||
a8e58e9c DM |
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; | |
96f6f684 | 33 | |
a8e58e9c DM |
34 | my $version; |
35 | if ($lsbinfo =~ m/^DISTRIB_RELEASE=(\d+\.\d+)$/mi) { | |
36 | $version = $1; | |
37 | } | |
96f6f684 | 38 | |
a8e58e9c | 39 | die "unable to read version info\n" if !defined($version); |
96f6f684 | 40 | |
40dee029 DM |
41 | die "unsupported Ubuntu version '$version'\n" |
42 | if !$known_versions->{$version}; | |
a8e58e9c DM |
43 | |
44 | my $self = { conf => $conf, rootdir => $rootdir, version => $version }; | |
45 | ||
27916659 | 46 | $conf->{ostype} = "ubuntu"; |
a8e58e9c DM |
47 | |
48 | return bless $self, $class; | |
49 | } | |
50 | ||
51 | sub template_fixup { | |
52 | my ($self, $conf) = @_; | |
53 | ||
91bf89e1 | 54 | my $version = $self->{version}; |
73a7a0e8 DC |
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 | ||
45ebd6c7 | 69 | if ($version eq '15.04' || $version eq '15.10' || $version eq '16.04') { |
a8e58e9c | 70 | # edit /etc/securetty (enable login on console) |
b7cd927f | 71 | $self->setup_securetty($conf, qw(pts/0)); |
a8e58e9c | 72 | } |
91bf89e1 DM |
73 | |
74 | if ($version eq '12.04') { | |
75 | # suppress log level output for udev | |
2063d380 WB |
76 | my $filename = '/etc/udev/udev.conf'; |
77 | my $data = $self->ct_file_get_contents($filename); | |
91bf89e1 | 78 | $data =~ s/=\"err\"/=0/m; |
2063d380 | 79 | $self->ct_file_set_contents($filename, $data); |
91bf89e1 | 80 | } |
a8e58e9c DM |
81 | } |
82 | ||
83 | sub setup_init { | |
84 | my ($self, $conf) = @_; | |
85 | ||
c40a11f2 | 86 | my $version = $self->{version}; |
a8e58e9c | 87 | |
6e273acd | 88 | if ($version >= '16.10') { |
5e84bdc8 | 89 | $self->setup_container_getty_service($conf); |
45ebd6c7 | 90 | } |
96f6f684 | 91 | |
c40a11f2 | 92 | if ($version eq '12.04' || $version eq '14.04') { |
1b4cf758 | 93 | my $ttycount = PVE::LXC::Config->get_tty_count($conf); |
c40a11f2 | 94 | for (my $i = 1; $i < 7; $i++) { |
2063d380 | 95 | my $filename = "/etc/init/tty$i.conf"; |
c40a11f2 DM |
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__ | |
2063d380 | 113 | $self->ct_file_set_contents($filename, $tty_conf); |
c40a11f2 DM |
114 | } else { |
115 | for (my $i = $ttycount + 1; $i < 7; $i++) { | |
2063d380 | 116 | $self->ct_unlink($filename); |
c40a11f2 DM |
117 | } |
118 | } | |
119 | } | |
120 | } | |
a8e58e9c DM |
121 | } |
122 | ||
73a7a0e8 DC |
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 | ||
a8e58e9c | 133 | 1; |