summaryrefslogtreecommitdiffstats
path: root/src/boot-env/OpenSLX/MakeInitRamFS/Engine/Preboot.pm
blob: 319ff65e839e6a070a327763a5fb38af48791c2b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# Copyright (c) 2006..2011 - OpenSLX GmbH
#
# This program is free software distributed under the GPL version 2.
# See http://openslx.org/COPYING
#
# If you have any feedback please consult http://openslx.org/feedback and
# send your suggestions, praise, or complaints to feedback@openslx.org
#
# General information about OpenSLX can be found at http://openslx.org/
# -----------------------------------------------------------------------------
# MakeInitialRamFS::Engine::Preboot.pm
#    - provides driver engine for MakeInitialRamFS API, implementing the
#      base of all preboot variants.
# -----------------------------------------------------------------------------
package OpenSLX::MakeInitRamFS::Engine::Preboot;

use strict;
use warnings;

use base qw(OpenSLX::MakeInitRamFS::Engine::Base);

use OpenSLX::Basics;
use OpenSLX::Utils;

################################################################################
### implementation methods
################################################################################
sub _collectCMDs
{
    my $self = shift;
    
    $self->{CMDs} = [];

    $self->_setupBuildPath();

    $self->_writeInitramfsSetup();
    $self->_writeSlxSystemConf();

    $self->_copyRootfs();
    $self->_copyPrebootSpecificFiles();

    $self->{distro}->applyChanges($self);

    $self->_copyKernelModules();
    
    $self->_createInitRamFS();

    return;
}

sub _setupBuildPath
{
    my $self = shift;
    
    my $buildPath = "$openslxConfig{'temp-path'}/slx-initramfs";
    $self->addCMD("rm -rf $buildPath");

    my @stdFolders = qw(
        bin 
        dev 
        etc
        lib
        mnt 
        proc 
        root 
        sbin
        sys 
        tmp 
        var/lib
        var/run
    );
    $self->addCMD(
        'mkdir -p ' . join(' ', map { "$buildPath/$_"; } @stdFolders)
    );
    
    $self->{'build-path'} = $buildPath;
    
    return;
}
    
sub _writeInitramfsSetup
{
    my $self = shift;
    
    # generate initramfs-setup file containing attributes that are
    # relevant for the initramfs only (before there's a root-FS) -
    # this override adds the name of the client such that the booting
    # system has an ID to use for accessing the corresponding boot environment
    # on the server
    my $initramfsAttrs = {
        'host_name'      => 'slx-client', # just to have something at all
        'ramfs_miscmods' => $self->{attrs}->{ramfs_miscmods} || '',
        'ramfs_nicmods'  => $self->{attrs}->{ramfs_nicmods} || '',
        'ramfs_firmmods'  => $self->{attrs}->{ramfs_firmmods} || '',
        'preboot_id'     => $self->{'preboot-id'} || '',
        'boot_uri'       => $self->{'boot-uri'} || '',
    };
    my $content = "# attributes set by slxconfig-demuxer:\n";
    foreach my $attr (keys %$initramfsAttrs) {
        $content .= qq[$attr="$initramfsAttrs->{$attr}"\n];
    }
    $self->addCMD( {
        file    => "$self->{'build-path'}/etc/initramfs-setup", 
        content => $content
    } );
    
    return;
}

sub _copyRootfs
{
    my $self = shift;

    my $rootfs = "$openslxConfig{'base-path'}/share/rootfs";
    
    my @excludes = qw(
    );

    # exclude strace unless this system is in debug mode
    if (!$self->{'debug-level'}) {
        push @excludes, 'strace';
    }

    my $exclOpts = join ' ', map { "--exclude $_" } @excludes;

    $self->addCMD("rsync $exclOpts -rlpt --numeric-ids $rootfs/ $self->{'build-path'}");
    
    return 1;
}

sub _copyPrebootSpecificFiles
{
    my $self = shift;

    # write secondary rootfs-layer (including init) on top of base layer
    my $prebootRootfs 
        = "$openslxConfig{'base-path'}/share/boot-env/preboot/rootfs";
    $self->addCMD("rsync -rlpt --numeric-ids $prebootRootfs/ $self->{'build-path'}");

    return 1;
}

1;