Hi, The attached patch (code + doc) allows partition sizes in setup-storage to be defined relative to the RAM size.
For some of the setups I use, I need to be able to define the size of one or more swap partitions as a function of the amount of RAM installed in the machine. I figured it would be better to integrate this into setup-storage rather than playing ugly games with the disk config files and FAI hooks. Config example: disk_config /dev/sda fstabkey:uuid primary swap RAM:150% swap - primary swap RAM:50%-RAM:100% swap - primary swap -RAM:100% swap - logical swap 10G-RAM:100% swap - logical swap RAM:100%-20G swap - When using mixed ranges, be careful wrt the min < max constraint. Currently there is no specific handling for this case, not sure there is a need for it. JB. -- Julien BLACHE <jbla...@debian.org> | Debian, because code matters more Debian & GNU/Linux Developer | <http://www.debian.org> Public key available on <http://www.jblache.org> - KeyID: F5D6 5169 GPG Fingerprint : 935A 79F1 C8B3 3521 FD62 7CC7 CD61 4FD7 F5D6 5169
diff -ru a/lib/setup-storage/Parser.pm b/lib/setup-storage/Parser.pm --- a/lib/setup-storage/Parser.pm 2010-04-05 14:39:33.000000000 +0200 +++ b/lib/setup-storage/Parser.pm 2010-05-10 13:49:54.000000000 +0200 @@ -299,6 +299,21 @@ { my ($val) = @_; + if ($val =~ /^RAM:(\d+)%/) { + $val = $1 / 100.0; + + ## get total RAM + open(F, "/proc/meminfo"); + my @meminfo = <F>; + close F; + + my ($totalmem) = grep /^MemTotal:/, @meminfo; + $totalmem =~ s/[^0-9]//g; + $totalmem = $totalmem / 1024.0; + + return $val * $totalmem; + } + ## don't warn for now, G/GiB/GB are all treated the same way ## ($val =~ /([kKMGTP])\s*$/) and ## warn "Using $1 as size modifier is deprecated, please use $1iB or $1B @@ -630,17 +645,17 @@ 1; } - size: /^(\d+[kMGTP%iB]*(-(\d+[kMGTP%iB]*)?)?)(:resize)?\s+/ + size: /^((RAM:\d+%|\d+[kMGTP%iB]*)(-(RAM:\d+%|\d+[kMGTP%iB]*)?)?)(:resize)?\s+/ { # complete the size specification to be a range in all cases my $range = $1; # the size is fixed - if (!defined ($2)) + if (!defined ($3)) { # make it a range of the form x-x - $range = "$range-$1"; + $range = "$range-$2"; } - elsif (!defined ($3)) + elsif (!defined ($4)) { # range has no upper limit, assume the whole disk $range = "${range}100%"; @@ -656,12 +671,12 @@ # enter the range into the hash $FAI::partition_pointer->{size}->{range} = $range; # set the resize flag, if required - if (defined ($4)) { + if (defined ($5)) { $FAI::partition_pointer->{size}->{resize} = 1; $FAI::configs{$FAI::device}{preserveparts} = 1; } } - | /^(-\d+[kMGTP%iB]*)(:resize)?\s+/ + | /^(-(RAM:\d+%|\d+[kMGTP%iB]*))(:resize)?\s+/ { # complete the range by assuming 0 as the lower limit my $range = "0$1"; @@ -675,7 +690,7 @@ # enter the range into the hash $FAI::partition_pointer->{size}->{range} = $range; # set the resize flag, if required - if (defined ($2)) { + if (defined ($3)) { $FAI::partition_pointer->{size}->{resize} = 1; $FAI::configs{$FAI::device}{preserveparts} = 1; } diff -ru a/man/setup-storage.8 b/man/setup-storage.8 --- a/man/setup-storage.8 2010-05-10 13:57:09.000000000 +0200 +++ b/man/setup-storage.8 2010-05-10 14:01:41.000000000 +0200 @@ -318,19 +318,19 @@ .br -size ::= [[:digit:]]+[kKMGTP%iB]*(-([[:digit:]]+[kKMGTP%iB]*)?)?(:resize)? +size ::= (RAM:[[:digit:]]+%|[[:digit:]]+[kKMGTP%iB]*)(-(RAM:[[:digit:]]+%|[[:digit:]]+[kKMGTP%iB]*)?)?(:resize)? .br - /* size in kilo (KiB), mega (default, MiB), giga (GiB), tera (TiB) or + /* size in kilo (KiB), mega (default, MiB), giga (GiB), tera (TiB), .br - * petabytes (PiB) or %, possibly given as a range; physical + * petabytes (PiB) or percentage of disk size or RAM size, possibly .br - * partitions or lvm logical volumes only; in future releases KB, MB, + * given as a range; physical partitions or lvm logical volumes only; .br - * GB, ... will be treated as 1000 instead of 1024 (KiB, MiB, GiB, ...) + * in future releases KB, MB, GB, ... will be treated as 1000 instead .br - * multipliers */ + * of 1024 (KiB, MiB, GiB, ...) multipliers */ .br - | -[[:digit:]]+[kKMGTP%iB]*(:resize)? + | -(RAM:[[:digit:]]+%|[[:digit:]]+[kKMGTP%iB]*)(:resize)? .br /* size in kilo, mega (default), giga, tera or petabytes or %, .br