Changeset 3691 in MondoRescue for branches/3.3/mindi
- Timestamp:
- Oct 7, 2017, 12:50:35 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi/mr-parted2fdisk
r3689 r3691 160 160 ) || pb_syntax(-1,0); 161 161 162 pb_temp_init(); 163 162 164 if (defined $opts{'L'}) { 163 165 open(pbLOG,"> $opts{'L'}") || die "Unable to log to $opts{'L'}: $!"; … … 243 245 # fdisk has a bug when handling more than 1024 disks, seen on RHEL 244 246 # so in that case we want to use parted instead 245 # #Cf: http://trac.mondorescue.org/ticket/805247 # Cf: http://trac.mondorescue.org/ticket/805 246 248 my $use_parted = 0; 247 249 open(CMD,"LANGUAGE=C $fdisk -l |") || die "Unable to execute $fdisk"; … … 252 254 close(CMD); 253 255 # More than 1000 is a lot of disks so may triggers the issue 254 my $maxhdd = 1 ;256 my $maxhdd = 1000; 255 257 $use_parted = 1 if ($lines >= $maxhdd); 256 258 … … 282 284 print "command (m for help) sent back to fake fdisk for mondorestore\n"; 283 285 } elsif ($i =~ /^n$/) { 286 $endmax = get_max($device); 287 $un = get_un($device,undef,0); 288 my $sizemax = $endmax*$mega; 284 289 fdisk_list($device,undef,\%start,\%end, 0); 285 if ( $type ne "GPT"){286 pb_log( 1,"Forcing GPT type of disk label\n");290 if (($type ne "GPT") && ($sizemax > 2*$mega*$mega)){ 291 pb_log(0,"INFO: Forcing GPT type of disk label due to size > 2TB\n"); 287 292 pb_log(1,"mklabel gpt\n"); 288 293 pb_system("$parted -s $device mklabel gpt\n") if ($fake == 0); … … 315 320 } 316 321 $cylstart = 1 if ($cylstart < 1); 317 $un = get_un($device, "", 0);318 322 # parted needs MB 319 323 if ($cylstart == 1) { 320 $start = 0.01;324 $start = $cylstart; 321 325 } else { 322 $start = $cylstart* $un / $mega + 0.001; 323 } 326 $start = $cylstart* $un / $mega; 327 } 328 pb_log(1,"start: $start\n"); 324 329 # this is a size in B/KB/MB/GB 325 330 326 $endmax = get_max($device);327 331 $cylend = <STDIN>; 328 332 chomp($cylend); … … 340 344 $cylend /= $un; 341 345 $cylend = sprintf("%d",$cylend); 342 $cylend += $cylstart - 0.001;346 $cylend += $cylstart; 343 347 # We now have the end cyl 344 348 } … … 347 351 # parted needs MB 348 352 $end = $cylend * $un / $mega; 353 pb_log(1,"end: $end\n"); 349 354 pb_log(1,"n $l $part $cylstart $cylend => mkpart primary ext2 $start $end\n"); 355 # Would that work ??? pb_system("$parted -s $device unit cyl\n") if ($fake == 0); 350 356 pb_system("$parted -s $device mkpart primary ext2 $start $end\n") if ($fake == 0); 351 357 print "command (m for help) sent back to fake fdisk for mondorestore\n"; … … 553 559 554 560 $endmax = get_max($device); 561 # Returned KB change to MB 562 $endmax = sprintf("%d",$endmax*$mega); 555 563 556 564 # This will return MB … … 619 627 my $device = shift; 620 628 my $max = 0; 621 my $foo; 622 623 open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk"; 629 630 open (FDISK, "$fdisk -s $device 2>/dev/null |") || die "Unable to read from $fdisk"; 624 631 while (<FDISK>) { 625 if ($_ =~ /heads/) { 626 chomp; 627 $max = $_; 628 $max =~ s/.* ([0-9]+) cylinders/$1/; 629 } 630 } 631 if ($max == 0) { 632 close(FDISK); 633 # Try by forcing the cylinders display, not done by default on more recent fdisk 634 open (FDISK, "$fdisk -u=cylinders -l $device 2>/dev/null |") || die "Unable to read from $fdisk -u=cylinders"; 635 while (<FDISK>) { 636 if ($_ =~ /heads/) { 637 chomp; 638 $max = $_; 639 $max =~ s/.* ([0-9]+) cylinders/$1/; 640 } 641 } 632 chomp; 633 $max = $_; 642 634 } 643 635 close(FDISK); 644 pb_log(2,"get_max returns $max \n");636 pb_log(2,"get_max returns $max kB\n"); 645 637 return($max); 646 638 } … … 657 649 my $foo; 658 650 659 open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk"; 651 # Use -u=cylinders for recent fdisk, if it fails, it's an older fdisk which uses cylinders by default 652 open (FDISK, "$fdisk -u=cylinders -l $device 2>/dev/null |") || open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk"; 660 653 while (<FDISK>) { 661 654 print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) and ($verbose == 1)); 662 655 if ($_ =~ /^Units/) { 663 ($foo, $un , $foo) = split /=/;656 ($foo, $un , $foo) = split(/=/); 664 657 $un =~ s/[A-z\s=]//g; 665 658 $un = eval($un); … … 667 660 } 668 661 close(FDISK); 669 pb_log(2,"get_un returns $un \n");662 pb_log(2,"get_un returns $un bytes\n"); 670 663 return($un); 671 664 } … … 733 726 #3:735MB:500GB:499GB:::lvm; 734 727 # 728 # In a VM 729 #BYT; 730 #/dev/sda:7516MB:scsi:512:512:msdos:ATA QEMU HARDDISK:; 731 #1:1049kB:525MB:524MB:xfs::boot; 732 #2:525MB:7516MB:6991MB:::lvm; 733 # 735 734 # On RHEL6: 736 735 #BYT; … … 780 779 } 781 780 } else { 782 # Mainta ned for compatibility with very old distributions now781 # Maintained for compatibility with very old distributions now 783 782 open(PARTED, "$parted -s $device print |") || die "Unable to read from $parted"; 784 783 # Skip 3 first lines
Note:
See TracChangeset
for help on using the changeset viewer.