Changeset 3343 in MondoRescue for branches/3.2/mindi/parted2fdisk.pl
- Timestamp:
- Feb 13, 2015, 8:27:10 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi/parted2fdisk.pl
r3330 r3343 4 4 # 5 5 # parted2fdisk: fdisk like interface for parted 6 # [develop ped for mindi/mondo http://www.mondorescue.org]6 # [developed for mindi/mondo http://www.mondorescue.org] 7 7 # 8 8 # Aims to be architecture independant (i386/ia64) 9 9 # Tested on ia64 with RHAS 2.1 - Mandrake 9.0 - RHEL 3.0 - SLES 10 10 10 # 11 # Copyright B. Cornec 2000-201 311 # Copyright B. Cornec 2000-2015 12 12 # Provided under the GPL v2 13 13 14 14 use strict; 15 use File::Basename; 15 16 16 17 … … 19 20 =head1 NAME 20 21 21 parted2fdisk is a fdisk li e command using parted internally.22 parted2fdisk is a fdisk like command using parted internally. 22 23 23 24 =head1 DESCRIPTION 24 25 25 parted2fdisk behaves like a fdisk command, but dialog internally with parted in order to manipulate partiion tables, which allow it to support GPT partition format as well as MBR, contrary to fdisk. It aimed at providing compatible external interface wti fdisk. Developed initialy for ia64 Linux, but is also useful now on x86 systems using GPT partition format (for large HDDs).26 parted2fdisk behaves like the fdisk command, but dialog internally with parted in order to manipulate partition tables, which allow it to support GPT partition format as well as MBR, contrary to fdisk. It aims at providing compatible external interface with fdisk. Developed initialy for ia64 Linux, it is also useful now on x86 systems using GPT partition format (for large HDDs). 26 27 27 28 =head1 SYNOPSIS … … 96 97 97 98 my $fdisk = "/sbin/fdisk"; 99 $fdisk = "/usr/sbin/fdisk" if (not -x "/sbin/fdisk"); 98 100 my $parted = "/sbin/parted"; 101 $parted = "/usr/sbin/parted" if (not -x "/sbin/parted"); 99 102 100 103 my $i; … … 109 112 my %end; 110 113 my %type; 111 my $arch;112 114 my $fake = 0; 113 115 my $mega = 1048576; … … 116 118 $| = 1; 117 119 118 # Determine on which arch we're running119 if (defined ($ENV{ARCH})) {120 $arch = $ENV{ARCH};121 } else {122 $arch = `uname -m`;123 chomp($arch);124 }125 126 120 # 127 121 # Looking for fdisk … … 129 123 $fdisk = is_lsb($fdisk); 130 124 # 131 # We always use fdisk except on ia64with GPT types of125 # We always use fdisk except with GPT types of 132 126 # partition tables where we need parted 133 127 # All should return fdisk like format so that callers … … 156 150 "linux-swap" => "82", 157 151 "lvm" => "8e", 152 "raid" => "fd", 158 153 "" => "", 159 154 ); … … 197 192 print FLOG "Called with device $device and arg $args\n"; 198 193 199 if ($arch =~ /^ia64/) { 194 # util-linux/fdisk version 195 open(CMD,"$fdisk -v |") || die "Unable to execute $fdisk"; 196 my $version = <CMD>; 197 close(CMD); 198 chomp($version); 199 $version =~ s/[^0-9\.]*([0-9\.]+)[\)]$/$1/; 200 my ($v,$maj,$min) = split(/\./,$version); 201 202 if (($v == 1) || (($v == 2) && ($maj < 22))) { 200 203 # Check partition table type 201 print FLOG "We 're on ia64...\n";204 print FLOG "We use an old fdisk, activating replacement code...\n"; 202 205 $parted = is_lsb($parted); 203 206 $type = which_type($device); … … 435 438 "linux-swap" => "Linux swap", 436 439 "lvm" => "Linux LVM", 440 "raid" => "RAID Linux auto", 437 441 "fat16" => "fat16", 438 442 "fat32" => "fat32", … … 601 605 print FLOG "$d"; 602 606 close(PARTED); 607 chomp($d); 608 # parted version 609 $d =~ s/[^0-9\.]*([0-9\.]+)$/$1/; 610 my ($v,$maj,$min) = split(/\./,$d); 611 # depending on parted version, information given change: 612 if ($v == 2) { 613 # RHEL 6 parted 2.1 614 $mode=2; 615 } elsif ($v == 1) { 616 if (($maj <= 5) || (($maj == 6) && (defined $min) && ($min < 25))) { 617 # RHEL 3 parted 1.6.3 618 # RHEL 4 parted 1.6.19 619 $mode=0; 620 } else { 621 # SLES 10 parted >= 1.6.25 622 $mode=1; 623 } 624 } else { 625 $mode=-1; 626 } 627 print FLOG "mode: $mode\n"; 603 628 604 629 open (PARTED, "$parted -s $device print |") || die "Unable to read from $parted"; … … 608 633 $d = <PARTED>; 609 634 610 # depending on parted version, information given change: 611 if ($d =~ /\bSize\b/) { 612 # SLES 10 parted >= 1.6.25 613 $mode=1; 614 } else { 615 # RHEL 3 parted 1.6.3 616 # RHEL 4 parted 1.6.19 617 $mode=0; 618 } 619 print FLOG "mode: $mode\n"; 635 if ($mode == 2) { 636 $d = <PARTED>; 637 $d = <PARTED>; 638 $d = <PARTED>; 639 } 620 640 print FLOG "Got from parted: \n"; 621 641 print FLOG "Minor Start End Filesystem\n"; … … 623 643 while (($n,$d) = split(/\s/, <PARTED>,2)) { 624 644 chomp($d); 645 # v2 of parted ends with empty line 646 next if (($mode == 2) && ($n eq "") && ($d eq "")); 647 # v2 of parted starts with space potentially 648 ($n,$d) = split(/\s/, $d,2) if (($mode == 2) && ($n eq "")); 625 649 next if ($n !~ /^[1-9]/); 626 650 $d =~ s/^\s*//; … … 630 654 $unit = 1; 631 655 } elsif ($mode == 1) { 656 ($$start{$n},$$end{$n},$size,$$type{$n},$void) = split(/ /,$d); 657 $unit = $mega; 658 } elsif ($mode == 2) { 632 659 ($$start{$n},$$end{$n},$size,$$type{$n},$void) = split(/ /,$d); 633 660 $unit = $mega; … … 675 702 } 676 703 677 678 # Based on Version 2.4 27-Sep-1996 Charles Bailey bailey@genetics.upenn.edu679 # in Basename.pm680 681 sub basename {682 683 my($fullname) = shift;684 685 my($dirpath,$basename);686 687 ($dirpath,$basename) = ($fullname =~ m#^(.*/)?(.*)#s);688 689 return($basename);690 }691 692 704 sub myexit { 693 705
Note:
See TracChangeset
for help on using the changeset viewer.