Changeset 89 in MondoRescue for trunk/mindi
- Timestamp:
- Oct 27, 2005, 10:45:34 PM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/mindi/parted2fdisk.pl
r30 r89 1 1 #!/usr/bin/perl -w 2 2 # 3 # $Id$ 4 # 3 5 # parted2fdisk: fdisk like interface for parted 4 # [developped for mindi/mondo http:// www.mondorescue.org]6 # [developped for mindi/mondo http://mondorescue.berlios.de] 5 7 # 6 8 # Aims to be architecture independant (i386/ia64) … … 34 36 my %flags; 35 37 my $arch; 38 my $fake = 0; 36 39 37 40 # Determine on which arch we're running … … 57 60 my $args = ""; 58 61 my $device = ""; 62 my $endmax = ""; 59 63 60 64 if ($#ARGV < 0) { … … 104 108 } 105 109 110 if ($args =~ /-n/) { 111 print FLOG "Fake mode. Nothing will be really done\n"; 112 $fake = 1; 113 } 114 106 115 print FLOG "Called with device $device and arg $args\n"; 107 116 … … 117 126 } elsif ($args =~ /-s/) { 118 127 fdisk_list($device,$wpart,\%start,\%end); 119 } elsif ( $args =~ /-/) {128 } elsif (($args =~ /-/) and ($fake == 0)) { 120 129 printf FLOG "Option not supported ($args) ...\n"; 121 130 printf FLOG "Please report to the author\n"; … … 134 143 print FLOG "Forcing GPT type of disk label\n"; 135 144 print FLOG "mklabel gpt\n"; 136 system "$parted -s $device mklabel gpt\n" ;145 system "$parted -s $device mklabel gpt\n" if ($fake != 0); 137 146 $type = "gpt"; 138 147 } … … 160 169 } 161 170 } 171 $start = 1 if ($start < 1); 162 172 print FLOG "start cyl : $start\n"; 173 $un = get_un($device); 174 # parted needs MB 175 $start = $start * $un / 1048576; 176 # this is a size in B/KB/MB/GB 177 $endmax = get_max($device); 163 178 $end = <STDIN>; 164 179 chomp($end); 165 180 if ((not (defined $end)) || ($end eq "")) { 166 181 print FLOG "no end cyl given for creation... assuming full disk)\n"; 167 $end = get_max($device); 168 } 169 $un = get_un($device); 182 $end = $endmax; 183 } 170 184 # Handles end syntaxes (+, K, M, ...) 185 # to give cylinders 171 186 if ($end =~ /^\+/) { 172 187 $end =~ s/^\+//; … … 181 196 $end *= 1000000000; 182 197 } 198 # This gives the number of cyl 183 199 $end /= $un; 184 $end = int($end)+1;200 $end = sprintf("%d",$end); 185 201 $end += $start - 0.001; 202 # We now have the end cyl 186 203 } 187 204 print FLOG "end cyl : $end\n"; 188 print FLOG "n $l $part $start $end => mkpart primary $start $end\n"; 189 system "$parted -s $device mkpart primary ext2 $start $end\n"; 205 # parted needs MB 206 $end = $end * $un / 1048576; 207 $end = $endmax if ($end > $endmax); 208 print FLOG "n $l $part => mkpart primary $start $end\n"; 209 system "$parted -s $device mkpart primary ext2 $start $end\n" if ($fake != 0); 190 210 } 191 211 elsif ($i =~ /^d$/) { … … 197 217 chomp($part); 198 218 print FLOG "d $part => rm $part\n"; 199 system "$parted -s $device rm $part\n" ;219 system "$parted -s $device rm $part\n" if ($fake != 0); 200 220 get_parted($device,undef,\%start,\%end,undef,undef); 201 221 } … … 221 241 } 222 242 print FLOG "t $part => mkfs $part $pnum{$l}\n"; 223 system "$parted -s $device mkfs $part $pnum{$l}\n" ;243 system "$parted -s $device mkfs $part $pnum{$l}\n" if ($fake != 0); 224 244 } 225 245 elsif ($i =~ /^a$/) { … … 231 251 chomp($part); 232 252 print FLOG "a $part => set $part boot on\n"; 233 system "$parted -s $device set $part boot on\n" ;253 system "$parted -s $device set $part boot on\n" if ($fake != 0); 234 254 } 235 255 elsif ($i =~ /^q$/) { … … 323 343 324 344 my $un; 345 my $endmax; 325 346 my $d; 326 347 my $n; … … 367 388 # Keep Fdisk headers 368 389 # 390 # this will return bytes 369 391 $un = get_un ($device,$wpart); 392 $endmax = get_max($device); 393 # This will return MB 370 394 get_parted ($device,$start,$end,\%type,\%flags); 371 395 … … 373 397 # Print infos fdisk like 374 398 $part = ${device}.$n; 375 $mstart = sprintf("%d",int($$start{$n})); 376 $mend = sprintf("%d",int($$end{$n})); 377 $length = sprintf("%d",($mend-$mstart+1)*$un/1048576); 399 # start and end are in cylinder in fdisk format 400 # so return in MB * 1MB / what represents 1 cyl in B 401 $mstart = sprintf("%d",$$start{$n}*1048576/$un); 402 $mstart = 1 if ($mstart < 1); 403 $mend = sprintf("%d",$$end{$n}*1048576/$un - 1); 404 $mend = $endmax if ($mend > $endmax); 405 # length is in 1K blocks 406 $length = sprintf("%d",($mend-$mstart+1)*$un/1024); 378 407 $pid = $pid{$type{$n}}; 379 408 $cmt = $cmt{$type{$n}}; … … 404 433 } else { 405 434 # manage the -s option of fdisk here 406 my $s = int(eval("$length/1048576*$un*1024")); 407 print "$s\n" if ($part eq $wpart); 408 print FLOG "$part has $s Bytes\n" if ($part eq $wpart); 435 print "$length\n" if ($part eq $wpart); 436 print FLOG "$part has $length KBytes\n" if ($part eq $wpart); 409 437 } 410 438 } … … 424 452 open (FDISK, "$fdisk -l $device |") || die "Unable to read from $fdisk"; 425 453 while (<FDISK>) { 426 if ($_ =~ / ^Disk/) {427 ($foo, $un , $foo) = split /=/;428 $max = ~ s/.*sectors,([0-9]+) cylinders/$1/g;429 $max = eval($max);454 if ($_ =~ /heads/) { 455 chomp; 456 $max = $_; 457 $max =~ s/.* ([0-9]+) cylinders/$1/; 430 458 } 431 459 } … … 436 464 437 465 # 438 # Get units from fdisk 466 # Get units from fdisk (cylinder size) 439 467 # 440 468 sub get_un { … … 459 487 } 460 488 489 # 490 # Parted gives info in MB 491 # 461 492 sub get_parted { 462 493
Note:
See TracChangeset
for help on using the changeset viewer.