summaryrefslogtreecommitdiffstats
path: root/perl-install/partition_table
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/partition_table')
-rw-r--r--perl-install/partition_table/bsd.pm3
-rw-r--r--perl-install/partition_table/dmcrypt.pm2
-rw-r--r--perl-install/partition_table/dos.pm8
-rw-r--r--perl-install/partition_table/empty.pm2
-rw-r--r--perl-install/partition_table/gpt.pm197
-rw-r--r--perl-install/partition_table/lvm.pm2
-rw-r--r--perl-install/partition_table/mac.pm2
-rw-r--r--perl-install/partition_table/raw.pm36
-rw-r--r--perl-install/partition_table/readonly.pm2
-rw-r--r--perl-install/partition_table/sun.pm2
10 files changed, 189 insertions, 67 deletions
diff --git a/perl-install/partition_table/bsd.pm b/perl-install/partition_table/bsd.pm
index f69cae97c..b27df6d3a 100644
--- a/perl-install/partition_table/bsd.pm
+++ b/perl-install/partition_table/bsd.pm
@@ -1,4 +1,4 @@
-package partition_table::bsd; # $Id: bsd.pm 228416 2007-09-18 10:32:56Z pixel $
+package partition_table::bsd;
use diagnostics;
use strict;
@@ -144,7 +144,6 @@ sub initialize {
my ($class, $hd) = @_;
$hd->{primary} = { raw => [ ({}) x $nb_primary ], info => info($hd) };
bless $hd, $class;
-;
}
sub first_usable_sector { 2048 }
diff --git a/perl-install/partition_table/dmcrypt.pm b/perl-install/partition_table/dmcrypt.pm
index 3eae783c6..eb35eb41c 100644
--- a/perl-install/partition_table/dmcrypt.pm
+++ b/perl-install/partition_table/dmcrypt.pm
@@ -1,4 +1,4 @@
-package partition_table::dmcrypt; # $Id: $
+package partition_table::dmcrypt;
# dmcrypt on full disk
diff --git a/perl-install/partition_table/dos.pm b/perl-install/partition_table/dos.pm
index 2cd6fe311..c420599d3 100644
--- a/perl-install/partition_table/dos.pm
+++ b/perl-install/partition_table/dos.pm
@@ -1,4 +1,4 @@
-package partition_table::dos; # $Id: dos.pm 263707 2009-11-26 13:26:41Z pterjan $
+package partition_table::dos;
use diagnostics;
use strict;
@@ -220,14 +220,14 @@ sub read_one {
sysread $F, $tmp, length $magic or die "error reading magic number on disk $hd->{device}";
$tmp eq $magic or die "bad magic number on disk $hd->{device}";
- if(c::get_disk_type($hd->{file}) ne "msdos") {
+ if (c::get_disk_type($hd->{file}) ne "msdos") {
# libparted may have ignored it because of overlapping partitions or other error
# while it is actually a partition table.
$hd->{fs_type_from_magic} and die "unpartitionned disk";
my $primary = partition_table::raw::pt_info_to_primary($hd, [ @pt ]);
foreach my $i (@{$primary->{normal}}) {
- if (($i->{active} && $i->{active} != 0x80) ||
- ($hd->{totalsectors} && $i->{start} > $hd->{totalsectors})) {
+ if ($i->{active} && $i->{active} != 0x80 ||
+ $hd->{totalsectors} && $i->{start} > $hd->{totalsectors}) {
die "Invalid DOS partition table";
}
}
diff --git a/perl-install/partition_table/empty.pm b/perl-install/partition_table/empty.pm
index 5d45143f8..fe4ad4317 100644
--- a/perl-install/partition_table/empty.pm
+++ b/perl-install/partition_table/empty.pm
@@ -1,4 +1,4 @@
-package partition_table::empty; # $Id: empty.pm 228433 2007-09-18 12:30:17Z pixel $
+package partition_table::empty;
#- this is a mainly dummy partition table. If we find it's empty, we just call -
#- ->clear which will take care of bless'ing us to the partition table type best
diff --git a/perl-install/partition_table/gpt.pm b/perl-install/partition_table/gpt.pm
index c0f748b06..4a277f7b6 100644
--- a/perl-install/partition_table/gpt.pm
+++ b/perl-install/partition_table/gpt.pm
@@ -1,4 +1,4 @@
-package partition_table::gpt; # $Id: gpt.pm 252200 2009-01-27 18:08:22Z pterjan $
+package partition_table::gpt;
use diagnostics;
use strict;
@@ -6,72 +6,201 @@ use vars qw(@ISA);
@ISA = qw(partition_table::raw);
+use fs::type;
use partition_table::raw;
use c;
-#sub use_pt_type { 1 }
+my $nb_primary = 128;
+
+my %_GUID_to_Label = (
+ # No OS
+ "00000000-0000-0000-0000-000000000000" => "Unused entry",
+ "024DEE41-33E7-11D3-9D69-0008C781F39F" => "MBR partition scheme",
+ "C12A7328-F81F-11D2-BA4B-00A0C93EC93B" => "EFI System partition",
+ "21686148-6449-6E6F-744E-656564454649" => "BIOS Boot partition",
+ "D3BFE2DE-3DAF-11DF-BA40-E3A556D89593" => "Intel Fast Flash (iFFS) partition for Rapid Start (iRST)",
+ "F4019732-066E-4E12-8273-346C5641494F" => "Sony boot partition",
+ "BFBFAFE7-A34F-448A-9A5B-6213EB736C22" => "Lenovo boot partition",
+ # Microsoft
+ "E3C9E316-0B5C-4DB8-817D-F92DF00215AE" => "Microsoft Reserved Partition (MSR)",
+ "EBD0A0A2-B9E5-4433-87C0-68B6B72699C7" => "Microsoft Basic data partition",
+ "5808C8AA-7E8F-42E0-85D2-E1E90434CFB3" => "Microsoft Logical Disk Manager (LDM) metadata partition",
+ "AF9B60A0-1431-4F62-BC68-3311714A69AD" => "Microsoft Logical Disk Manager data partition",
+ "DE94BBA4-06D1-4D40-A16A-BFD50179D6AC" => "Microsoft Windows Recovery Environment",
+ "37AFFC90-EF7D-4E96-91C3-2D7AE055B174" => "Microsoft IBM General Parallel File System (GPFS) partition",
+ "E75CAF8F-F680-4CEE-AFA3-B001E56EFC2D" => "Microsoft Storage Spaces partition",
+ # HP-UX
+ "75894C1E-3AEB-11D3-B7C1-7B03A0000000" => "HP-UX Data partition",
+ "E2A1E728-32E3-11D6-A682-7B03A0000000" => "HP-UX Service Partition",
+ # Linux
+ "0FC63DAF-8483-4772-8E79-3D69D8477DE4" => "Linux filesystem data",
+ "A19D880F-05FC-4D3B-A006-743F0F84911E" => "Linux RAID partition",
+ "0657FD6D-A4AB-43C4-84E5-0933C84B4F4F" => "Linux Swap partition",
+ "E6D6D379-F507-44C2-A23C-238F2A3DF928" => "Linux Logical Volume Manager (LVM) partition",
+ "933AC7E1-2EB4-4F13-B844-0E14E2AEF915" => "Linux /home partition",
+ "3B8F8425-20E0-4F3B-907F-1A25A76F98E8" => "Linux /srv (server data) partition",
+ "7FFEC5C9-2D00-49B7-8941-3EA10A5586B7" => "Linux Plain dm-crypt partition",
+ "CA7D7CCB-63ED-4C53-861C-1742536059CC" => "Linux LUKS partition",
+ "8DA63339-0007-60C0-C436-083AC8230908" => "Linux Reserved",
+ # FreeBSD
+ "83BD6B9D-7F41-11DC-BE0B-001560B84F0F" => "FreeBSD Boot partition",
+ "516E7CB4-6ECF-11D6-8FF8-00022D09712B" => "FreeBSD Data partition",
+ "516E7CB5-6ECF-11D6-8FF8-00022D09712B" => "FreeBSD Swap partition",
+ "516E7CB6-6ECF-11D6-8FF8-00022D09712B" => "FreeBSD Unix File System (UFS) partition",
+ "516E7CB8-6ECF-11D6-8FF8-00022D09712B" => "FreeBSD Vinum volume manager partition",
+ "516E7CBA-6ECF-11D6-8FF8-00022D09712B" => "FreeBSD ZFS partition",
+ # Mac OSX
+ "48465300-0000-11AA-AA11-00306543ECAC" => "Mac OSX Hierarchical File System Plus (HFS+) partition",
+ "55465300-0000-11AA-AA11-00306543ECAC" => "Mac OSX Apple UFS",
+ "6A898CC3-1DD2-11B2-99A6-080020736631" => "Mac OSX ZFS",
+ "52414944-0000-11AA-AA11-00306543ECAC" => "Apple RAID partition",
+ "52414944-5F4F-11AA-AA11-00306543ECAC" => "Apple RAID partition, offline",
+ "426F6F74-0000-11AA-AA11-00306543ECAC" => "Apple Boot partition",
+ "4C616265-6C00-11AA-AA11-00306543ECAC" => "Apple Label",
+ "5265636F-7665-11AA-AA11-00306543ECAC" => "Apple TV Recovery partition",
+ "53746F72-6167-11AA-AA11-00306543ECAC" => "Apple Core Storage (Lion FileVault) partition",
+ # Solaris
+ "6A82CB45-1DD2-11B2-99A6-080020736631" => "Solaris Boot partition",
+ "6A85CF4D-1DD2-11B2-99A6-080020736631" => "Solaris Root partition",
+ "6A87C46F-1DD2-11B2-99A6-080020736631" => "Solaris Swap partition",
+ "6A8B642B-1DD2-11B2-99A6-080020736631" => "Solaris Backup partition",
+ "6A898CC3-1DD2-11B2-99A6-080020736631" => "Solaris /usr partition",
+ "6A8EF2E9-1DD2-11B2-99A6-080020736631" => "Solaris /var partition",
+ "6A90BA39-1DD2-11B2-99A6-080020736631" => "Solaris /home partition",
+ "6A9283A5-1DD2-11B2-99A6-080020736631" => "Solaris Alternate sector",
+ "6A945A3B-1DD2-11B2-99A6-080020736631" => "Solaris Reserved partition",
+ "6A9630D1-1DD2-11B2-99A6-080020736631" => "Solaris Reserved partition",
+ "6A980767-1DD2-11B2-99A6-080020736631" => "Solaris Reserved partition",
+ "6A96237F-1DD2-11B2-99A6-080020736631" => "Solaris Reserved partition",
+ "6A8D2AC7-1DD2-11B2-99A6-080020736631" => "Solaris Reserved partition",
+ # NetBSD
+ "49F48D32-B10E-11DC-B99B-0019D1879648" => "NetBSD Swap partition",
+ "49F48D5A-B10E-11DC-B99B-0019D1879648" => "NetBSD FFS partition",
+ "49F48D82-B10E-11DC-B99B-0019D1879648" => "NetBSD LFS partition",
+ "49F48DAA-B10E-11DC-B99B-0019D1879648" => "NetBSD RAID partition",
+ "2DB519C4-B10F-11DC-B99B-0019D1879648" => "NetBSD Concatenated partition",
+ "2DB519EC-B10F-11DC-B99B-0019D1879648" => "NetBSD Encrypted partition",
+ # ChromeOS
+ "FE3A2A5D-4F32-41A7-B725-ACCC3285A309" => "ChromeOS kernel",
+ "3CB8E202-3B7E-47DD-8A3C-7FF2A13CFCEC" => "ChromeOS rootfs",
+ "2E0A753D-9E48-43B0-8337-B15192CB1B5E" => "ChromeOS future use",
+ # Haiku
+ "42465331-3BA3-10F1-802A-4861696B7521" => "Haiku BFS",
+ # MidnightBSD
+ "85D5E45E-237C-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD Boot partition",
+ "85D5E45A-237C-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD Data partition",
+ "85D5E45B-237C-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD Swap partition",
+ "0394EF8B-237E-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD Unix File System (UFS) partition",
+ "85D5E45C-237C-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD Vinum volume manager partition",
+ "85D5E45D-237C-11E1-B4B3-E89A8F7FC3A7" => "MidnightBSD ZFS partition",
+ # Ceph
+ "BFBFAFE7-A34F-448A-9A5B-6213EB736C22" => "Ceph Journal",
+ "45B0969E-9B03-4F30-B4C6-5EC00CEFF106" => "Ceph dm-crypt Encrypted Journal",
+ "4FBD7E29-9D25-41B8-AFD0-062C0CEFF05D" => "Ceph OSD",
+ "4FBD7E29-9D25-41B8-AFD0-5EC00CEFF05D" => "Ceph dm-crypt OSD",
+ "89C57F98-2FE5-4DC0-89C1-F3AD0CEFF2BE" => "Ceph disk in creation",
+ "89C57F98-2FE5-4DC0-89C1-5EC00CEFF2BE" => "Ceph dm-crypt disk in creation",
+);
+
+my %parted_mapping = (
+ 'linux-swap(v1)' => 'swap',
+ 'ntfs' => 'ntfs-3g',
+ 'fat16' => 'vfat',
+ 'fat32' => 'vfat',
+ );
+my %rev_parted_mapping = reverse %parted_mapping;
+# prefer 'fat32' over 'fat16':
+$rev_parted_mapping{vfat} = 'fat32';
sub read_one {
- my ($hd, $sector) = @_;
- my $info;
-
- c::get_disk_type($hd->{file}) eq "gpt" or die "not a GPT disk";
- my @pt = map {
- my %p;
- print $_;
- if (/^([^ ]*) ([^ ]*) ([^ ]*) (.*) \((\d*),(\d*),(\d*)\)$/) {
- $p{part_number} = $1;
- $p{real_device} = $2;
- $p{fs_type} = $3;
- $p{pt_type} = 0xba;
- $p{start} = $5;
- $p{size} = $7;
+ my ($hd, $_sector) = @_;
+
+ c::get_disk_type($hd->{file}) eq "gpt" or die "$hd->{device} not a GPT disk ($hd->{file})";
+
+ my @pt;
+ # FIXME: just use '@pt = map { ... } c::...' if part_numbers are always linear:
+ foreach (c::get_disk_partitions($hd->{file})) {
+ # compatibility with MBR partitions tables:
+ $_->{pt_type} = 0x82 if $_->{fs_type} eq 'swap';
+ $_->{pt_type} = 0x0b if $_->{fs_type} eq 'vfat';
+ $_->{pt_type} = 0x83 if $_->{fs_type} =~ /^ext/;
+
+ # fix detecting ESP (special case are they're detected through pt_type):
+ if ($_->{flag} eq 'ESP') {
+ $_->{pt_type} = 0xef;
+ } elsif ($_->{flag} eq 'LVM') {
+ $_->{pt_type} = 0x8e;
+ } elsif ($_->{flag} eq 'RAID') {
+ $_->{pt_type} = 0xfd;
+ } elsif ($_->{flag} eq 'RECOVERY') {
+ $_->{pt_type} = 0x12;
}
- \%p;
- } c::get_disk_partitions($hd->{file});
+ $_->{fs_type} = $parted_mapping{$_->{fs_type}} if $parted_mapping{$_->{fs_type}};
+
+ @pt[$_->{part_number}-1] = $_;
+ }
- use Data::Dumper;
- print Dumper(@pt);
+ for (my $part_number = 1; $part_number < $nb_primary; $part_number++) {
+ next if exists($pt[$part_number-1]);
+ $pt[$part_number-1] = { part_number => $part_number };
+ }
- [ @pt ], $info;
+ \@pt;
}
sub write {
- my ($hd, $sector, $pt, $info) = @_;
+ my ($hd, $_sector, $pt, $_info) = @_;
+
+ my $partitions_killed;
# Initialize the disk if current partition table is not gpt
if (c::get_disk_type($hd->{file}) ne "gpt") {
c::set_disk_type($hd->{file}, "gpt");
+ $partitions_killed = 1;
}
foreach (@{$hd->{will_tell_kernel}}) {
my ($action, $part_number, $o_start, $o_size) = @$_;
- my $part;
+ my ($part) = grep { $_->{start} == $o_start && $_->{size} == $o_size } @$pt;
print "($action, $part_number, $o_start, $o_size)\n";
if ($action eq 'add') {
- c::disk_add_partition($hd->{file}, $o_start, $o_size, $part->{fs_type}) or die "failed to add partition";
- } elsif ($action eq 'del') {
- c::disk_del_partition($hd->{file}, $part_number) or die "failed to del partition";
+ local $part->{fs_type} = $rev_parted_mapping{$part->{fs_type}} if $rev_parted_mapping{$part->{fs_type}};
+ c::disk_add_partition($hd->{file}, $o_start, $o_size, $part->{fs_type}) or die "failed to add partition #$part_number on $hd->{file}";
+ my $flag;
+ if (isESP($part)) {
+ $flag = 'ESP';
+ } elsif (isRawLVM($part)) {
+ $flag = 'LVM';
+ } elsif (isRawRAID($part)) {
+ $flag = 'RAID';
+ }
+ if ($flag) {
+ c::set_partition_flag($hd->{file}, $part_number, $flag)
+ or die "failed to set type '$flag' for $part->{file} on $part->{mntpoint}";
+ }
+ } elsif ($action eq 'del' && !$partitions_killed) {
+ c::disk_del_partition($hd->{file}, $part_number) or die "failed to del partition #$part_number on $hd->{file}";
}
}
+ # prevent errors when telling kernel to reread partition table:
+ # (above add/del_partition result in udev events)
+ system(qw(udevadm settle));
common::sync();
1;
}
sub initialize {
my ($class, $hd) = @_;
- $hd->{primary} = { raw => [] };
+ my @raw;
+ for (my $part_number = 0; $part_number < $nb_primary-1; $part_number++) {
+ # part_number starts at 1
+ $raw[$part_number] = { part_number => $part_number + 1 };
+ }
+ $hd->{primary} = { raw => \@raw };
bless $hd, $class;
}
sub can_add { &can_raw_add }
-sub can_raw_add { 1 }
-sub raw_add {
- my ($hd, $raw, $part) = @_;
- $hd->can_raw_add or die "raw_add: partition table already full";
- push @$raw, $part;
-}
-
sub adjustStart {}
sub adjustEnd {}
diff --git a/perl-install/partition_table/lvm.pm b/perl-install/partition_table/lvm.pm
index 8a28a4c2a..920507fa5 100644
--- a/perl-install/partition_table/lvm.pm
+++ b/perl-install/partition_table/lvm.pm
@@ -1,4 +1,4 @@
-package partition_table::lvm; # $Id: $
+package partition_table::lvm;
# LVM on full disk
diff --git a/perl-install/partition_table/mac.pm b/perl-install/partition_table/mac.pm
index 015feaee6..547704b45 100644
--- a/perl-install/partition_table/mac.pm
+++ b/perl-install/partition_table/mac.pm
@@ -1,4 +1,4 @@
-package partition_table::mac; # $Id: mac.pm 228416 2007-09-18 10:32:56Z pixel $
+package partition_table::mac;
use diagnostics;
#use strict; - fixed other PPC code to comply, but program bails on empty partition table - sbenedict
diff --git a/perl-install/partition_table/raw.pm b/perl-install/partition_table/raw.pm
index 09a0137e7..7b4e7d5cf 100644
--- a/perl-install/partition_table/raw.pm
+++ b/perl-install/partition_table/raw.pm
@@ -1,4 +1,4 @@
-package partition_table::raw; # $Id: raw.pm 266069 2010-02-09 19:47:35Z pterjan $
+package partition_table::raw;
use diagnostics;
use strict;
@@ -11,10 +11,6 @@ use log;
use c;
my @MBR_signatures = (
-if_(arch() =~ /ppc/,
- (map { [ 'yaboot', 0, "PM", 0x200 * $_ + 0x10, "bootstrap\0" ] } 0 .. 61), #- "PM" is a Partition Map
- [ 'yaboot', 0x400, "BD", 0x424, "\011bootstrap" ], #- "BD" is a HFS filesystem
-),
[ 'empty', 0, "\0\0\0\0" ],
[ 'grub', 0, "\xEBG", 0x17d, "stage1 \0" ],
[ 'grub', 0, "\xEBH", 0x17e, "stage1 \0" ],
@@ -29,6 +25,14 @@ if_(arch() =~ /ppc/,
substr($tmp, 0, 2) eq "\xEBH" or return;
index($tmp, $magic, $min) >= 0 && "grub";
},
+ sub { my ($F) = @_;
+ #- similar to grub-legacy, grub2 doesn't seem to have good magic
+ #- so scanning a range of possible places where grub can have its string
+ my ($min, $max, $magic) = (0x176, 0x188, "GRUB");
+ my $tmp;
+ sysseek($F, 0, 0) && sysread($F, $tmp, $max + length($magic)) or return;
+ index($tmp, $magic, $min) >= 0 && "grub2";
+ },
[ 'lilo', 0x2, "LILO" ],
[ 'lilo', 0x6, "LILO" ],
[ 'lilo', 0x6 + 0x40, "LILO" ], #- when relocated in lilo's bsect_update(), variable "space" on paragraph boundary gives 0x40
@@ -73,20 +77,9 @@ sub last_usable_sector {
sub max_partition_start { 1e99 }
sub max_partition_size { 1e99 }
-#- default method for starting a partition, only head size or twice
-#- is allowed for starting a partition after a cylinder boundarie.
-sub adjustStart($$) {
- my ($hd, $part) = @_;
- my $end = $part->{start} + $part->{size};
+#- default method for starting a partition
+sub adjustStart($$) {}
- if (cylinder_size($hd)) {
- $part->{start} = round_up($part->{start},
- $part->{start} % cylinder_size($hd) < 2 * $hd->{geom}{sectors} ?
- $hd->{geom}{sectors} : cylinder_size($hd));
- $part->{size} = $end - $part->{start};
- $part->{size} > 0 or die "adjustStart get a too small partition to handle correctly";
- }
-}
#- adjusting end to match a cylinder boundary, two methods are used and must
#- match at the end, else something is wrong and nothing will be done on
#- partition table.
@@ -133,7 +126,7 @@ sub get_geometries {
$geom{start} = 1;
compute_nb_cylinders(\%geom, $total);
$geom{totalcylinders} = $geom{cylinders};
- log::l("Fake geometry on ".$_->{file}.": heads=$geom{heads} sectors=$geom{sectors} cylinders=$geom{cylinders} start=$geom{start}");
+ log::l("Fake geometry on " . $_->{file} . ": heads=$geom{heads} sectors=$geom{sectors} cylinders=$geom{cylinders} start=$geom{start}");
add2hash_($_, { totalsectors => $total, geom => \%geom });
1;
} elsif (my $h = get_geometry($_->{file})) {
@@ -248,7 +241,8 @@ sub zero_MBR_and_dirty {
sub read_primary {
my ($hd) = @_;
- my ($pt, $info) = eval { $hd->read_one(0) } or return;
+ my ($pt, $info) = eval { $hd->read_one(0) };
+ $pt or return;
my $primary = partition_table::raw::pt_info_to_primary($hd, $pt, $info);
$hd->{primary} = $primary;
undef $hd->{extended};
@@ -296,7 +290,7 @@ sub test_for_bad_drives {
my $tmp2;
&$seek; sysread $F, $tmp2, $SECTORSIZE or die "test_for_bad_drives: cannot even read again ($!)";
$tmp eq $tmp2 or die
-N("Something bad is happening on your drive.
+N("Something bad is happening on your hard disk drive.
A test to check the integrity of data has failed.
It means writing anything on the disk will end up with random, corrupted data.");
}
diff --git a/perl-install/partition_table/readonly.pm b/perl-install/partition_table/readonly.pm
index f36b60e4a..ee3624f88 100644
--- a/perl-install/partition_table/readonly.pm
+++ b/perl-install/partition_table/readonly.pm
@@ -1,4 +1,4 @@
-package partition_table::readonly; # $Id: $
+package partition_table::readonly;
use diagnostics;
use strict;
diff --git a/perl-install/partition_table/sun.pm b/perl-install/partition_table/sun.pm
index 47d702621..e2fd747ac 100644
--- a/perl-install/partition_table/sun.pm
+++ b/perl-install/partition_table/sun.pm
@@ -1,4 +1,4 @@
-package partition_table::sun; # $Id: sun.pm 228416 2007-09-18 10:32:56Z pixel $
+package partition_table::sun;
use diagnostics;
use strict;