]> git.proxmox.com Git - dab.git/commitdiff
add usr-merge and enable it for newer Ubuntu and Debian releases
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Sep 2021 11:39:39 +0000 (13:39 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 20 Sep 2021 11:39:41 +0000 (13:39 +0200)
Hard-code enabling usr-merge for Ubuntu releases equal or newer than
21.x and Debian releases equal or newer than Bullseye (11).

We probably want to add a override to the configuration, for force
enabling or disabling.

For now avoid doing so in Devuan, IIRC they do not want to follow
usr-merge at the moment.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
DAB.pm

diff --git a/DAB.pm b/DAB.pm
index 590fd629517eff48d57a78bf2ba55fd9ea207784..1f1bb3055b9de5477e3805090470d92ad7c619e8 100644 (file)
--- a/DAB.pm
+++ b/DAB.pm
@@ -438,6 +438,45 @@ sub __allocate_ve {
     return $self->{veid};
 }
 
+# just use some simple heuristic for now, merge usr for releases newer than ubuntu 21.x or debian 11
+sub can_usr_merge {
+    my ($self) = @_;
+
+    my $ostype = $self->{config}->{ostype};
+
+    # FIXME: add configuration override posibillity
+
+    if ($ostype =~ m/^debian-(\d+)/) {
+       return int($1) >= 11;
+    } elsif ($ostype =~ m/^ubuntu-(\d+)/) {
+       return int($1) >= 21;
+    }
+    return; # false
+}
+
+sub setup_usr_merge {
+    my ($self) = @_;
+
+    my $rootfs = $self->{rootfs};
+    my $arch = $self->{config}->{architecture};
+
+    # similar to https://salsa.debian.org/installer-team/debootstrap/-/blob/master/functions#L1354
+    my @merged_dirs = qw(bin sbin lib);
+
+    if ($arch eq 'amd64') {
+       push @merged_dirs, qw(lib32 lib64 libx32);
+    } elsif ($arch eq 'i386') {
+       push @merged_dirs, qw(lib64 libx32);
+    }
+
+    $self->logmsg ("setup usr-merge symlinks for '" . join("', '", @merged_dirs) . "'\n");
+
+    for my $dir (@merged_dirs) {
+       symlink("usr/$dir", "$rootfs/$dir") or warn "could not create symlink - $!\n";
+       mkpath "$rootfs/usr/$dir";
+    }
+}
+
 sub new {
     my ($class, $config) = @_;
 
@@ -1397,6 +1436,12 @@ sub bootstrap {
 
     # extract required packages first
     $self->logmsg ("create basic environment\n");
+
+    if ($self->can_usr_merge()) {
+       $self->setup_usr_merge();
+    }
+
+    $self->logmsg ("extract required packages to rootfs\n");
     foreach my $p (@$required) {
        my $filename = $self->getpkgfile ($p);
        my $content = $self->run_command("ar -t '$self->{cachedir}/$filename'", undef, 1);