[Fai-commit] r4614 - people/michael/features/setup_harddisks_2/implementation
andreas at alioth.debian.org
andreas at alioth.debian.org
Tue Oct 9 18:36:33 UTC 2007
Author: andreas
Date: 2007-10-09 18:36:33 +0000 (Tue, 09 Oct 2007)
New Revision: 4614
Modified:
people/michael/features/setup_harddisks_2/implementation/shdd2
people/michael/features/setup_harddisks_2/implementation/shdd2-commands
people/michael/features/setup_harddisks_2/implementation/shdd2-exec
people/michael/features/setup_harddisks_2/implementation/shdd2-fstab
people/michael/features/setup_harddisks_2/implementation/shdd2-init
people/michael/features/setup_harddisks_2/implementation/shdd2-parser
people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
people/michael/features/setup_harddisks_2/implementation/shdd2-volumes
Log:
make tidy
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2 2007-10-09 18:36:33 UTC (rev 4614)
@@ -44,7 +44,7 @@
# TODO list
# - parted, libparse-recdescent-perl must get installed in nfsroot (add Depends:
# to fai-nfsroot package)
-#
+#
# - closes #380629, #330915, #277045, #356862, #416633
# - no-bug: #364763
#
@@ -63,13 +63,14 @@
# parsing
################################################################################
-
package FAI;
# command line parameter handling
use Getopt::Std;
+
# the variables for getopt
our ( $opt_X, $opt_f );
+
# parse the command line
&getopts('Xf:') || die "
USAGE: [-X] no test, your harddisks will be formated
@@ -77,7 +78,7 @@
[-f<config-filename>] default: parse classes
";
-# $disklist must be provided by the environment
+# $disklist must be provided by the environment
defined( $ENV{disklist} ) or die "Environment variable disklist is not set";
################################################################################
@@ -86,8 +87,8 @@
#
################################################################################
$FAI::no_dry_run = 0;
-( $opt_X ) and $FAI::no_dry_run = 1;
-( $opt_X ) or warn "shdd2 is running in test-only mode!\n";
+($opt_X) and $FAI::no_dry_run = 1;
+($opt_X) or warn "shdd2 is running in test-only mode!\n";
# include all subparts
require "shdd2-init";
@@ -101,25 +102,26 @@
# the config source file
my $config_file = undef;
+
# use the config file, if given
-if ( $opt_f )
+if ($opt_f)
{
- open($config_file, $opt_f) or die
- "Failed to open config file $opt_f\n";
+ open( $config_file, $opt_f ) or die "Failed to open config file $opt_f\n";
}
+
# see which class file to use
else
{
- foreach my $classfile (reverse split(/\s+/,$ENV{"classes"}))
+ foreach my $classfile ( reverse split( /\s+/, $ENV{"classes"} ) )
{
next unless ( -r "$ENV{'FAI'}/disk_config/$classfile" );
- open($config_file, "$ENV{'FAI'}/disk_config/$classfile");
+ open( $config_file, "$ENV{'FAI'}/disk_config/$classfile" );
last;
}
}
# if we could not find any matching class file, bail out
-defined( $config_file ) or die "No matching disk_config found\n";
+defined($config_file) or die "No matching disk_config found\n";
# start the parsing - thereby $FAI::configs is filled
&FAI::run_parser($config_file);
@@ -141,19 +143,22 @@
use Data::Dumper;
# debugging only: print the current contents of $FAI::current_config
-if ( $FAI::debug )
+if ($FAI::debug)
{
print "Current disk layout\n";
+
# make sure perl doesn't warn about it being used only once
our %current_config;
print Dumper \%current_config;
-
+
print "Current LVM layout\n";
+
# make sure perl doesn't warn about it being used only once
our %current_lvm_config;
print Dumper \%current_lvm_config;
-
+
print "Current RAID layout\n";
+
# make sure perl doesn't warn about it being used only once
our %current_raid_config;
print Dumper \%current_raid_config;
@@ -165,7 +170,7 @@
&FAI::compute_lv_sizes;
# debugging only: print the current contents of $FAI::configs
-if ( $FAI::debug )
+if ($FAI::debug)
{
print "Desired disk layout\n";
print Dumper \%FAI::configs;
@@ -178,38 +183,39 @@
# run all commands
# debugging only: print the command script
-( $FAI::debug ) and print "$_\n" foreach ( @FAI::commands );
+($FAI::debug) and print "$_\n" foreach (@FAI::commands);
+
# run the command (if $FAI::no_dry_run is set)
-&FAI::execute_command_std($_) foreach ( @FAI::commands );
+&FAI::execute_command_std($_) foreach (@FAI::commands);
# generate the proposed fstab contents
my @fstab = &FAI::generate_fstab( \%FAI::configs );
# debugging only; print fstab
-( $FAI::debug ) and print "$_\n" foreach (@fstab);
+($FAI::debug) and print "$_\n" foreach (@fstab);
# write the proposed contents of fstab to $LOGDIR/fstab, if $FAI::no_dry_run is set
-if ( $FAI::no_dry_run )
+if ($FAI::no_dry_run)
{
+
# write fstab to $LOGDIR/fstab
- open(FSTAB, ">$ENV{LOGDIR}/fstab") or die
- "Failed to open $ENV{LOGDIR}/fstab for writing\n";
+ open( FSTAB, ">$ENV{LOGDIR}/fstab" )
+ or die "Failed to open $ENV{LOGDIR}/fstab for writing\n";
print FSTAB "$_\n" foreach (@fstab);
close FSTAB;
}
# write variables to $LOGDIR/disk_var.sh
# debugging
-( $FAI::debug ) and print "$_=$FAI::disk_var{$_}\n"
+($FAI::debug) and print "$_=$FAI::disk_var{$_}\n"
foreach ( keys %FAI::disk_var );
+
# do it, if $FAI::no_dry_run is set
-if ( $FAI::no_dry_run )
+if ($FAI::no_dry_run)
{
- open(DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh") or die
- "Unable to write to file $ENV{LOGDIR}/disk_var.sh\n";
- print DISK_VAR "$_=$FAI::disk_var{$_}\n"
- foreach ( keys %FAI::disk_var );
+ open( DISK_VAR, ">$ENV{LOGDIR}/disk_var.sh" )
+ or die "Unable to write to file $ENV{LOGDIR}/disk_var.sh\n";
+ print DISK_VAR "$_=$FAI::disk_var{$_}\n" foreach ( keys %FAI::disk_var );
close DISK_VAR;
}
-
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-commands
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-commands 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-commands 2007-10-09 18:36:33 UTC (rev 4614)
@@ -49,8 +49,8 @@
{
my ( $device, $partition ) = @_;
- defined( $partition->{"filesystem"} ) or die
- "INTERNAL ERROR: filesystem is undefined\n";
+ defined( $partition->{"filesystem"} )
+ or die "INTERNAL ERROR: filesystem is undefined\n";
if ( $partition->{"filesystem"} eq "-" )
{
@@ -58,12 +58,15 @@
}
elsif ( $partition->{"filesystem"} eq "swap" )
{
- push @FAI::commands, "mkswap " . $partition->{"fs_options"} . " $device";
+ push @FAI::commands, "mkswap " . $partition->{"fs_options"} . " $device";
}
else
{
- push @FAI::commands, "mkfs." . $partition->{"filesystem"} . " " .
- $partition->{"fs_options"} . " $device";
+ push @FAI::commands,
+ "mkfs."
+ . $partition->{"filesystem"} . " "
+ . $partition->{"fs_options"}
+ . " $device";
}
}
@@ -77,12 +80,14 @@
################################################################################
sub build_raid_commands
{
+
# TODO: do we need to stop anything before we continue? Do we need to issue
# mdadm --misc --zero-superblock /dev/hdx?
# loop through all configs
foreach my $config ( keys %FAI::configs )
{
+
# no LVM here
next if ( $config =~ /^VG_(.+)$/ );
@@ -90,28 +95,34 @@
next if ( $config =~ /^PHY_(.+)$/ );
# create the RAID devices and the filesystems
- ( $config eq "RAID" ) or die
- "INTERNAL ERROR: Invalid config\n";
+ ( $config eq "RAID" ) or die "INTERNAL ERROR: Invalid config\n";
# create all raid devices
foreach my $id ( sort keys %{ $FAI::configs{$config}{"volumes"} } )
{
+
# the desired RAID level
my $level = $FAI::configs{$config}{"volumes"}{$id}{"mode"};
+
# prepend "raid", if the mode is numeric-only
$level = "raid" . $level if ( $level =~ /^\d+$/ );
+
# the list of RAID devices
my @devs = keys %{ $FAI::configs{$config}{"volumes"}{$id}{"devices"} };
+
# create the command
- push @FAI::commands, "yes | mdadm --create /dev/md$id --level=$level "
- . "--raid-devices=" . scalar( @devs ) . " " . join( " ", @devs );
+ push @FAI::commands,
+ "yes | mdadm --create /dev/md$id --level=$level "
+ . "--raid-devices="
+ . scalar(@devs) . " "
+ . join( " ", @devs );
+
# create the filesystem on the volume
&FAI::build_mkfs_commands( "/dev/md$id",
\%{ $FAI::configs{$config}{"volumes"}{$id} } );
}
}
}
-
################################################################################
#
@@ -127,6 +138,7 @@
# loop through all configs
foreach my $config ( keys %FAI::configs )
{
+
# no physical devices here
next if ( $config =~ /^PHY_(.+)$/ );
@@ -134,23 +146,18 @@
next if ( $config eq "RAID" );
# create the volume groups, the logical volumes and the filesystems
- ( $config =~ /^VG_(.+)$/ ) or die
- "INTERNAL ERROR: Invalid config\n";
+ ( $config =~ /^VG_(.+)$/ ) or die "INTERNAL ERROR: Invalid config\n";
# the volume group
my $vg = $1;
-
+
# find volumes that should be preserved or resized and ensure that they
# already exist
- foreach
- my $lv ( keys %{ $FAI::configs{$config}{"volumes"} } )
+ foreach my $lv ( keys %{ $FAI::configs{$config}{"volumes"} } )
{
next
- unless (
- $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"preserve"} ==
- 1
- || $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"resize"} ==
- 1 );
+ unless ( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"preserve"} == 1
+ || $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"resize"} == 1 );
# preserved or resized volumes must exist already
defined( $FAI::current_lvm_config{$vg}{"volumes"}{$lv} )
@@ -158,51 +165,66 @@
}
# create the volume group, if it doesn't exist already
- if ( ! defined( $FAI::current_lvm_config{$vg} ) )
+ if ( !defined( $FAI::current_lvm_config{$vg} ) )
{
+
# create all the devices, unless they already exist (then, pvdisplay will
# succeed)
- push @FAI::commands, "pvdisplay $_ || pvcreate $_" foreach ( keys
- %{ $FAI::configs{$config}{"devices"} } );
+ push @FAI::commands, "pvdisplay $_ || pvcreate $_"
+ foreach ( keys %{ $FAI::configs{$config}{"devices"} } );
+
# create the volume group
- push @FAI::commands, "vgcreate $vg " . join( " ", keys %{
- $FAI::configs{$config}{"devices"} } );
+ push @FAI::commands, "vgcreate $vg "
+ . join( " ", keys %{ $FAI::configs{$config}{"devices"} } );
}
+
# otherwise add or remove the devices for the volume group, run pvcreate
# where needed (using pvdisplay <bla> || pvcreate <bla>)
else
{
+
# the list of devices to be created
my %new_devs = ();
+
# create an undefined entry for each new device
- @new_devs{keys %{ $FAI::configs{$config}{"devices"} }} = ();
+ @new_devs{ keys %{ $FAI::configs{$config}{"devices"} } } = ();
+
# create all the devices, unless they already exist (then, pvdisplay will
# succeed)
- push @FAI::commands, "pvdisplay $_ || pvcreate $_" foreach ( keys
- %new_devs );
+ push @FAI::commands, "pvdisplay $_ || pvcreate $_"
+ foreach ( keys %new_devs );
+
# extend the volume group by the new devices (includes the current ones)
push @FAI::commands, "vgextend $vg " . join( " ", keys %new_devs );
+
# the devices to be removed
my %rm_devs = ();
- @rm_devs{@{$FAI::current_lvm_config{$vg}{"physical_volumes"}}} = ();
+ @rm_devs{ @{ $FAI::current_lvm_config{$vg}{"physical_volumes"} } } = ();
+
# remove remaining devices from the list
delete $rm_devs{$_} foreach ( keys %new_devs );
+
# run vgreduce to get them removed
- push @FAI::commands, "vgreduce $vg " . join( " ", keys %rm_devs ) if (
- scalar( keys %rm_devs ) );
+ push @FAI::commands, "vgreduce $vg " . join( " ", keys %rm_devs )
+ if ( scalar( keys %rm_devs ) );
}
-
+
# enable the volume group
push @FAI::commands, "vgchange -a y $vg";
-
+
# remove, resize, create the logical volumes
# remove all volumes that do not exist anymore or need not be preserved
foreach my $lv ( keys %{ $FAI::current_lvm_config{$vg}{"volumes"} } )
{
+
# skip preserved/resized volumes
- next if ( defined( $FAI::configs{$config}{"volumes"}{$lv} ) &&
- ( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"preserve"} == 1 ||
- $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"resize"} ) );
+ next
+ if (
+ defined( $FAI::configs{$config}{"volumes"}{$lv} )
+ && ( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"preserve"} == 1
+ || $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"resize"} )
+ );
+
# remove $lv
push @FAI::commands, "lvremove -f $vg/$lv";
}
@@ -210,27 +232,35 @@
# now create or resize the configured logical volumes
foreach my $lv ( keys %{ $FAI::configs{$config}{"volumes"} } )
{
+
# skip preserved partitions, but ensure that they exist
if ( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"preserve"} == 1 )
{
- defined( $FAI::current_lvm_config{$vg}{"volumes"}{$lv} ) or die
- "Preserved volume $vg/$lv does not exist\n";
+ defined( $FAI::current_lvm_config{$vg}{"volumes"}{$lv} )
+ or die "Preserved volume $vg/$lv does not exist\n";
next;
}
- # resize the volume
+
+ # resize the volume
if ( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"resize"} == 1 )
{
- defined( $FAI::current_lvm_config{$vg}{"volumes"}{$lv} ) or die
- "Resized volume $vg/$lv does not exist\n";
+ defined( $FAI::current_lvm_config{$vg}{"volumes"}{$lv} )
+ or die "Resized volume $vg/$lv does not exist\n";
+
# note that resizing a volume destroys the data on it
- push @FAI::commands, "lvresize -L " .
- $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} . " $vg/$lv";
+ push @FAI::commands,
+ "lvresize -L "
+ . $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"}
+ . " $vg/$lv";
}
+
# create a new volume
else
{
- push @FAI::commands, "lvcreate -n $lv -L " .
- $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} . " $vg";
+ push @FAI::commands,
+ "lvcreate -n $lv -L "
+ . $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} . " $vg";
+
# create the filesystem on the volume
&FAI::build_mkfs_commands( "/dev/$vg/$lv",
\%{ $FAI::configs{$config}{"volumes"}{$lv} } );
@@ -254,6 +284,7 @@
# loop through all configs
foreach my $config ( keys %FAI::configs )
{
+
# no RAID devices here
next if ( $config eq "RAID" );
@@ -261,8 +292,7 @@
next if ( $config =~ /^VG_(.+)$/ );
# configure a physical device
- ( $config =~ /^PHY_(.+)$/ ) or die
- "INTERNAL ERROR: Invalid config\n";
+ ( $config =~ /^PHY_(.+)$/ ) or die "INTERNAL ERROR: Invalid config\n";
# the device to be configured
my $disk = $1;
@@ -270,6 +300,7 @@
# create partitions on non-virtual configs
if ( $FAI::configs{$config}{"virtual"} == 0 )
{
+
# the list of partitions that must be preserved
my @to_preserve = ();
@@ -301,32 +332,47 @@
# sort the list of preserved partitions
@to_preserve = sort { $a <=> $b } @to_preserve;
-
+
# add the extended partition as well, if logical partitions must be
# preserved; and mark it as resize
if ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
{
+
# we assume there are no logical partitions
my $has_logical = 0;
- my $extended = -1;
+ my $extended = -1;
+
# now check all entries; the array is sorted
foreach my $part_id (@to_preserve)
{
+
# the extended partition may already be listed; then, the id of the
# extended partition must not change
- if ( $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"} == 1 )
+ if ( $FAI::current_config{$disk}{"partitions"}{$part_id}
+ {"is_extended"} == 1 )
{
- ( defined( $FAI::configs{$config}{"partitions"}{$extended}{"size"}{"extended"} ) &&
- defined( $FAI::current_config{$disk}{"partitions"}{$extended}{"is_extended"} ) &&
- $FAI::configs{$config}{"partitions"}{$extended}{"size"}{"extended"} == 1 &&
- $FAI::current_config{$disk}{"partitions"}{$extended}{"is_extended"}
- == 1 ) or die "ID of extended partition changes\n";
+ (
+ defined(
+ $FAI::configs{$config}{"partitions"}{$extended}{"size"}
+ {"extended"}
+ )
+ && defined(
+ $FAI::current_config{$disk}{"partitions"}{$extended}
+ {"is_extended"}
+ )
+ && $FAI::configs{$config}{"partitions"}{$extended}{"size"}
+ {"extended"} == 1
+ && $FAI::current_config{$disk}{"partitions"}{$extended}
+ {"is_extended"} == 1
+ ) or die "ID of extended partition changes\n";
+
# make sure resize is set
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} =
1;
$extended = $part_id;
last;
}
+
# there is some logical partition
if ( $part_id > 4 )
{
@@ -339,26 +385,27 @@
# that we need to add the existing one
if ( 1 == $has_logical && -1 == $extended )
{
- foreach
- my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
+ foreach my $part_id (
+ sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
{
+
# no extended partition
- next unless (
- $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"} == 1
- );
-
+ next
+ unless ( $FAI::current_config{$disk}{"partitions"}{$part_id}
+ {"is_extended"} == 1 );
+
# find the configured extended partition to set the mapping
foreach
my $p ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
{
- next unless (
- $FAI::configs{$config}{"partitions"}{$p}{"size"}{"extended"} == 1
- );
-
+ next
+ unless (
+ $FAI::configs{$config}{"partitions"}{$p}{"size"}{"extended"} ==
+ 1 );
+
# make sure resize is set
- $FAI::configs{$config}{"partitions"}{$p}{"size"}{"resize"} =
- 1;
-
+ $FAI::configs{$config}{"partitions"}{$p}{"size"}{"resize"} = 1;
+
# store the id for further checks
$extended = $p;
@@ -371,40 +418,47 @@
last;
}
-
+
# sort the list of preserved partitions (again)
@to_preserve = sort { $a <=> $b } @to_preserve;
-
+
last;
}
}
-
+
# a sanity check: if there are logical partitions, they extended must
# have been added
- ( 0 == $has_logical || -1 != $extended ) or die
- "INTERNAL ERROR: Required extended partition not detected for preserve\n";
+ ( 0 == $has_logical || -1 != $extended )
+ or die
+"INTERNAL ERROR: Required extended partition not detected for preserve\n";
}
# A new disk label may only be written if no partitions need to be
# preserved
- ( ( $FAI::configs{$config}{'disklabel'} eq
- $FAI::current_config{$disk}{'disklabel'} ) || ( scalar(@to_preserve) == 0
- ) ) or die "Can't change disklabel, partitions are to be preserved\n";
+ (
+ (
+ $FAI::configs{$config}{'disklabel'} eq
+ $FAI::current_config{$disk}{'disklabel'}
+ )
+ || ( scalar(@to_preserve) == 0 )
+ ) or die "Can't change disklabel, partitions are to be preserved\n";
# write the disklabel to drop the previous partition table
push @FAI::commands, "$FAI::system_commands{'parted'} $disk mklabel "
. $FAI::configs{$config}{'disklabel'};
-
+
# once we rebuild partitions, their ids are likely to change; this counter
# helps keeping track of this
my $part_nr = 0;
-
+
# now rebuild all preserved partitions
foreach my $part_id (@to_preserve)
{
+
# get the existing id
my $mapped_id =
$FAI::configs{$config}{"partitions"}{$part_id}{"maps_to_existing"};
+
# get the original starts and ends
my $start =
$FAI::current_config{$disk}{"partitions"}{$mapped_id}{"begin_byte"};
@@ -436,26 +490,32 @@
$part_nr;
# build a parted command to create the partition
- push @FAI::commands, "$FAI::system_commands{'parted'} $disk mkpart "
- . "$part_type $start" . "B " . $end . "B";
+ push @FAI::commands,
+ "$FAI::system_commands{'parted'} $disk mkpart "
+ . "$part_type $start" . "B "
+ . $end . "B";
}
# resize partitions; first we shrink partitions, then grow others;
# furthermore we start from the end to shrink logical partitions before
# the extended one, but grow partitions starting from the beginning
my @shrink_list = reverse sort (@to_preserve);
- my @grow_list = ();
+ my @grow_list = ();
+
# iterate over the worklists
foreach my $part_id (@shrink_list)
{
+
# anything to be done?
- next unless (
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} == 1 );
+ next
+ unless (
+ $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} ==
+ 1 );
# get the existing id
my $mapped_id =
$FAI::configs{$config}{"partitions"}{$part_id}{"maps_to_existing"};
-
+
# if partition is to be grown, move it to then grow_list
if (
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} >
@@ -464,40 +524,43 @@
unshift @grow_list, $part_id;
next;
}
-
+
# get the new partition id
my $p = $FAI::current_config{$disk}{"partitions"}{$mapped_id}{"new_id"};
+
# get the new starts and ends
my $start =
$FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"};
- my $end =
- $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
+ my $end = $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
# build an appropriate command
push @FAI::commands,
- "$FAI::system_commands{'parted'} $disk resize $p $start"
- . "B " . $end . "B";
+ "$FAI::system_commands{'parted'} $disk resize $p $start" . "B " . $end
+ . "B";
}
+
# grow the remaining partitions
foreach my $part_id (@grow_list)
{
+
# get the existing id
my $mapped_id =
$FAI::configs{$config}{"partitions"}{$part_id}{"maps_to_existing"};
+
# get the new partition id
my $p = $FAI::current_config{$disk}{"partitions"}{$mapped_id}{"new_id"};
+
# get the new starts and ends
my $start =
$FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"};
- my $end =
- $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
+ my $end = $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
# build an appropriate command
push @FAI::commands,
- "$FAI::system_commands{'parted'} $disk resize $p $start"
- . "B " . $end . "B";
+ "$FAI::system_commands{'parted'} $disk resize $p $start" . "B " . $end
+ . "B";
}
-
+
# write the disklabel again to drop the partition table
push @FAI::commands, "$FAI::system_commands{'parted'} $disk mklabel "
. $FAI::configs{$config}{'disklabel'};
@@ -510,8 +573,7 @@
# get the new starts and ends
my $start =
$FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"};
- my $end =
- $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
+ my $end = $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"};
# the type of the partition defaults to primary
my $part_type = "primary";
@@ -531,33 +593,35 @@
}
# build a parted command to create the partition
- push @FAI::commands, "$FAI::system_commands{'parted'} $disk mkpart "
- . "$part_type $start" . "B " . $end . "B";
+ push @FAI::commands,
+ "$FAI::system_commands{'parted'} $disk mkpart "
+ . "$part_type $start" . "B "
+ . $end . "B";
}
-
+
# set the bootable flag, if requested at all
- push @FAI::commands, "$FAI::system_commands{'parted'} $disk set "
- . $FAI::configs{$config}{"bootable"} . " boot on" if
- ( $FAI::configs{$config}{"bootable"} > -1 );
-
+ push @FAI::commands,
+ "$FAI::system_commands{'parted'} $disk set "
+ . $FAI::configs{$config}{"bootable"}
+ . " boot on"
+ if ( $FAI::configs{$config}{"bootable"} > -1 );
+
# sleep a little to wait for udev to set up all devices
push @FAI::commands, "sleep 1";
}
# generate the commands for creating all filesystems
- foreach
- my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
+ foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
{
+
# skip preserved/resized/extended partitions
next
if (
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
- 1
- || $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} ==
- 1
+ $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} == 1
+ || $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"resize"} == 1
|| $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"extended"} ==
1 );
-
+
# create the filesystem on $disk$part_id
&FAI::build_mkfs_commands( $disk . $part_id,
\%{ $FAI::configs{$config}{"partitions"}{$part_id} } );
@@ -572,12 +636,14 @@
################################################################################
sub restore_partition_table
{
+
# loop through all existing configs
foreach my $disk ( keys %FAI::current_config )
{
+
# write the disklabel again to drop the partition table
&FAI::execute_command( "$FAI::system_commands{'parted'} $disk mklabel "
- . $FAI::current_config{$disk}{'disklabel'} );
+ . $FAI::current_config{$disk}{'disklabel'} );
# generate the commands for creating all partitions
foreach
@@ -587,8 +653,7 @@
# get the starts and ends
my $start =
$FAI::current_config{$disk}{"partitions"}{$part_id}{"begin_byte"};
- my $end =
- $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"};
+ my $end = $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"};
# the type of the partition defaults to primary
my $part_type = "primary";
@@ -596,8 +661,9 @@
{
# change the partition type to extended or logical as appropriate
- if ( $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"}
- == 1 )
+ if (
+ $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"} ==
+ 1 )
{
$part_type = "extended";
}
@@ -609,14 +675,15 @@
# build a parted command to create the partition
&FAI::execute_command( "$FAI::system_commands{'parted'} $disk mkpart "
- . "$part_type $start" . "B " . $end . "B" );
+ . "$part_type $start" . "B "
+ . $end
+ . "B" );
}
warn "Partition table of disk $disk has been restored\n";
}
-
+
die "shdd2 failed, but the partition tables have been restored\n";
}
-
1;
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-exec
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-exec 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-exec 2007-10-09 18:36:33 UTC (rev 4614)
@@ -79,23 +79,26 @@
{
error => "parted_4",
message => "parted not found\n",
- stderr_regex => ".*(parted: command not found|/sbin/parted: No such file or directory)",
+ stderr_regex =>
+ ".*(parted: command not found|/sbin/parted: No such file or directory)",
stdout_regex => "",
program => "parted",
response => "die"
},
{
- error => "parted_5",
- message => "Parted was unable to create the partition\n",
+ error => "parted_5",
+ message => "Parted was unable to create the partition\n",
stderr_regex => "Warning: You requested a partition from .* to .*\\.\$",
stdout_regex => "",
program => "parted",
response => \&FAI::restore_partition_table,
},
{
- error => "mkfs.xfs_1",
- message => "mkfs.xfs refused to create a filesystem. Probably you should add -f to the mkfs options in your disk_config file.\n",
- stderr_regex => "mkfs.xfs: /dev/.* appears to contain an existing filesystem",
+ error => "mkfs.xfs_1",
+ message =>
+"mkfs.xfs refused to create a filesystem. Probably you should add -f to the mkfs options in your disk_config file.\n",
+ stderr_regex =>
+ "mkfs.xfs: /dev/.* appears to contain an existing filesystem",
stdout_regex => "",
program => "mkfs.xfs",
response => "die",
@@ -115,8 +118,9 @@
{
my ($error) = @_;
my @treffer = grep { $_->{error} eq "$error" } @$FAI::error_codes;
+
# returns the first found error message.
- return $treffer[ 0 ]->{'message'};
+ return $treffer[0]->{'message'};
}
################################################################################
@@ -133,8 +137,9 @@
{
my ( $error, $field ) = @_;
my @treffer = grep { $_->{error} eq "$error" } @$FAI::error_codes;
+
# returns the first found error message.
- return $treffer[ 0 ]->{$field};
+ return $treffer[0]->{$field};
}
################################################################################
#
@@ -162,7 +167,7 @@
my $response = &get_error( $err, "response" );
my $message = &get_error( $err, "message" );
- $response->() if ( ref( $response ) );
+ $response->() if ( ref($response) );
die $message if ( $response eq "die" );
@@ -203,10 +208,12 @@
( my $stdout_fh, my $stdout_filename ) = File::Temp::tempfile( UNLINK => 1 );
# do only execute the given command, when in no_dry_mode
- if ( $FAI::no_dry_run )
+ if ($FAI::no_dry_run)
{
-
- ( $FAI::debug ) and print "(CMD) $command 1> $stdout_filename 2> $stderr_filename\n";
+
+ ($FAI::debug)
+ and print "(CMD) $command 1> $stdout_filename 2> $stderr_filename\n";
+
# execute the bash command, write stderr and stdout into the testfiles
`$command 1> $stdout_filename 2> $stderr_filename`;
}
@@ -223,8 +230,8 @@
close($stderr_fh);
close($stdout_fh);
- ( $FAI::debug ) and print "(STDERR) $_" foreach ( @stderr );
- ( $FAI::debug ) and print "(STDOUT) $_" foreach ( @stdout );
+ ($FAI::debug) and print "(STDERR) $_" foreach (@stderr);
+ ($FAI::debug) and print "(STDOUT) $_" foreach (@stdout);
#if the stderr contains information, get the first line for error recognition
$stderr_line = $stderr[0] if ( scalar(@stderr) > 0 );
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-fstab
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-fstab 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-fstab 2007-10-09 18:36:33 UTC (rev 4614)
@@ -40,7 +40,7 @@
# @brief this function generates the fstab file from our representation of the
# partitions to be created.
#
-# @reference config Reference to our representation of the partitions to be
+# @reference config Reference to our representation of the partitions to be
# created
#
# @return list of fstab lines
@@ -48,8 +48,9 @@
################################################################################
sub generate_fstab
{
+
# config structure is the only input
- my ( $config ) = @_;
+ my ($config) = @_;
# the file to be returned, a list of lines
my @fstab = ();
@@ -58,148 +59,191 @@
# the order of entries is most likely wrong, it is fixed at the end
foreach my $c ( keys %$config )
{
+
# entry is a physical device
if ( $c =~ /^PHY_(.+)$/ )
{
my $device = $1;
+
# make sure the desired fstabkey is defined at all
- defined( $config->{$c}->{"fstabkey"} ) or die
- "INTERNAL ERROR: fstabkey undefined\n";
+ defined( $config->{$c}->{"fstabkey"} )
+ or die "INTERNAL ERROR: fstabkey undefined\n";
+
# create a line in the output file for each partition
foreach my $p ( sort keys %{ $config->{$c}->{"partitions"} } )
{
+
# keep a reference to save some typing
my $p_ref = $config->{$c}->{"partitions"}->{$p};
+
# skip extended partitions
next if ( $p_ref->{"size"}->{"extended"} );
+
# skip entries without a mountpoint
next if ( $p_ref->{"mountpoint"} eq "-" );
+
# each line is a list of values
my @fstab_line = ();
+
# write the device name as the first entry; if the user prefers uuids
# or labels, use these if available
my @uuid = ();
- &execute_command_std( "/lib/udev/vol_id -u $device" .
- $p_ref->{"number"}, \@uuid, 0 );
+ &execute_command_std(
+ "/lib/udev/vol_id -u $device" . $p_ref->{"number"},
+ \@uuid, 0 );
+
# every device must have a uuid, otherwise this is an error (unless we
# are testing only)
- ( $FAI::no_dry_run == 0 || scalar( @uuid ) == 1 ) or die
- "Failed to obtain UUID for $device" . $p_ref->{"number"} . "\n";
+ ( $FAI::no_dry_run == 0 || scalar(@uuid) == 1 )
+ or die "Failed to obtain UUID for $device"
+ . $p_ref->{"number"} . "\n";
+
# get the label -- this is likely empty
my @label = ();
- &execute_command_std( "/lib/udev/vol_id -l $device" .
- $p_ref->{"number"}, \@label, 0 );
+ &execute_command_std(
+ "/lib/udev/vol_id -l $device" . $p_ref->{"number"},
+ \@label, 0 );
+
# using the fstabkey value the desired device entry is defined
if ( $config->{$c}->{"fstabkey"} eq "uuid" )
{
- chomp( $uuid[ 0 ] );
- push @fstab_line, "UUID=" . $uuid[ 0 ];
+ chomp( $uuid[0] );
+ push @fstab_line, "UUID=" . $uuid[0];
}
- elsif ( $config->{$c}->{"fstabkey"} eq "label" && scalar( @label ) == 1 )
+ elsif ( $config->{$c}->{"fstabkey"} eq "label" && scalar(@label) == 1 )
{
- chomp( $label[ 0 ] );
- push @fstab_line, "LABEL=" . $label[ 0 ];
+ chomp( $label[0] );
+ push @fstab_line, "LABEL=" . $label[0];
}
else
{
+
# otherwise, use the usual device path
push @fstab_line, $device . $p_ref->{"number"};
}
+
# next is the mountpoint
push @fstab_line, $p_ref->{"mountpoint"};
+
# the filesystem to be used
push @fstab_line, $p_ref->{"filesystem"};
+
# add the mount options
push @fstab_line, $p_ref->{"mount_options"};
+
# never dump
push @fstab_line, 0;
+
# order of filesystem checks; the root filesystem gets a 1, the others 2
push @fstab_line, 2;
$fstab_line[-1] = 1 if ( $p_ref->{"mountpoint"} eq "/" );
- # join the columns of one line with tabs, and push it to our fstab line array
+ # join the columns of one line with tabs, and push it to our fstab line array
push @fstab, join( "\t", @fstab_line );
-
- # set the ROOT_PARTITION variable, if this is the mountpoint for /
-# $FAI::disk_var{ "ROOT_PARTITION" } = $device . $p_ref->{"number"}
- $FAI::disk_var{ "ROOT_PARTITION" } = $fstab_line[0]
- if ( $p_ref->{"mountpoint"} eq "/" );
+
+ # set the ROOT_PARTITION variable, if this is the mountpoint for /
+ # $FAI::disk_var{ "ROOT_PARTITION" } = $device . $p_ref->{"number"}
+ $FAI::disk_var{"ROOT_PARTITION"} = $fstab_line[0]
+ if ( $p_ref->{"mountpoint"} eq "/" );
+
# add to the swaplist, if the filesystem is swap
- $FAI::disk_var{ "SWAPLIST" } .= " " . $device . $p_ref->{"number"} if (
- $p_ref->{"filesystem"} eq "swap" );
+ $FAI::disk_var{"SWAPLIST"} .= " " . $device . $p_ref->{"number"}
+ if ( $p_ref->{"filesystem"} eq "swap" );
}
}
elsif ( $c =~ /^VG_(.+)$/ )
{
my $device = $1;
+
# create a line in the output file for each logical volume
foreach my $l ( sort keys %{ $config->{$c}->{"volumes"} } )
{
+
# keep a reference to save some typing
my $l_ref = $config->{$c}->{"volumes"}->{$l};
+
# skip entries without a mountpoint
next if ( $l_ref->{"mountpoint"} eq "-" );
+
# each line is a list of values
my @fstab_line = ();
+
# write the logical volume path as the first entry
push @fstab_line, "/dev/$device/$l";
+
# next is the mountpoint
push @fstab_line, $l_ref->{"mountpoint"};
+
# the filesystem to be used
push @fstab_line, $l_ref->{"filesystem"};
+
# add the mount options
push @fstab_line, $l_ref->{"mount_options"};
+
# never dump
push @fstab_line, 0;
+
# order of filesystem checks; the root filesystem gets a 1, the others 2
push @fstab_line, 2;
$fstab_line[-1] = 1 if ( $l_ref->{"mountpoint"} eq "/" );
- # join the columns of one line with tabs, and push it to our fstab line array
+ # join the columns of one line with tabs, and push it to our fstab line array
push @fstab, join( "\t", @fstab_line );
-
+
# set the ROOT_PARTITION variable, if this is the mountpoint for /
- $FAI::disk_var{ "ROOT_PARTITION" } = "/dev/$device/$l" if ( $l_ref->{"mountpoint"} eq
- "/" );
+ $FAI::disk_var{"ROOT_PARTITION"} = "/dev/$device/$l"
+ if ( $l_ref->{"mountpoint"} eq "/" );
+
# add to the swaplist, if the filesystem is swap
- $FAI::disk_var{ "SWAPLIST" } .= " /dev/$device/$l" if (
- $l_ref->{"filesystem"} eq "swap" );
+ $FAI::disk_var{"SWAPLIST"} .= " /dev/$device/$l"
+ if ( $l_ref->{"filesystem"} eq "swap" );
}
}
elsif ( $c eq "RAID" )
{
+
# create a line in the output file for each device
foreach my $r ( sort keys %{ $config->{$c}->{"volumes"} } )
{
+
# keep a reference to save some typing
my $r_ref = $config->{$c}->{"volumes"}->{$r};
+
# skip entries without a mountpoint
next if ( $r_ref->{"mountpoint"} eq "-" );
+
# each line is a list of values
my @fstab_line = ();
+
# write the device name as the first entry
push @fstab_line, "/dev/md" . $r;
+
# next is the mountpoint
push @fstab_line, $r_ref->{"mountpoint"};
+
# the filesystem to be used
push @fstab_line, $r_ref->{"filesystem"};
+
# add the mount options
push @fstab_line, $r_ref->{"mount_options"};
+
# never dump
push @fstab_line, 0;
+
# order of filesystem checks; the root filesystem gets a 1, the others 2
push @fstab_line, 2;
$fstab_line[-1] = 1 if ( $r_ref->{"mountpoint"} eq "/" );
- # join the columns of one line with tabs, and push it to our fstab line array
+ # join the columns of one line with tabs, and push it to our fstab line array
push @fstab, join( "\t", @fstab_line );
-
+
# set the ROOT_PARTITION variable, if this is the mountpoint for /
- $FAI::disk_var{ "ROOT_PARTITION" } = "/dev/md" . $r if ( $r_ref->{"mountpoint"} eq
- "/" );
+ $FAI::disk_var{"ROOT_PARTITION"} = "/dev/md" . $r
+ if ( $r_ref->{"mountpoint"} eq "/" );
+
# add to the swaplist, if the filesystem is swap
- $FAI::disk_var{ "SWAPLIST" } .= " /dev/md$r" if (
- $r_ref->{"filesystem"} eq "swap" );
+ $FAI::disk_var{"SWAPLIST"} .= " /dev/md$r"
+ if ( $r_ref->{"filesystem"} eq "swap" );
}
}
else
@@ -209,40 +253,47 @@
}
# cleanup the swaplist (remove leading space)
- $FAI::disk_var{ "SWAPLIST" } =~ s/^\s+//;
+ $FAI::disk_var{"SWAPLIST"} =~ s/^\s+//;
+
# quote the entries of SWAPLIST
- $FAI::disk_var{ "SWAPLIST" } = '"' . $FAI::disk_var{ "SWAPLIST" } . '"';
+ $FAI::disk_var{"SWAPLIST"} = '"' . $FAI::disk_var{"SWAPLIST"} . '"';
# sort the lines in @fstab to enable all sub mounts
- for ( my $i = 0; $i < scalar( @fstab ); $i++ )
+ for ( my $i = 0 ; $i < scalar(@fstab) ; $i++ )
{
+
# take out the mountpoint
- ($_, my $mp_1) = split( "\t", $fstab[ $i ] );
+ ( $_, my $mp_1 ) = split( "\t", $fstab[$i] );
+
# partitions without a mountpoint are fine
next if ( $mp_1 eq "none" );
- for ( my $j = $i + 1; $j < scalar( @fstab ); $j++ )
+ for ( my $j = $i + 1 ; $j < scalar(@fstab) ; $j++ )
{
+
# take out the other mountpoint
- ($_, my $mp_2) = split( "\t", $fstab[ $j ] );
+ ( $_, my $mp_2 ) = split( "\t", $fstab[$j] );
+
# remove the trailing / (even though this might make it the empty string
$mp_2 =~ s/\/$//;
# $mp_1 depends on $mp_2 being mounted, swap them
if ( $mp_1 =~ /^\Q$mp_2\E\// )
{
- my $line_i = $fstab[ $i ];
- $fstab[ $i ] = $fstab[ $j ];
- $fstab[ $j ] = $line_i;
- $mp_1 = $mp_2;
+ my $line_i = $fstab[$i];
+ $fstab[$i] = $fstab[$j];
+ $fstab[$j] = $line_i;
+ $mp_1 = $mp_2;
}
}
}
# add a nice header to fstab
- unshift @fstab, "# <file sys>\t<mount point>\t<type>\t<options>\t<dump>\t<pass>";
+ unshift @fstab,
+ "# <file sys>\t<mount point>\t<type>\t<options>\t<dump>\t<pass>";
unshift @fstab, "#";
unshift @fstab, "# /etc/fstab: static file system information.";
+
# return the list of lines
return @fstab;
}
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-init
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-init 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-init 2007-10-09 18:36:33 UTC (rev 4614)
@@ -57,7 +57,7 @@
#
################################################################################
%FAI::disk_var = ();
-$FAI::disk_var{ "SWAPLIST" } = "";
+$FAI::disk_var{"SWAPLIST"} = "";
################################################################################
#
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-parser
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-parser 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-parser 2007-10-09 18:36:33 UTC (rev 4614)
@@ -150,7 +150,7 @@
{
# $disk-1 must be a valid index in the map of all disks in the system
- ( scalar( @FAI::disks ) >= $disk )
+ ( scalar(@FAI::disks) >= $disk )
or die "this system does not have a physical disk $disk\n";
# fetch the (short) device name
@@ -667,7 +667,7 @@
################################################################################
sub run_parser
{
- my ( $IN ) = @_;
+ my ($IN) = @_;
# read <$IN> to a single string (not a list), thus $/ has to be unset
my $ifs = $/;
@@ -679,8 +679,8 @@
( $FAI::debug > 0 ) and print "Input was:\n" . $input;
# check for old-style configuration files
- ( $input =~ m{(^|\n)[^\n#]+;} ) and die
- "Old style configuration files are not supported\n";
+ ( $input =~ m{(^|\n)[^\n#]+;} )
+ and die "Old style configuration files are not supported\n";
# attempt to parse $input - any error will lead to termination
defined $FAI::Parser->file($input) or die "Syntax error\n";
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-sizes
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-sizes 2007-10-09 18:36:33 UTC (rev 4614)
@@ -49,82 +49,94 @@
################################################################################
sub estimate_size
{
- my ( $dev ) = @_;
+ my ($dev) = @_;
# try the entire disk first; we then use the data from the current
# configuration; this matches in fact for than the allowable strings, but
# this should be caught later on
if ( $dev =~ /^\/dev\/[sh]d[a-z]$/ )
{
- defined( $FAI::current_config{$dev}{"end_byte"} ) or die
- "$dev is not a valid block device\n";
+ defined( $FAI::current_config{$dev}{"end_byte"} )
+ or die "$dev is not a valid block device\n";
# the size is known, return it
return ( $FAI::current_config{$dev}{"end_byte"} -
- $FAI::current_config{$dev}{"begin_byte"} ) / ( 1024 * 1024 );
+ $FAI::current_config{$dev}{"begin_byte"} ) / ( 1024 * 1024 );
}
+
# try a partition
elsif ( $dev =~ /^(\/dev\/[sh]d[a-z])(\d+)$/ )
{
+
# the size is configured, return it
- defined( $FAI::configs{"PHY_$1"}{"partitions"}{$2}{"size"}{"eff_size"} ) and
- return $FAI::configs{"PHY_$1"}{"partitions"}{$2}{"size"}{"eff_size"} / ( 1024 * 1024 );
+ defined( $FAI::configs{"PHY_$1"}{"partitions"}{$2}{"size"}{"eff_size"} )
+ and return $FAI::configs{"PHY_$1"}{"partitions"}{$2}{"size"}{"eff_size"} /
+ ( 1024 * 1024 );
+
# the size is known from the current configuration on disk, return it
- defined( $FAI::current_config{$1}{"partitions"}{$2}{"count_byte"} ) and
- return $FAI::current_config{$1}{"partitions"}{$2}{"count_byte"} / ( 1024 * 1024 );
+ defined( $FAI::current_config{$1}{"partitions"}{$2}{"count_byte"} )
+ and return $FAI::current_config{$1}{"partitions"}{$2}{"count_byte"} /
+ ( 1024 * 1024 );
+
# the size is not known (yet?)
die "Cannot determine size of $dev\n";
}
+
# try RAID; estimations here are very limited and possible imprecise
elsif ( $dev =~ /^\/dev\/md(\d+)$/ )
{
+
# the list of underlying devices
my @devs = ();
+
# the raid level, like raid0, raid5, linear, etc.
my $level = "";
# let's see, whether there is a configuration of this volume
if ( defined( $FAI::configs{"RAID"}{"volumes"}{$1}{"devices"} ) )
{
- @devs = keys %{ $FAI::configs{"RAID"}{"volumes"}{$1}{"devices"} };
+ @devs = keys %{ $FAI::configs{"RAID"}{"volumes"}{$1}{"devices"} };
$level = $FAI::configs{"RAID"}{"volumes"}{$1}{"mode"};
}
- elsif( defined( $FAI::current_raid_config{$1}{"devices"} ) )
+ elsif ( defined( $FAI::current_raid_config{$1}{"devices"} ) )
{
- @devs = $FAI::current_raid_config{$1}{"devices"};
+ @devs = $FAI::current_raid_config{$1}{"devices"};
$level = $FAI::current_raid_config{$1}{"mode"};
}
else
{
die "$dev is not a known RAID device\n";
}
-
+
# prepend "raid", if the mode is numeric-only
$level = "raid" . $level if ( $level =~ /^\d+$/ );
-
+
# the number of devices in the volume
- my $dev_count = scalar( @devs );
+ my $dev_count = scalar(@devs);
# now do the mode-specific size estimations
if ( $level =~ /^raid[015]$/ )
{
my $min_size = &estimate_size( shift @devs );
- foreach ( @devs )
+ foreach (@devs)
{
- my $s = &estimate_size( $_ );
+ my $s = &estimate_size($_);
$min_size = $s if ( $s < $min_size );
}
- return $min_size * POSIX::floor( $dev_count / 2 ) if ( $level eq "raid1" );
+ return $min_size * POSIX::floor( $dev_count / 2 )
+ if ( $level eq "raid1" );
return $min_size * $dev_count if ( $level eq "raid0" );
return $min_size * ( $dev_count - 1 ) if ( $level eq "raid5" );
}
else
{
+
# probably some more should be implemented
die "Don't know how to estimate the size of a $level device\n";
}
}
+
# otherwise we are clueless
else
{
@@ -139,31 +151,36 @@
################################################################################
sub compute_lv_sizes
{
+
# loop through all device configurations
foreach my $config ( keys %FAI::configs )
{
+
# for RAID, there is nothing to be done here
next if ( $config eq "RAID" );
+
# device is an effective disk
next if ( $config =~ /^PHY_(.+)$/ );
-
+
# configure a volume group
- ( $config =~ /^VG_(.+)$/ ) or die
- "INTERNAL ERROR: invalid config entry $config.\n";
-
+ ( $config =~ /^VG_(.+)$/ )
+ or die "INTERNAL ERROR: invalid config entry $config.\n";
+
# the volume group name
my $vg = $1;
-
+
# compute the size of the volume group; this is not exact, but should at
# least give a rough estimation, we assume 1 % of overhead; the value is
# stored in megabytes
my $vg_size = 0;
foreach my $dev ( keys %{ $FAI::configs{$config}{"devices"} } )
{
+
# $dev may be a partition, an entire disk or a RAID device; otherwise we
# cannot deal with it
- $vg_size += &estimate_size( $dev );
+ $vg_size += &estimate_size($dev);
}
+
# now subtract 1% of overhead
$vg_size *= 0.99;
@@ -172,14 +189,14 @@
# the minimum space required in this volume group
my $min_space = 0;
-
+
# the maximum space used in this volume group
my $max_space = 0;
-
+
# set effective sizes where available
- foreach
- my $lv ( keys %{ $FAI::configs{$config}{"volumes"} } )
+ foreach my $lv ( keys %{ $FAI::configs{$config}{"volumes"} } )
{
+
# make sure the size specification is a range (even though it might be
# something like x-x) and store the dimensions
( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"range"} =~
@@ -189,10 +206,10 @@
my $end = $2;
# start may be given in percents of the size, rewrite it to megabytes
- $start = POSIX::floor( $vg_size * $1 / 100 ) if ( $start =~ /^(\d+)%$/);
+ $start = POSIX::floor( $vg_size * $1 / 100 ) if ( $start =~ /^(\d+)%$/ );
# end may be given in percents of the size, rewrite it to megabytes
- $end = POSIX::ceil( $vg_size * $1 / 100 ) if ( $end =~ /^(\d+)%$/);
+ $end = POSIX::ceil( $vg_size * $1 / 100 ) if ( $end =~ /^(\d+)%$/ );
# make sure that $end >= $start
( $end >= $start ) or die "INTERNAL ERROR: end < start\n";
@@ -200,35 +217,38 @@
# increase the used space
$min_space += $start;
$max_space += $end;
-
+
# write back the range in MB
$FAI::configs{$config}{"volumes"}{$lv}{"size"}{"range"} = "$start-$end";
-
+
# the size is fixed
if ( $start == $end )
{
+
# write the size back to the configuration
$FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} = $start;
}
else
{
+
# add this volume to the redistribution list
push @redist_list, $lv;
}
}
# test, whether the configuration fits on the volume group at all
- ( $min_space < $vg_size ) or die
- "Volume group $vg requires $min_space MB\n";
+ ( $min_space < $vg_size )
+ or die "Volume group $vg requires $min_space MB\n";
# the extension factor
my $redist_factor = 0;
- $redist_factor = ( $vg_size - $min_space ) / ( $max_space - $min_space ) if
- ( $max_space > $min_space );
+ $redist_factor = ( $vg_size - $min_space ) / ( $max_space - $min_space )
+ if ( $max_space > $min_space );
# update all sizes that are still ranges
- foreach my $lv ( @redist_list )
+ foreach my $lv (@redist_list)
{
+
# get the range again
( $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"range"} =~
/^(\d+%?)-(\d+%?)$/ )
@@ -237,8 +257,8 @@
my $end = $2;
# write the final size
- $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} = $start + ( (
- $end - $start ) * $redist_factor );
+ $FAI::configs{$config}{"volumes"}{$lv}{"size"}{"eff_size"} =
+ $start + ( ( $end - $start ) * $redist_factor );
}
}
}
@@ -255,35 +275,38 @@
# loop through all device configurations
foreach my $config ( keys %FAI::configs )
{
+
# for RAID, there is nothing to be done here
next if ( $config eq "RAID" );
+
# don't configure the sizes of logical volumes here
next if ( $config =~ /^VG_(.+)$/ );
# device is an effective disk
- ( $config =~ /^PHY_(.+)$/ ) or die
- "INTERNAL ERROR: invalid config entry $config.\n";
-
+ ( $config =~ /^PHY_(.+)$/ )
+ or die "INTERNAL ERROR: invalid config entry $config.\n";
+
# nothing to be done, if this is a configuration for a virtual disk
next if ( $FAI::configs{$config}{"virtual"} == 1 );
# the device name of the disk
my $disk = $1;
-
- # at various points the following code highly depends on the desired disk label!
- # initialise variables
- # the id of the extended partition to be created, if required
+
+# at various points the following code highly depends on the desired disk label!
+# initialise variables
+# the id of the extended partition to be created, if required
my $extended = -1;
# the id of the current extended partition, if any; this setup only caters
# for a single existing extended partition!
my $current_extended = -1;
-
+
# find the first existing extended partition
foreach
my $part_id ( sort keys %{ $FAI::current_config{$disk}{"partitions"} } )
{
- if ( 1 == $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"} )
+ if ( 1 ==
+ $FAI::current_config{$disk}{"partitions"}{$part_id}{"is_extended"} )
{
$current_extended = $part_id;
last;
@@ -295,7 +318,7 @@
# the start byte for the next partition
my $next_start = 0;
-
+
# on msdos disk labels, the first partitions starts at head #1
if ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
{
@@ -303,7 +326,8 @@
$FAI::current_config{$disk}{"sector_size"};
# the MBR requires space, too
- $min_req_total_space += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $min_req_total_space +=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
}
@@ -311,26 +335,27 @@
if ( $FAI::configs{$config}{"disklabel"} eq "gpt" )
{
$next_start = 34 * $FAI::current_config{$disk}{"sector_size"};
-
+
# modify the disk to claim the space for the second partition table
- $FAI::current_config{$disk}{"end_byte"} -= 34 *
- $FAI::current_config{$disk}{"sector_size"};
-
- # the space required by the GPTs
- $min_req_total_space += 2 * 34 * $FAI::current_config{$disk}{"sector_size"};
+ $FAI::current_config{$disk}{"end_byte"} -=
+ 34 * $FAI::current_config{$disk}{"sector_size"};
+
+ # the space required by the GPTs
+ $min_req_total_space +=
+ 2 * 34 * $FAI::current_config{$disk}{"sector_size"};
}
# the list of partitions that we need to find start and end bytes for
my @worklist = ( sort keys %{ $FAI::configs{$config}{"partitions"} } );
- while ( scalar( @worklist ) > 0 )
+ while ( scalar(@worklist) > 0 )
{
+
# work on the first entry of the list
- my $part_id = $worklist[ 0 ];
+ my $part_id = $worklist[0];
# the partition $part_id must be preserved
- if (
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
+ if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"preserve"} ==
1 )
{
@@ -339,9 +364,9 @@
or die "$part_id can't be preserved, it does not exist.\n";
( $next_start >
- $FAI::current_config{$disk}{"partitions"}{$part_id}{"begin_byte"} )
- and die
- "Previous partitions overflow begin of preserved partition $part_id\n";
+ $FAI::current_config{$disk}{"partitions"}{$part_id}{"begin_byte"} )
+ and die
+"Previous partitions overflow begin of preserved partition $part_id\n";
# set the effective size to the value known already
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
@@ -360,63 +385,80 @@
# set the next start
$next_start =
$FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} + 1;
-
+
# several msdos specific parts
if ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
{
# make sure the partition ends at a cylinder boundary
- ( 0 == ( $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"} + 1 ) %
- ( $FAI::current_config{$disk}{"sector_size"} *
- $FAI::current_config{$disk}{"bios_sectors_per_track"} *
- $FAI::current_config{$disk}{"bios_heads"} ) ) or die
- "Preserved partition $part_id does not end at a cylinder boundary\n";
+ (
+ 0 == (
+ $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"} +
+ 1
+ ) % (
+ $FAI::current_config{$disk}{"sector_size"} *
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $FAI::current_config{$disk}{"bios_heads"}
+ )
+ )
+ or die
+"Preserved partition $part_id does not end at a cylinder boundary\n";
# add one head of disk usage if this is a logical partition
- $min_req_total_space += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
- $FAI::current_config{$disk}{"sector_size"} if ( $part_id > 4);
+ $min_req_total_space +=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $FAI::current_config{$disk}{"sector_size"}
+ if ( $part_id > 4 );
# extended partitions consume no space
- if (
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"extended"} ==
- 1 )
+ if ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+ {"extended"} == 1 )
{
+
# revert the addition of the size
$min_req_total_space -=
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
+ $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+ {"eff_size"};
# set the next start to the start of the extended partition
$next_start =
$FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"};
}
- }
-
+ }
+
# on gpt, ensure that the partition ends at a sector boundary
if ( $FAI::configs{$config}{"disklabel"} eq "gpt" )
{
- ( 0 == ( $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"} + 1 ) %
- $FAI::current_config{$disk}{"sector_size"} ) or die
+ (
+ 0 == (
+ $FAI::current_config{$disk}{"partitions"}{$part_id}{"end_byte"} +
+ 1
+ ) % $FAI::current_config{$disk}{"sector_size"}
+ )
+ or die
"Preserved partition $part_id does not end at a sector boundary\n";
}
# partition done
shift @worklist;
}
+
# msdos specific: deal with extended partitions
elsif (
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"extended"} ==
1 )
{
- ( $FAI::configs{$config}{"disklabel"} eq "msdos" ) or die
- "found an extended partition on a non-msdos disklabel\n";
+ ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
+ or die "found an extended partition on a non-msdos disklabel\n";
# make sure that there is only one extended partition
- ( $extended == -1 || 1 == scalar( @worklist ) )
+ ( $extended == -1 || 1 == scalar(@worklist) )
or die "INTERNAL ERROR: More than 1 extended partition\n";
# ensure that it is a primary partition
- ( $part_id <= 4 ) or die
+ ( $part_id <= 4 )
+ or die
"INTERNAL ERROR: Extended partition wouldn't be a primary one\n";
# set the local variable to this id
@@ -425,18 +467,21 @@
# the size cannot be determined now, push it to the end of the
# worklist; the check against $extended being == -1 ensures that
# there is no indefinite loop
- if( scalar( @worklist ) > 1 )
+ if ( scalar(@worklist) > 1 )
{
push @worklist, shift @worklist;
}
+
# determine the size of the extended partition
else
{
- my $epbr_size = $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ my $epbr_size =
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
-
+
# initialise the size and the start byte
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} = 0;
+ $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} =
+ 0;
$FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"} = -1;
foreach my $p ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
@@ -450,25 +495,27 @@
$FAI::configs{$config}{"partitions"}{$p}{"start_byte"} -
$epbr_size;
}
-
- $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} +=
+
+ $FAI::configs{$config}{"partitions"}{$part_id}{"size"}
+ {"eff_size"} +=
$FAI::configs{$config}{"partitions"}{$p}{"size"}{"eff_size"} +
$epbr_size;
-
+
$FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} =
$FAI::configs{$config}{"partitions"}{$p}{"end_byte"};
}
-
- ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"}
- > 0 ) or die
- "Extended partition has a size of 0\n";
-
+
+ ( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"} >
+ 0 )
+ or die "Extended partition has a size of 0\n";
+
# partition done
shift @worklist;
}
}
else
{
+
# make sure the size specification is a range (even though it might be
# something like x-x) and store the dimensions
( $FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =~
@@ -482,8 +529,8 @@
{
# rewrite it to bytes
- $start = POSIX::floor(
- $FAI::current_config{$disk}{"size"} * $1 / 100 );
+ $start =
+ POSIX::floor( $FAI::current_config{$disk}{"size"} * $1 / 100 );
}
else
{
@@ -497,8 +544,7 @@
{
# rewrite it to bytes
- $end =
- POSIX::ceil( $FAI::current_config{$disk}{"size"} * $1 / 100 );
+ $end = POSIX::ceil( $FAI::current_config{$disk}{"size"} * $1 / 100 );
}
else
{
@@ -506,56 +552,61 @@
# it is given in megabytes, make it bytes
$end = $end * 1024.0 * 1024.0;
}
-
+
# make sure that $end >= $start
( $end >= $start ) or die "INTERNAL ERROR: end < start\n";
# check, whether the size is fixed
if ( $end != $start )
{
+
# the end of the current range (may be the end of the disk or some
# preserved partition
my $end_of_range = -1;
- # minimum space required by all partitions, i.e., the lower ends of the
- # ranges
- # $min_req_space counts up to the next preserved partition or the
- # end of the disk
+ # minimum space required by all partitions, i.e., the lower ends of the
+ # ranges
+ # $min_req_space counts up to the next preserved partition or the
+ # end of the disk
my $min_req_space = 0;
# maximum useful space
my $max_space = 0;
# inspect all remaining entries in the worklist
- foreach my $p ( @worklist )
+ foreach my $p (@worklist)
{
+
# we have found the delimiter
- if (
- $FAI::configs{$config}{"partitions"}{$p}{"size"}{"preserve"} ==
+ if ( $FAI::configs{$config}{"partitions"}{$p}{"size"}{"preserve"} ==
1 )
{
- $end_of_range =
+ $end_of_range =
$FAI::current_config{$disk}{"partitions"}{$p}{"begin_byte"};
+
# logical partitions require the space for the EPBR to be left
# out
- if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" ) &&
- ( $p > 4 ) )
+ if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
+ && ( $p > 4 ) )
{
- $end_of_range -= $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $end_of_range -=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
}
last;
}
- elsif (
- $FAI::configs{$config}{"partitions"}{$p}{"size"}{"extended"} == 1 )
+ elsif (
+ $FAI::configs{$config}{"partitions"}{$p}{"size"}{"extended"} ==
+ 1 )
{
next;
}
else
{
- # below is a slight duplication of the code
- # make sure the size specification is a range (even though it might be
- # something like x-x) and store the dimensions
+
+ # below is a slight duplication of the code
+ # make sure the size specification is a range (even though it might be
+ # something like x-x) and store the dimensions
( $FAI::configs{$config}{"partitions"}{$p}{"size"}{"range"} =~
/^(\d+%?)-(\d+%?)$/ )
or die "INTERNAL ERROR: Invalid range\n";
@@ -567,7 +618,8 @@
{
# rewrite it to bytes
- $min_size = POSIX::floor(
+ $min_size =
+ POSIX::floor(
$FAI::current_config{$disk}{"size"} * $1 / 100 );
}
else
@@ -576,7 +628,7 @@
# it is given in megabytes, make it bytes
$min_size *= 1024.0 * 1024.0;
}
-
+
# end may be given in percents of the size
if ( $max_size =~ /^(\d+)%$/ )
{
@@ -594,51 +646,61 @@
# logical partitions require the space for the EPBR to be left
# out
- if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" ) &&
- ( $p > 4 ) )
+ if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
+ && ( $p > 4 ) )
{
- $min_size += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $min_size +=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
- $max_size += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $max_size +=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
}
$min_req_space += $min_size;
- $max_space += $max_size;
+ $max_space += $max_size;
}
}
# set the end if we have reached the end of the disk
- $end_of_range = $FAI::current_config{$disk}{"end_byte"} if ( -1 ==
- $end_of_range );
+ $end_of_range = $FAI::current_config{$disk}{"end_byte"}
+ if ( -1 == $end_of_range );
my $available_space = $end_of_range - $next_start + 1;
# the next boundary is closer than the minimal space that we need
- ( $available_space < $min_req_space ) and die
- "Insufficient space available for partition $part_id\n";
-
+ ( $available_space < $min_req_space )
+ and die "Insufficient space available for partition $part_id\n";
+
# the new size
my $scaled_size = $end;
- $scaled_size = POSIX::floor( ( $end - $start ) * ( ( $available_space -
- $min_req_space ) / ( $max_space - $min_req_space ) ) ) +
- $start if ( $max_space > $available_space );
+ $scaled_size = POSIX::floor(
+ ( $end - $start ) * (
+ ( $available_space - $min_req_space ) /
+ ( $max_space - $min_req_space )
+ )
+ ) + $start
+ if ( $max_space > $available_space );
- ( $scaled_size >= $start ) or die
+ ( $scaled_size >= $start )
+ or die
"INTERNAL ERROR: scaled size is smaller than the desired minimum\n";
$start = $scaled_size;
- $end = $start;
+ $end = $start;
}
-
+
# now we compute the effective locations on the disk
# msdos specific offset for logical partitions
- if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" ) &&
- ( $part_id > 4 ) )
+ if ( ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
+ && ( $part_id > 4 ) )
{
+
# add one head of disk usage if this is a logical partition
- $min_req_total_space += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
+ $min_req_total_space +=
+ $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
+
# move the start byte as well
$next_start += $FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"sector_size"};
@@ -654,8 +716,8 @@
# on msdos, ensure that the partition ends at a cylinder boundary
if ( $FAI::configs{$config}{"disklabel"} eq "msdos" )
{
- $end_byte -= ( $end_byte + 1 ) %
- ( $FAI::current_config{$disk}{"sector_size"} *
+ $end_byte -=
+ ( $end_byte + 1 ) % ( $FAI::current_config{$disk}{"sector_size"} *
$FAI::current_config{$disk}{"bios_sectors_per_track"} *
$FAI::current_config{$disk}{"bios_heads"} );
}
@@ -663,14 +725,14 @@
# on gpt, ensure that the partition ends at a sector boundary
if ( $FAI::configs{$config}{"disklabel"} eq "gpt" )
{
- $end_byte -= ( $end_byte + 1 ) %
- $FAI::current_config{$disk}{"sector_size"};
+ $end_byte -=
+ ( $end_byte + 1 ) % $FAI::current_config{$disk}{"sector_size"};
}
# set $start and $end to the effective values
$start = $end_byte - $next_start + 1;
- $end = $start;
-
+ $end = $start;
+
# write back the size spec in bytes
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"range"} =
$start . "-" . $end;
@@ -680,9 +742,8 @@
$start;
# write the end byte to the configuration
- $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} =
- $end_byte;
-
+ $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} = $end_byte;
+
# and add it to the total disk space required by this config
$min_req_total_space +=
$FAI::configs{$config}{"partitions"}{$part_id}{"size"}{"eff_size"};
@@ -690,7 +751,7 @@
# set the next start
$next_start =
$FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} + 1;
-
+
# partition done
shift @worklist;
}
@@ -699,19 +760,19 @@
# check, whether there is sufficient space on the disk
( $min_req_total_space > $FAI::current_config{$disk}{"size"} )
and die
- "Disk $disk is too small - at least $min_req_total_space bytes are required\n";
+"Disk $disk is too small - at least $min_req_total_space bytes are required\n";
# make sure, extended partitions are only created on msdos disklabels
( $FAI::configs{$config}{"disklabel"} ne "msdos" && $extended > -1 )
and die
- "INTERNAL ERROR: extended partitions are not supported by this disklabel\n";
+"INTERNAL ERROR: extended partitions are not supported by this disklabel\n";
# ensure that we have done our work
- foreach
- my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
+ foreach my $part_id ( sort keys %{ $FAI::configs{$config}{"partitions"} } )
{
- ( defined( $FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"} ) &&
- defined( $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} ) )
+ ( defined( $FAI::configs{$config}{"partitions"}{$part_id}{"start_byte"} )
+ && defined(
+ $FAI::configs{$config}{"partitions"}{$part_id}{"end_byte"} ) )
or die "INTERNAL ERROR: start or end of partition $part_id not set\n";
}
Modified: people/michael/features/setup_harddisks_2/implementation/shdd2-volumes
===================================================================
--- people/michael/features/setup_harddisks_2/implementation/shdd2-volumes 2007-10-09 15:49:55 UTC (rev 4613)
+++ people/michael/features/setup_harddisks_2/implementation/shdd2-volumes 2007-10-09 18:36:33 UTC (rev 4614)
@@ -82,15 +82,17 @@
{
# if there is no disk configuration, write an msdos disklabel
- if ( ! defined( $FAI::configs{$disk}{"disklabel"} ) )
+ if ( !defined( $FAI::configs{$disk}{"disklabel"} ) )
{
+
# write the disk label as configured
$error =
- &FAI::execute_command( $FAI::system_commands{"parted"}
- . " $disk mklabel msdos" );
+ &FAI::execute_command(
+ $FAI::system_commands{"parted"} . " $disk mklabel msdos" );
}
else
{
+
# write the disk label as configured
$error =
&FAI::execute_command( $FAI::system_commands{"parted"}
@@ -154,7 +156,7 @@
# 3 1077511680B 13662190079B 12584678400B primary ext3 boot
# 4 13662190080B 82343278079B 68681088000B extended
# 5 13662222336B 14715025919B 1052803584B logical ext3
-# 14715058176B 30449986559B 15734928384B
+# 14715058176B 30449986559B 15734928384B
# 7 30450018816B 32547432959B 2097414144B logical ext3
# 8 32547465216B 82343278079B 49795812864B logical ext3
#
@@ -192,20 +194,24 @@
elsif ( $line =~ /^(Number\s+)(\S+\s+)+/ )
{
my $col_start = 0;
+
# check the length of each heading; note that they might contain spaces
while ( $line =~ /^(\S+( [a-z]\S+)?\s*)([A-Z].*)?$/ )
{
my $heading = $1;
+
# set the line to the remainder
$line = "";
- $line = $3 if defined( $3 );
+ $line = $3 if defined($3);
+
# the width of the column includes any whitespace
- my $col_width = length( $heading );
+ my $col_width = length($heading);
$heading =~ s/(\S+)\s*$/$1/;
+
# build the hash entry
# this start counter starts at 0, which is useful below
$cols{$heading} = {
- "start" => $col_start,
+ "start" => $col_start,
"length" => $col_width
};
$col_start += $col_width;
@@ -215,23 +221,26 @@
# one of the partitions
else
{
+
# we must have seen the header, otherwise probably the format has
# changed
- defined( $cols{"File system"}{"start"} ) or die
+ defined( $cols{"File system"}{"start"} )
+ or die
or die "INTERNAL ERROR: Table header not seen yet\n";
# the info for the partition number
my $num_cols_before = $cols{"Number"}{"start"};
- my $num_col_width = $cols{"Number"}{"length"};
+ my $num_col_width = $cols{"Number"}{"length"};
# the info for the file system column
my $fs_cols_before = $cols{"File system"}{"start"};
- my $fs_col_width = $cols{"File system"}{"length"};
+ my $fs_col_width = $cols{"File system"}{"length"};
# get the partition number, if any
$line =~ /^.{$num_cols_before}(.{$num_col_width})/;
my $id = $1;
$id =~ s/\s*//g;
+
# if there is no partition number, then it must be free space, so no
# file system either
next if ( $id eq "" );
@@ -267,20 +276,21 @@
# execute_command_std
# if ( $error ne "" )
# {
- # my $response = &FAI::get_error( $error, "response" );
- # ( $response eq "die" ) and die &FAI::get_error( $error, "message" );
- # ( $response eq "warn" ) and warn &FAI::get_error( $error, "message" );
+ # my $response = &FAI::get_error( $error, "response" );
+ # ( $response eq "die" ) and die &FAI::get_error( $error, "message" );
+ # ( $response eq "warn" ) and warn &FAI::get_error( $error, "message" );
# }
-
+
# Parse the output of the byte-wise partition table
foreach my $line (@parted_print)
{
+
# the disk size line (Disk /dev/hda: 82348277759B)
if ( $line =~ /Disk \Q$disk\E: (\d+)B$/ )
{
$FAI::current_config{$disk}{"begin_byte"} = 0;
$FAI::current_config{$disk}{"end_byte"} = ( $1 - 1 );
- $FAI::current_config{$disk}{"size"} = $1;
+ $FAI::current_config{$disk}{"size"} = $1;
# nothing else to be done
next;
@@ -305,7 +315,7 @@
&& ( $6 eq "extended" ) )
and $FAI::current_config{$disk}{"partitions"}{$1}{"is_extended"} = 1;
}
-
+
# set no_dry_run to perform read-only commands always
$FAI::no_dry_run = 1;
@@ -324,27 +334,29 @@
# Parse the output of the CHS partition table
foreach my $line (@parted_print)
{
- # find the BIOS geometry that looks like this:
- # BIOS cylinder,head,sector geometry: 10011,255,63. Each cylinder is 8225kB.
- if ( $line =~ /^BIOS cylinder,head,sector geometry:\s*(\d+),(\d+),(\d+)\.\s*Each cylinder is \d+kB\.$/ )
+
+ # find the BIOS geometry that looks like this:
+ # BIOS cylinder,head,sector geometry: 10011,255,63. Each cylinder is 8225kB.
+ if ( $line =~
+/^BIOS cylinder,head,sector geometry:\s*(\d+),(\d+),(\d+)\.\s*Each cylinder is \d+kB\.$/
+ )
{
- $FAI::current_config{$disk}{"bios_cylinders"} = $1;
- $FAI::current_config{$disk}{"bios_heads"} = $2;
+ $FAI::current_config{$disk}{"bios_cylinders"} = $1;
+ $FAI::current_config{$disk}{"bios_heads"} = $2;
$FAI::current_config{$disk}{"bios_sectors_per_track"} = $3;
}
}
# make sure we have determined all the necessary information
- ( $FAI::current_config{$disk}{"begin_byte"} == 0 ) or die
- "Invalid start byte\n";
- ( $FAI::current_config{$disk}{"end_byte"} > 0 ) or die
- "Invalid end byte\n";
- defined( $FAI::current_config{$disk}{"size"} ) or die
- "Failed to determine disk size\n";
- defined( $FAI::current_config{$disk}{"sector_size"} ) or die
- "Failed to determine sector size\n";
- defined( $FAI::current_config{$disk}{"bios_sectors_per_track"} ) or die
- "Failed to determine the number of sectors per track\n";
+ ( $FAI::current_config{$disk}{"begin_byte"} == 0 )
+ or die "Invalid start byte\n";
+ ( $FAI::current_config{$disk}{"end_byte"} > 0 ) or die "Invalid end byte\n";
+ defined( $FAI::current_config{$disk}{"size"} )
+ or die "Failed to determine disk size\n";
+ defined( $FAI::current_config{$disk}{"sector_size"} )
+ or die "Failed to determine sector size\n";
+ defined( $FAI::current_config{$disk}{"bios_sectors_per_track"} )
+ or die "Failed to determine the number of sectors per track\n";
}
}
@@ -356,6 +368,7 @@
################################################################################
sub get_current_lvm
{
+
# backup value of $FAI::no_dry_run
my $no_dry_run = $FAI::no_dry_run;
@@ -374,82 +387,86 @@
# "XENU" 453.36 GB [451.93 GB used / 1.43 GB free]
# parse the output line by line and call vgdisplay -v <VG>
- foreach my $line ( @vgdisplay_print )
+ foreach my $line (@vgdisplay_print)
{
- ( $line =~ /^\s*"(\S+)"\s+\d+\.\d+ [MGT]B\s+\[\d+\.\d+ [MGT]B\s+used \/ \d+\.\d+ [MGT]B\s+free\]$/ )
- or die "Unexpected vgdisplay output $line";
+ ( $line =~
+/^\s*"(\S+)"\s+\d+\.\d+ [MGT]B\s+\[\d+\.\d+ [MGT]B\s+used \/ \d+\.\d+ [MGT]B\s+free\]$/
+ ) or die "Unexpected vgdisplay output $line";
# the name of the volume group
my $vg = $1;
-
+
# initialise the hash entry
$FAI::current_lvm_config{$vg}{"physical_volumes"} = ();
# get the detailed configuration for $vg
my @vgdisplay_v_print = ();
-
+
# try to obtain the detailed information for the volume group $vg
- my $error = &FAI::execute_command_std( "vgdisplay -v $vg", \@vgdisplay_v_print, 0 );
+ my $error =
+ &FAI::execute_command_std( "vgdisplay -v $vg", \@vgdisplay_v_print, 0 );
# the expected output (if any) looks like this:
-# $ vgdisplay -v XENU
-# Using volume group(s) on command line
-# Finding volume group "XENU"
-# --- Volume group ---
-# VG Name XENU
-# System ID
-# Format lvm2
-# Metadata Areas 4
-# Metadata Sequence No 65
-# VG Access read/write
-# VG Status resizable
-# MAX LV 0
-# Cur LV 53
-# Open LV 46
-# Max PV 0
-# Cur PV 4
-# Act PV 4
-# VG Size 453.36 GB
-# PE Size 4.00 MB
-# Total PE 116060
-# Alloc PE / Size 115693 / 451.93 GB
-# Free PE / Size 367 / 1.43 GB
-# VG UUID 09JCPv-v2RU-NWEZ-ilNA-mNLk-Scw3-aURtE6
-#
-# --- Logical volume ---
-# LV Name /dev/XENU/mole_
-# VG Name XENU
-# LV UUID WBcBDw-1z2J-F3b2-FGAk-u7Ki-IEgF-lMEURK
-# LV Write Access read/write
-# LV Status available
-# # open 1
-# LV Size 1000.00 MB
-# Current LE 250
-# Segments 1
-# Allocation inherit
-# Read ahead sectors 0
-# Block device 254:0
-#
-# --- Physical volumes ---
-# PV Name /dev/sda8
-# PV UUID 4i7Tpi-k9io-Ud44-gWJd-nSuG-hbh7-CE1m43
-# PV Status allocatable
-# Total PE / Free PE 29015 / 0
-#
-# PV Name /dev/sda9
-# PV UUID VXSxq1-vEwU-5VrY-QVC8-3Wf1-AY45-ayD9KY
-# PV Status allocatable
-# Total PE / Free PE 29015 / 0
-#
+ # $ vgdisplay -v XENU
+ # Using volume group(s) on command line
+ # Finding volume group "XENU"
+ # --- Volume group ---
+ # VG Name XENU
+ # System ID
+ # Format lvm2
+ # Metadata Areas 4
+ # Metadata Sequence No 65
+ # VG Access read/write
+ # VG Status resizable
+ # MAX LV 0
+ # Cur LV 53
+ # Open LV 46
+ # Max PV 0
+ # Cur PV 4
+ # Act PV 4
+ # VG Size 453.36 GB
+ # PE Size 4.00 MB
+ # Total PE 116060
+ # Alloc PE / Size 115693 / 451.93 GB
+ # Free PE / Size 367 / 1.43 GB
+ # VG UUID 09JCPv-v2RU-NWEZ-ilNA-mNLk-Scw3-aURtE6
+ #
+ # --- Logical volume ---
+ # LV Name /dev/XENU/mole_
+ # VG Name XENU
+ # LV UUID WBcBDw-1z2J-F3b2-FGAk-u7Ki-IEgF-lMEURK
+ # LV Write Access read/write
+ # LV Status available
+ # # open 1
+ # LV Size 1000.00 MB
+ # Current LE 250
+ # Segments 1
+ # Allocation inherit
+ # Read ahead sectors 0
+ # Block device 254:0
+ #
+ # --- Physical volumes ---
+ # PV Name /dev/sda8
+ # PV UUID 4i7Tpi-k9io-Ud44-gWJd-nSuG-hbh7-CE1m43
+ # PV Status allocatable
+ # Total PE / Free PE 29015 / 0
+ #
+ # PV Name /dev/sda9
+ # PV UUID VXSxq1-vEwU-5VrY-QVC8-3Wf1-AY45-ayD9KY
+ # PV Status allocatable
+ # Total PE / Free PE 29015 / 0
+ #
# parse the output to select the interesting parts
# there are 3 main groups: the volume group, logical volumes and physical
# volumes; use mode to indicate this
my $mode = "";
+
# we need to remember the logical volume name across the lines
my $lv_name = "";
+
# do the line-wise parsing
- foreach my $line_v ( @vgdisplay_v_print )
+ foreach my $line_v (@vgdisplay_v_print)
{
$mode = "vg" if ( $line_v =~ /^\s*--- Volume group ---\s*$/ );
$mode = "lv" if ( $line_v =~ /^\s*--- Logical volume ---\s*$/ );
@@ -460,17 +477,21 @@
# Now select the interesting information for each mode
if ( $mode eq "vg" )
{
+
# for a volume group only the size is needed
if ( $line_v =~ /^\s*Alloc PE \/ Size\s+\d+ \/ (\d+\.\d+) ([MG]B)\s*$/ )
{
+
# extract the floatingpoint value
$FAI::current_lvm_config{$vg}{"size"} = $1;
+
# make it megabytes
$FAI::current_lvm_config{$vg}{"size"} *= 1024 if ( $2 eq "GB" );
}
}
elsif ( $mode eq "lv" )
{
+
# we need the name and the size of each existing logical volume
if ( $line_v =~ /^\s*LV Name\s+\/dev\/\Q$vg\E\/(\S+)\s*$/ )
{
@@ -478,14 +499,18 @@
}
elsif ( $line_v =~ /^\s*LV Size\s+(\d+\.\d+) ([MG]B)\s*$/ )
{
+
# extract the floatingpoint value
$FAI::current_lvm_config{$vg}{"volumes"}{$lv_name}{"size"} = $1;
+
# make it megabytes
- $FAI::current_lvm_config{$vg}{"volumes"}{$lv_name}{"size"} *= 1024 if ( $2 eq "GB" );
+ $FAI::current_lvm_config{$vg}{"volumes"}{$lv_name}{"size"} *= 1024
+ if ( $2 eq "GB" );
}
}
elsif ( $mode eq "pv" )
{
+
# get the physical devices that are part of this volume group
if ( $line_v =~ /^\s*PV Name\s+(\S+)\s*$/ )
{
@@ -495,7 +520,7 @@
}
}
-
+
# reset no_dry_run
$FAI::no_dry_run = $no_dry_run;
}
@@ -508,6 +533,7 @@
################################################################################
sub get_current_raid
{
+
# backup value of $FAI::no_dry_run
my $no_dry_run = $FAI::no_dry_run;
@@ -518,8 +544,9 @@
$FAI::no_dry_run = 1;
# try to obtain the list of existing RAID arrays
- my $error = &FAI::execute_command_std(
- "mdadm --detail --scan --verbose -c partitions", \@mdadm_print, 0 );
+ my $error =
+ &FAI::execute_command_std( "mdadm --detail --scan --verbose -c partitions",
+ \@mdadm_print, 0 );
# the expected output is as follows
# $ mdadm --detail --scan --verbose -c partitions
@@ -530,8 +557,9 @@
# the id of the RAID
my $id;
+
# parse the output line by line
- foreach my $line ( @mdadm_print )
+ foreach my $line (@mdadm_print)
{
if ( $line =~ /^ARRAY \/dev\/md(\d+) level=(\S+) num-devices=\d+ UUID=/ )
{
@@ -540,10 +568,10 @@
}
elsif ( $line =~ /^\s*devices=(\S+)$/ )
{
- @{ $FAI::current_raid_config{$id}{"devices"} } = split(",", $1);
+ @{ $FAI::current_raid_config{$id}{"devices"} } = split( ",", $1 );
}
}
-
+
# reset no_dry_run
$FAI::no_dry_run = $no_dry_run;
}
More information about the Fai-commit
mailing list