]> git.proxmox.com Git - pve-container.git/blob - src/PVE/LXC/Setup/Alpine.pm
b56d8956ea5a8846455f259e20a7c768dcadc8e2
[pve-container.git] / src / PVE / LXC / Setup / Alpine.pm
1 package PVE::LXC::Setup::Alpine;
2
3 use strict;
4 use warnings;
5
6 use PVE::LXC;
7 use PVE::Network;
8 use File::Path;
9
10 use PVE::LXC::Setup::Base;
11 use PVE::LXC::Setup::Debian;
12
13 use base qw(PVE::LXC::Setup::Base);
14
15 sub new {
16 my ($class, $conf, $rootdir) = @_;
17
18 my $version = PVE::Tools::file_read_firstline("$rootdir/etc/alpine-release");
19
20 my $self = { conf => $conf, rootdir => $rootdir, version => $version };
21 $conf->{ostype} = "alpine";
22 return bless $self, $class;
23 }
24
25 # Alpine doesn't support the /dev/lxc/ subdirectory.
26 sub devttydir {
27 return '';
28 }
29
30 sub template_fixup {
31 my ($self, $conf) = @_;
32
33 # enable networking service
34 $self->ct_symlink('/etc/init.d/networking', '/etc/runlevels/boot/networking');
35 # fixup any symlinks
36 $self->ct_symlink('/etc/init.d/bootmisc', '/etc/runlevels/boot/bootmisc');
37 $self->ct_symlink('/etc/init.d/hostname', '/etc/runlevels/boot/hostname');
38 # fix stop system
39 $self->ct_symlink('/etc/init.d/killprocs', '/etc/runlevels/shutdown/killprocs');
40 $self->ct_symlink('/etc/init.d/savecache', '/etc/runlevels/shutdown/savecache');
41
42 $self->setup_securetty($conf);
43 }
44
45 sub setup_init {
46 my ($self, $conf) = @_;
47
48 my $filename = "/etc/inittab";
49 return if !$self->ct_file_exists($filename);
50
51 my $ttycount = PVE::LXC::Config->get_tty_count($conf);
52 my $inittab = $self->ct_file_get_contents($filename);
53
54 my @lines = grep {
55 !/^\s*tty\d+:\d*:[^:]*:.*getty/ # remove getty lines
56 } split(/\n/, $inittab);
57
58 $inittab = join("\n", @lines) . "\n";
59
60 for (my $id = 1; $id <= $ttycount; $id++) {
61 next if $id == 7; # reserved for X11
62 $inittab .= "tty$id\::respawn:/sbin/getty 38400 tty$id\n";
63 }
64
65 $self->ct_file_set_contents($filename, $inittab);
66 }
67
68 sub setup_network {
69 # Network is debian compatible, but busybox' udhcpc6 is unfinished
70 my ($self, $conf) = @_;
71
72 # XXX: udhcpc6 in busybox is broken; once a working alpine release comes
73 # we can remove this bit.
74 #
75 # Filter out ipv6 dhcp and turn it into 'manual' so they see what's up.
76 #
77 # XXX: slaac works different from debian - busybox has no 'auto'
78 # configuration type - https://wiki.alpinelinux.org/wiki/Configure_Networking#IPv6_Stateless_Autoconfiguration
79 # the suggested configuration sadly does not take the interface up, but
80 # at least with the workaround the networking starts and if an ipv4 is
81 # configured slaac for ipv6 works (unless accept_ra = 0 in the node)
82
83 my $newconf = {};
84 my $networks = {};
85 foreach my $k (keys %$conf) {
86 my $value = $conf->{$k};
87 $newconf->{$k} = $value;
88 next if $k !~ m/^net(\d+)$/;
89
90 my $netstring = $value;
91 # check for dhcp6:
92 my $d = PVE::LXC::Config->parse_lxc_network($netstring);
93 if (defined($d->{ip6}) && ($d->{ip6} eq 'dhcp' || $d->{ip6} eq 'auto')) {
94 $d->{ip6} = 'manual';
95 $netstring = PVE::LXC::Config->print_lxc_network($d);
96 }
97 $newconf->{$k} = $netstring;
98 }
99
100 PVE::LXC::Setup::Debian::setup_network($self, $newconf);
101 }
102
103 # non systemd based containers work with pure cgroupv2
104 sub unified_cgroupv2_support {
105 my ($self) = @_;
106
107 return 1;
108 }
109
110 1;