Changeset 3691 in MondoRescue for branches


Ignore:
Timestamp:
Oct 7, 2017, 12:50:35 AM (7 years ago)
Author:
Bruno Cornec
Message:

Fix the parted part usage (review creation of partitions with RHEL7)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3/mindi/mr-parted2fdisk

    r3689 r3691  
    160160) || pb_syntax(-1,0);
    161161
     162pb_temp_init();
     163
    162164if (defined $opts{'L'}) {
    163165    open(pbLOG,"> $opts{'L'}") || die "Unable to log to $opts{'L'}: $!";
     
    243245# fdisk has a bug when handling more than 1024 disks, seen on RHEL
    244246# so in that case we want to use parted instead
    245 # # Cf: http://trac.mondorescue.org/ticket/805
     247# Cf: http://trac.mondorescue.org/ticket/805
    246248my $use_parted = 0;
    247249open(CMD,"LANGUAGE=C $fdisk -l |") || die "Unable to execute $fdisk";
     
    252254close(CMD);
    253255# More than 1000 is a lot of disks so may triggers the issue
    254 my $maxhdd = 1;
     256my $maxhdd = 1000;
    255257$use_parted = 1 if ($lines >= $maxhdd);
    256258
     
    282284                print "command (m for help) sent back to fake fdisk for mondorestore\n";
    283285            } elsif ($i =~ /^n$/) {
     286                $endmax = get_max($device);
     287                $un = get_un($device,undef,0);
     288                my $sizemax = $endmax*$mega;
    284289                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");
    287292                    pb_log(1,"mklabel gpt\n");
    288293                    pb_system("$parted -s $device mklabel gpt\n") if ($fake == 0);
     
    315320                }
    316321                $cylstart = 1 if ($cylstart < 1);
    317                 $un = get_un($device, "", 0);
    318322                # parted needs MB
    319323                if ($cylstart == 1) {
    320                     $start = 0.01;
     324                    $start = $cylstart;
    321325                } else {
    322                     $start = $cylstart* $un / $mega + 0.001;
    323                 }
     326                    $start = $cylstart* $un / $mega;
     327                }
     328                pb_log(1,"start: $start\n");
    324329                # this is a size in B/KB/MB/GB
    325330
    326                 $endmax = get_max($device);
    327331                $cylend = <STDIN>;
    328332                chomp($cylend);
     
    340344                    $cylend /= $un;
    341345                    $cylend = sprintf("%d",$cylend);
    342                     $cylend += $cylstart - 0.001;
     346                    $cylend += $cylstart;
    343347                    # We now have the end cyl
    344348                }
     
    347351                # parted needs MB
    348352                $end = $cylend * $un / $mega;
     353                pb_log(1,"end: $end\n");
    349354                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);
    350356                pb_system("$parted -s $device mkpart primary ext2 $start $end\n") if ($fake == 0);
    351357                print "command (m for help) sent back to fake fdisk for mondorestore\n";
     
    553559
    554560$endmax = get_max($device);
     561# Returned KB change to MB
     562$endmax = sprintf("%d",$endmax*$mega);
    555563
    556564# This will return MB
     
    619627my $device = shift;
    620628my $max = 0;
    621 my $foo;
    622 
    623 open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
     629
     630open (FDISK, "$fdisk -s $device 2>/dev/null |") || die "Unable to read from $fdisk";
    624631while (<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 = $_;
    642634}
    643635close(FDISK);
    644 pb_log(2,"get_max returns $max\n");
     636pb_log(2,"get_max returns $max kB\n");
    645637return($max);
    646638}
     
    657649my $foo;
    658650
    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
     652open (FDISK, "$fdisk -u=cylinders -l $device 2>/dev/null |") || open (FDISK, "$fdisk -l $device 2>/dev/null |") || die "Unable to read from $fdisk";
    660653while (<FDISK>) {
    661654    print if (($_ !~ /^\/dev\//) and (not (defined $wpart)) and ($verbose == 1));
    662655    if ($_ =~ /^Units/) {
    663         ($foo, $un , $foo) = split /=/;
     656        ($foo, $un , $foo) = split(/=/);
    664657        $un =~ s/[A-z\s=]//g;
    665658        $un = eval($un);
     
    667660}
    668661close(FDISK);
    669 pb_log(2,"get_un returns $un\n");
     662pb_log(2,"get_un returns $un bytes\n");
    670663return($un);
    671664}
     
    733726#3:735MB:500GB:499GB:::lvm;
    734727#
     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#
    735734# On RHEL6:
    736735#BYT;
     
    780779    }
    781780} else {
    782     # Maintaned for compatibility with very old distributions now
     781    # Maintained for compatibility with very old distributions now
    783782    open(PARTED, "$parted -s $device print |") || die "Unable to read from $parted";
    784783    # Skip 3 first lines
Note: See TracChangeset for help on using the changeset viewer.