/[fai]/people/michael/features/setup_harddisks_2/implementation/setup-storage
ViewVC logotype

Contents of /people/michael/features/setup_harddisks_2/implementation/setup-storage

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4702 - (show annotations) (download)
Sun Nov 11 10:19:49 2007 UTC (5 years, 6 months ago) by michael-guest
Original Path: people/michael/features/setup_harddisks_2/implementation/shdd2
File size: 6872 byte(s)
changed the formatting, removed shdd2-lib (moved in_path to the parser,
print_hash has long ago be replaced by Data::Dumper), no more perl tidy
1 #!/usr/bin/perl -w
2
3 #*********************************************************************
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # A copy of the GNU General Public License is available as
15 # `/usr/share/common-licences/GPL' in the Debian GNU/Linux distribution
16 # or on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You
17 # can also obtain it by writing to the Free Software Foundation, Inc.,
18 # 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #*********************************************************************
20
21 use strict;
22
23 # treat all warnings about uninitialised values as errors
24 use warnings FATAL => qw(uninitialized);
25
26 ################################################################################
27 #
28 # @file shdd2
29 #
30 # @brief The main function of setup harddisks 2 - the tool to configure the
31 # partitioning from within FAI.
32 #
33 # This is an implementation from scratch to properly support LVM and RAID. The
34 # input format is documented in @ref shdd2-parser
35 #
36 # $Id$
37 #
38 # @author Christian Kern, Michael Tautschnig
39 # @date Sun Jul 23 16:09:36 CEST 2006
40 #
41 ################################################################################
42
43 ################################################################################
44 # TODO list
45 # - parted, libparse-recdescent-perl must get installed in nfsroot (add Depends:
46 # to fai-nfsroot package)
47 #
48 # - closes #380629, #330915, #277045, #356862, #416633
49 # - no-bug: #364763
50 #
51 # - auto mode (something like auto:server, auto:desktop?)
52 # - man page
53 #
54 # - resize should imply resizing the filesystem as well (unless this is done by
55 # parted already, needs to be checked)
56 # - LVMs definitely require resizing the filesystem
57 # - more error messages must be caught by shdd2-exec
58 # - how to detect old-style config files? migration strategies?
59 # - implement disklabels other than msdos and gpt
60 # - the RAID commands are surely incomplete and lack any management of
61 # unanticipated situations
62 # - try to get libparted-swig-perl and use that one instead of the manual
63 # parsing
64 ################################################################################
65
66 package FAI;
67
68 # command line parameter handling
69 use Getopt::Std;
70
71 # the variables for getopt
72 our ( $opt_X, $opt_f );
73
74 # parse the command line
75 &getopts('Xf:') || die <<EOF;
76 USAGE: [-X] no test, your harddisks will be formated
77 default: only test, no real formating
78 [-f<config-filename>] default: parse classes
79 EOF
80
81 # $disklist must be provided by the environment
82 defined( $ENV{disklist} ) or die "Environment variable disklist is not set";
83
84 ################################################################################
85 #
86 # @brief Really write any changes to disk
87 #
88 ################################################################################
89 $FAI::no_dry_run = 0;
90 ($opt_X) and $FAI::no_dry_run = 1;
91 ($opt_X) or warn "shdd2 is running in test-only mode!\n";
92
93 # include all subparts
94 require "shdd2-init";
95 require "shdd2-lib";
96 require "shdd2-volumes";
97 require "shdd2-parser";
98 require "shdd2-sizes";
99 require "shdd2-commands";
100 require "shdd2-fstab";
101 require "shdd2-exec";
102
103 # the config source file
104 my $config_file = undef;
105
106 # use the config file, if given
107 if ($opt_f) {
108 open( $config_file, $opt_f ) or die "Failed to open config file $opt_f\n";
109 }
110
111 # see which class file to use
112 else {
113 foreach my $classfile ( reverse split( /\s+/, $ENV{"classes"} ) ) {
114 next unless ( -r "$ENV{'FAI'}/disk_config/$classfile" );
115 open( $config_file, "$ENV{'FAI'}/disk_config/$classfile" );
116 last;
117 }
118 }
119
120 # if we could not find any matching class file, bail out
121 defined($config_file) or die "No matching disk_config found\n";
122
123 # start the parsing - thereby $FAI::configs is filled
124 &FAI::run_parser($config_file);
125
126 # read the sizes and partition tables of all disks listed in $FAI::disks
127 &FAI::get_current_disks;
128
129 # see whether there are any existing LVMs
130 # load the dm-mod module first, otherwise the LVM tools won't work
131 `modprobe dm-mod`;
132 &FAI::get_current_lvm;
133
134 # see whether there are any existing RAID devices
135 # load the md-mod module first, otherwise there is nothing that can be detected
136 `modprobe md-mod`;
137 &FAI::get_current_raid;
138
139 # for debugging purposes to print the hash structures
140 use Data::Dumper;
141
142 # debugging only: print the current contents of $FAI::current_config
143 if ($FAI::debug) {
144 print "Current disk layout\n";
145
146 # make sure perl doesn't warn about it being used only once
147 our %current_config;
148 print Dumper \%current_config;
149
150 print "Current LVM layout\n";
151
152 # make sure perl doesn't warn about it being used only once
153 our %current_lvm_config;
154 print Dumper \%current_lvm_config;
155
156 print "Current RAID layout\n";
157
158 # make sure perl doesn't warn about it being used only once
159 our %current_raid_config;
160 print Dumper \%current_raid_config;
161 }
162
163 # compute the new LVM and partition sizes; do the partition sizes first to have
164 # them available for the the volume group size estimation
165 &FAI::compute_partition_sizes;
166 &FAI::compute_lv_sizes;
167
168 # debugging only: print the current contents of $FAI::configs
169 if ($FAI::debug) {
170 print "Desired disk layout\n";
171 print Dumper \%FAI::configs;
172 }
173
174 # generate the command script
175 &FAI::build_disk_commands;
176 &FAI::build_raid_commands;
177 &FAI::build_lvm_commands;
178
179 # run all commands
180 # debugging only: print the command script
181 ($FAI::debug) and print "$_\n" foreach (@FAI::commands);
182
183 # run the command (if $FAI::no_dry_run is set)
184 &FAI::execute_command_std($_) foreach (@FAI::commands);
185
186 # generate the proposed fstab contents
187 my @fstab = &FAI::generate_fstab( \%FAI::configs );
188
189 # debugging only; print fstab
190 ($FAI::debug) and print "$_\n" foreach (@fstab);
191
192 # write the proposed contents of fstab to $LOGDIR/fstab, if $FAI::no_dry_run is set
193 if ($FAI::no_dry_run) {
194 # write fstab to $LOGDIR/fstab
195 open( FSTAB, ">$ENV{LOGDIR}/fstab" )
196 or die "Failed to open $ENV{LOGDIR}/fstab for writing\n";
197 print FSTAB "$_\n" foreach (@fstab);
198 close FSTAB;
199 }
200
201 # write variables to $LOGDIR/disk_var.sh
202 # debugging
203 ($FAI::debug) and print "$_=$FAI::disk_var{$_}\n"
204 foreach ( keys %FAI::disk_var );
205
206 # do it, if $FAI::no_dry_run is set
207 if ($FAI::no_dry_run)
208 {
209 open( DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh" )
210 or die "Unable to write to file $ENV{LOGDIR}/disk_var.sh\n";
211 print DISK_VAR "$_=$FAI::disk_var{$_}\n" foreach ( keys %FAI::disk_var );
212 close DISK_VAR;
213 }
214

Properties

Name Value
svn:executable *
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.5