summaryrefslogtreecommitdiffstats
path: root/perl-install/fsedit.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/fsedit.pm')
-rw-r--r--perl-install/fsedit.pm336
1 files changed, 222 insertions, 114 deletions
diff --git a/perl-install/fsedit.pm b/perl-install/fsedit.pm
index cbe94f5c1..d209b0196 100644
--- a/perl-install/fsedit.pm
+++ b/perl-install/fsedit.pm
@@ -1,8 +1,9 @@
-package fsedit; # $Id$
+package fsedit;
use diagnostics;
use strict;
use vars qw(%suggestions);
+use feature 'state';
#-######################################################################################
#- misc imports
@@ -19,34 +20,56 @@ use devices;
use log;
use fs;
+# min_hd_size: only suggest this partition if the hd size is bigger than that
%suggestions = (
N_("simple") => [
- { mntpoint => "/", size => 300 << 11, fs_type => 'ext3', ratio => 5, maxsize => 6000 << 11 },
- { mntpoint => "swap", size => 64 << 11, fs_type => 'swap', ratio => 1, maxsize => 1100 << 11 },
- { mntpoint => "/home", size => 300 << 11, fs_type => 'ext3', ratio => 3 },
+ { mntpoint => "/", size => MB(300), fs_type => defaultFS(), ratio => 6, maxsize => MB(51500) },
+ { mntpoint => "swap", size => MB(256), fs_type => 'swap', ratio => 1, maxsize => MB(4096) },
+ { mntpoint => "/home", size => MB(300), fs_type => defaultFS(), ratio => 12, min_hd_size => MB(51200) },
], N_("with /usr") => [
- { mntpoint => "/", size => 250 << 11, fs_type => 'ext3', ratio => 1, maxsize => 2000 << 11 },
- { mntpoint => "swap", size => 64 << 11, fs_type => 'swap', ratio => 1, maxsize => 1100 << 11 },
- { mntpoint => "/usr", size => 300 << 11, fs_type => 'ext3', ratio => 4, maxsize => 4000 << 11 },
- { mntpoint => "/home", size => 100 << 11, fs_type => 'ext3', ratio => 3 },
+ { mntpoint => "/", size => MB(250), fs_type => defaultFS(), ratio => 1, maxsize => MB(8000) },
+ { mntpoint => "swap", size => MB(64), fs_type => 'swap', ratio => 1, maxsize => MB(4000) },
+ { mntpoint => "/usr", size => MB(300), fs_type => defaultFS(), ratio => 4, maxsize => MB(8000) },
+ { mntpoint => "/home", size => MB(100), fs_type => defaultFS(), ratio => 3, min_hd_size => MB(10000) },
], N_("server") => [
- { mntpoint => "/", size => 150 << 11, fs_type => 'ext3', ratio => 1, maxsize => 800 << 11 },
- { mntpoint => "swap", size => 64 << 11, fs_type => 'swap', ratio => 2, maxsize => 1600 << 11 },
- { mntpoint => "/usr", size => 300 << 11, fs_type => 'ext3', ratio => 4, maxsize => 4000 << 11 },
- { mntpoint => "/var", size => 200 << 11, fs_type => 'ext3', ratio => 3 },
- { mntpoint => "/home", size => 150 << 11, fs_type => 'ext3', ratio => 3 },
- { mntpoint => "/tmp", size => 150 << 11, fs_type => 'ext3', ratio => 2, maxsize => 1000 << 11 },
+ { mntpoint => "/", size => MB(150), fs_type => defaultFS(), ratio => 1, maxsize => MB(8000) },
+ { mntpoint => "swap", size => MB(64), fs_type => 'swap', ratio => 2, maxsize => MB(4000) },
+ { mntpoint => "/usr", size => MB(300), fs_type => defaultFS(), ratio => 4, maxsize => MB(8000) },
+ { mntpoint => "/var", size => MB(200), fs_type => defaultFS(), ratio => 3 },
+ { mntpoint => "/home", size => MB(150), fs_type => defaultFS(), ratio => 3, min_hd_size => MB(10000) },
+ { mntpoint => "/tmp", size => MB(150), fs_type => defaultFS(), ratio => 2, maxsize => MB(4000) },
],
);
-foreach (values %suggestions) {
- if (arch() =~ /ia64/) {
- @$_ = ({ mntpoint => "/boot/efi", size => 50 << 11, pt_type => 0xef, ratio => 1, maxsize => 150 << 11 }, @$_);
+my %bck_suggestions = %suggestions;
+
+sub init_mntpnt_suggestions {
+ my ($all_hds, $o_target, $o_force) = @_;
+
+ my $device = $o_target ? $o_target->{device} : 'all';
+ state $last_device;
+ return if $device eq $last_device && !$o_force;
+ $last_device = $device;
+
+ #- If installing on a removable device, assume that the user wants that device to be self-bootable.
+ my $is_removable = $o_target && $o_target->{is_removable};
+ my @fstab = $is_removable ? partition_table::get_normal_parts($o_target) : fs::get::fstab($all_hds);
+
+ my $mntpoint;
+ # only suggests /boot/EFI if there's not already one:
+ require fs::any;
+ if (is_uefi()) {
+ if (!any { isESP($_) } @fstab) {
+ $mntpoint = { mntpoint => "/boot/EFI", size => MB(100), pt_type => 0xef, ratio => 1, maxsize => MB(300) };
+ }
+ }
+ foreach (keys %suggestions) {
+ $suggestions{$_} = [ if_($mntpoint, $mntpoint), @{$bck_suggestions{$_}} ];
}
}
my @suggestions_mntpoints = (
"/var/ftp", "/var/www", "/boot", '/usr/local', '/opt',
- arch() =~ /sparc/ ? "/mnt/sunos" : arch() =~ /ppc/ ? "/mnt/macos" : "/mnt/windows",
+ "/mnt/windows",
);
#-######################################################################################
@@ -59,11 +82,11 @@ sub recompute_loopbacks {
}
sub raids {
- my ($hds) = @_;
+ my ($hds, $raw_hds) = @_;
my @parts = fs::get::hds_fstab(@$hds);
- my @l = grep { isRawRAID($_) } @parts or return [];
+ my @l = grep { isRawRAID($_) } ( @parts, @$raw_hds ) or return [];
log::l("looking for raids in " . join(' ', map { $_->{device} } @l));
@@ -72,9 +95,29 @@ sub raids {
raid::get_existing(@l);
}
+sub dmcrypts {
+ my ($all_hds) = @_;
+
+ my @parts = fs::get::fstab($all_hds);
+
+ my @l = grep { fs::type::isRawLUKS($_) } @parts or return;
+
+ log::l("using dm-crypt from " . join(' ', map { $_->{device} } @l));
+
+ require fs::dmcrypt;
+ fs::dmcrypt::read_crypttab($all_hds);
+
+ fs::dmcrypt::get_existing(@l);
+}
+
sub lvms {
my ($all_hds) = @_;
my @pvs = grep { isRawLVM($_) } fs::get::fstab($all_hds) or return;
+ scan_pvs(@pvs);
+}
+
+sub scan_pvs {
+ my (@pvs) = @_;
log::l("looking for vgs in " . join(' ', map { $_->{device} } @pvs));
@@ -99,17 +142,31 @@ sub lvms {
}
sub handle_dmraid {
- my ($drives) = @_;
+ my ($drives, $o_in) = @_;
@$drives > 1 or return;
devices::make($_->{device}) foreach @$drives;
- eval { require fs::dmraid; 1 } or return;
+ require fs::dmraid;
+ eval { fs::dmraid::init() } or log::l("dmraid::init failed"), return;
my @vgs = fs::dmraid::vgs();
log::l(sprintf('dmraid: ' . join(' ', map { "$_->{device} [" . join(' ', @{$_->{disks}}) . "]" } @vgs)));
+ if ($o_in && @vgs && $::isInstall) {
+ @vgs = grep {
+ $o_in->ask_yesorno('', N("BIOS software RAID detected on disks %s. Activate it?", join(' ', @{$_->{disks}})), 1);
+ } @vgs or do {
+ fs::dmraid::call_dmraid('-an');
+ return;
+ };
+ }
+ if (!$::isInstall) {
+ fs::dmraid::migrate_device_names($_) foreach @vgs;
+ }
+ log::l("using dmraid on " . join(' ', map { $_->{device} } @vgs));
+
my @used_hds = map {
my $part = fs::get::device2part($_, $drives) or log::l("handle_dmraid: can't find $_ in known drives");
if_($part, $part);
@@ -128,11 +185,10 @@ sub get_hds {
my @drives = detect_devices::hds();
#- replace drives used in dmraid by the merged name
- handle_dmraid(\@drives);
+ handle_dmraid(\@drives, $o_in) if !$flags->{nodmraid};
foreach my $hd (@drives) {
$hd->{file} = devices::make($hd->{device});
- $hd->{prefix} ||= $hd->{device};
}
@drives = partition_table::raw::get_geometries(@drives);
@@ -141,9 +197,25 @@ sub get_hds {
foreach my $hd (@drives) {
$hd->{readonly} = $flags->{readonly};
+ #- We only create RAID components in disk partitions, but users may have used
+ #- mdadm directly to create them on raw disk devices. Detect that now, before
+ #- looking for a partition table (which is likely to fail badly - mga#26707).
+ if (my $type = fs::type::type_subpart_from_magic($hd)) {
+ if (isRawRAID($type)) {
+ #- Add the necessary information to the raw device to allow the RAID
+ #- array to be properly characterised in diskdrake.
+ put_in_hash($hd, $type);
+ $hd->{size} = $hd->{totalsectors};
+ push @raw_hds, $hd;
+ next;
+ }
+ }
+
eval { partition_table::raw::test_for_bad_drives($hd) if !$flags->{no_bad_drives} };
if (my $err = $@) {
+ log::l("test_for_bad_drives returned $err");
if ($err =~ /write error:/) {
+ log::l("setting $hd->{device} readonly");
$hd->{readonly} = 1;
} elsif ($err =~ /read error:/) {
next;
@@ -154,14 +226,11 @@ sub get_hds {
}
if ($flags->{clearall} || member($hd->{device}, @{$flags->{clear} || []})) {
- partition_table::raw::zero_MBR_and_dirty($hd);
+ my $lvms = []; #- temporary one, will be re-created later in get_hds()
+ partition_table_clear_and_initialize($lvms, $hd, $o_in);
} else {
my $handle_die_and_cdie = sub {
- if ($hd->{readonly}) {
- log::l("using /proc/partitions since diskdrake failed :(");
- fs::proc_partitions::use_($hd);
- 1;
- } elsif (my $type = fs::type::type_subpart_from_magic($hd)) {
+ if (my $type = fs::type::type_subpart_from_magic($hd)) {
#- non partitioned drive?
if (exists $hd->{usb_description} && $type->{fs_type}) {
#- USB keys
@@ -169,16 +238,13 @@ sub get_hds {
push @raw_hds, $hd;
$hd = '';
1;
- } elsif ($type->{pt_type} == 0x8e) {
- #- LVM on full disk
- my $part = { size => $hd->{totalsectors}, device => $hd->{device}, %$type };
- bless $hd, 'partition_table::raw';
- $hd->{readonly} = $hd->{getting_rid_of_readonly_allowed} = 1;
- $hd->{primary}{normal} = [ $part ];
- 1;
} else {
0;
}
+ } elsif ($hd->{readonly}) {
+ log::l("using /proc/partitions since diskdrake failed :(");
+ fs::proc_partitions::use_($hd);
+ 1;
} else {
0;
}
@@ -189,8 +255,15 @@ sub get_hds {
partition_table::read($hd);
if (listlength(partition_table::get_normal_parts($hd)) == 0) {
$handled = 1 if $handle_die_and_cdie->();
- } else {
- fs::proc_partitions::compare($hd) if !fs::type::is_dmraid($hd) && $::isInstall;
+ } elsif ($::isInstall) {
+ if (fs::type::is_dmraid($hd)) {
+ if (my $p = find { ! -e "/dev/$_->{device}" } partition_table::get_normal_parts($hd)) {
+ #- dmraid should have created the device, so it means we don't agree
+ die sprintf(q(bad dmraid (missing partition %s), you may try rebooting install with option "nodmraid"), $p->{device});
+ }
+ } else {
+ fs::proc_partitions::compare($hd) if !detect_devices::is_xbox();
+ }
}
} sub {
my $err = $@;
@@ -207,7 +280,7 @@ sub get_hds {
#- already handled in cdie handler above
} elsif ($handle_die_and_cdie->()) {
} elsif ($o_in && $o_in->ask_yesorno(N("Error"),
-N("I can not read the partition table of device %s, it's too corrupted for me :(
+N("I cannot read the partition table of device %s, it's too corrupted for me :(
I can try to go on, erasing over bad partitions (ALL DATA will be lost!).
The other solution is to not allow DrakX to modify the partition table.
(the error is %s)
@@ -229,29 +302,21 @@ Do you agree to lose all the partitions?
my @parts = partition_table::get_normal_parts($hd);
+ # fix installer failures due to udev's race when run too early:
+ run_program::run('udevadm', 'settle');
+
# checking the magic of the filesystem, do not rely on pt_type
- foreach (grep { member($_->{fs_type}, 'vfat', 'ntfs', 'ext2') || $_->{pt_type} == 0x100 } @parts) {
+ foreach (@parts) {
if (my $type = fs::type::type_subpart_from_magic($_)) {
- if ($type->{fs_type}) {
- #- keep {pt_type}
- $_->{fs_type} = $type->{fs_type};
- } else {
- put_in_hash($_, $type);
- }
+ $type->{pt_type} = $_->{pt_type}; #- keep {pt_type}
+ put_in_hash($_, $type);
} else {
$_->{bad_fs_type_magic} = 1;
}
}
-
- foreach (@parts) {
- my $label =
- member($_->{fs_type}, qw(ext2 ext3)) ?
- c::get_ext2_label(devices::make($_->{device})) :
- '';
- $_->{device_LABEL} = $label if $label;
- }
if ($hd->{usb_media_type}) {
+ $hd->{is_removable} = 1;
$_->{is_removable} = 1 foreach @parts;
}
@@ -259,13 +324,20 @@ Do you agree to lose all the partitions?
}
#- detect raids before LVM allowing LVM on raid
- my $raids = raids(\@hds);
+ my $raids = raids(\@hds, \@raw_hds);
my $all_hds = { %{ fs::get::empty_all_hds() }, hds => \@hds, raw_hds => \@raw_hds, lvms => [], raids => $raids };
$all_hds->{lvms} = [ lvms($all_hds) ];
fs::get_major_minor([ fs::get::fstab($all_hds) ]);
+ # must be done after getting major/minor
+ $all_hds->{dmcrypts} = [ dmcrypts($all_hds) ];
+ # allow lvm on dmcrypt
+ $all_hds->{lvms} = [ lvms($all_hds) ];
+
+ $_->{faked_device} = 0 foreach fs::get::fstab($all_hds);
+
$all_hds;
}
@@ -283,12 +355,12 @@ sub is_one_big_fat_or_NT {
@$hds == 1 or return 0;
my @l = fs::get::hds_fstab(@$hds);
- @l == 1 && isFat_or_NTFS($l[0]) && fs::get::hds_free_space(@$hds) < 10 << 11;
+ @l == 1 && isFat_or_NTFS($l[0]) && fs::get::hds_free_space(@$hds) < MB(10);
}
sub computeSize {
- my ($part, $best, $all_hds, $suggestions) = @_;
+ my ($part, $best, $all_hds, $suggestions, $o_target) = @_;
my $max = $part->{maxsize} || $part->{size};
return min($max, $best->{size}) unless $best->{ratio};
@@ -303,7 +375,7 @@ sub computeSize {
1;
} else { 0 } } @$suggestions;
- my $free_space = $best->{hd} && $free_space{$best->{hd}} || sum(values %free_space);
+ my $free_space = $o_target && $free_space{$o_target->{device}} || $best->{hd} && $free_space{$best->{hd}} || sum(values %free_space);
my $cylinder_size_maxsize_adjusted;
my $tot_ratios = 0;
@@ -334,7 +406,7 @@ sub computeSize {
}
sub suggest_part {
- my ($part, $all_hds, $o_suggestions) = @_;
+ my ($part, $all_hds, $o_suggestions, $o_target) = @_;
my $suggestions = $o_suggestions || $suggestions{server} || $suggestions{simple};
#- suggestions now use {fs_type}, but still keep compatibility
@@ -342,13 +414,26 @@ sub suggest_part {
fs::type::set_pt_type($_, $_->{pt_type}) if !exists $_->{fs_type};
}
- my $has_swap = any { isSwap($_) } fs::get::fstab($all_hds);
+ my $hd = fs::get::part2hd($part, $all_hds);
+ my $hd_size = $hd && $hd->{totalsectors}; # nb: no $hd if $part is /dev/mdX
+ my @fstab = $hd->{is_removable} ? partition_table::get_normal_parts($hd) : fs::get::fstab($all_hds);
+ my $has_swap = any { isSwap($_) } @fstab;
my @local_suggestions =
- grep { !fs::get::has_mntpoint($_->{mntpoint}, $all_hds) || isSwap($_) && !$has_swap }
+ grep { $::auto_install || !$_->{mntpoint} && !$_->{VG_name} || !fs::get::has_mntpoint($_->{mntpoint}, $all_hds) || isSwap($_) && !$has_swap }
+ grep { !$_->{min_hd_size} || !$hd_size || $_->{min_hd_size} <= $hd_size }
grep { !$_->{hd} || $_->{hd} eq $part->{rootDevice} }
@$suggestions;
+ #- this allows specifying the size using a relative size.
+ #- one should rather use {ratio} instead
+ foreach (@local_suggestions) {
+ if ($_->{percent_size} && $_->{percent_size} =~ /(.+?)%?$/) {
+ $_->{size} = $1 / 100 * $hd_size;
+ log::l("in suggestion, setting size=$_->{size} for percent_size=$_->{percent_size}");
+ }
+ }
+
my ($best) =
grep { !$_->{maxsize} || $part->{size} <= $_->{maxsize} }
grep { $_->{size} <= ($part->{maxsize} || $part->{size}) }
@@ -359,11 +444,12 @@ sub suggest_part {
$part->{mntpoint} = $best->{mntpoint};
fs::type::set_type_subpart($part, $best) if !isTrueFS($best) || !isTrueFS($part);
- $part->{size} = computeSize($part, $best, $all_hds, \@local_suggestions);
- foreach ('options', 'lv_name', 'encrypt_key', 'device_LABEL', 'prefer_device_LABEL', 'primaryOrExtended') {
+ $part->{size} = computeSize($part, $best, $all_hds, \@local_suggestions, $o_target);
+ foreach ('options', 'lv_name', 'encrypt_key', 'primaryOrExtended',
+ 'device_LABEL', 'prefer_device_LABEL', 'device_UUID', 'prefer_device_UUID', 'prefer_device') {
$part->{$_} = $best->{$_} if $best->{$_};
}
- 1;
+ $best;
}
sub suggestions_mntpoint {
@@ -382,26 +468,25 @@ sub check_mntpoint {
$mntpoint =~ m|[\x7f-\xff]| and cdie N("Mount points should contain only alphanumerical characters");
fs::get::mntpoint2part($mntpoint, [ grep { $_ ne $part } fs::get::really_all_fstab($all_hds) ]) and die N("There is already a partition with mount point %s\n", $mntpoint);
- cdie N("You've selected a software RAID partition as root (/).
+ if ($mntpoint eq "/" && (isLUKS($part) || isRawLUKS($part)) && !fs::get::has_mntpoint("/boot", $all_hds)) {
+ cdie N("You've selected an encrypted partition as root (/).
No bootloader is able to handle this without a /boot partition.
-Please be sure to add a /boot partition") if $mntpoint eq "/" && isRAID($part) && !fs::get::has_mntpoint("/boot", $all_hds);
+Please be sure to add a separate /boot partition");
+ }
- #- NB: if the LV doesn't exist, lv_nb_pvs returns 0
- die N("You can not use a LVM Logical Volume for mount point %s since it spans physical volumes", $mntpoint)
- if $mntpoint eq '/boot' && isLVM($part) && lvm::lv_nb_pvs($part) > 1;
- cdie N("You've selected a LVM Logical Volume as root (/).
-The bootloader is not able to handle this when the volume spans physical volumes.
-You should create a /boot partition first") if $mntpoint eq "/" && isLVM($part) && lvm::lv_nb_pvs($part) != 1 && !fs::get::has_mntpoint("/boot", $all_hds);
+ if ($mntpoint eq "/boot" && (isLUKS($part) || isRawLUKS($part))) {
+ die N("You cannot use an encrypted filesystem for mount point %s", "/boot");
+ }
cdie N("This directory should remain within the root filesystem")
if member($mntpoint, qw(/root));
die N("This directory should remain within the root filesystem")
- if member($mntpoint, qw(/bin /dev /etc /lib /sbin /mnt));
- die N("You need a true filesystem (ext2/ext3, reiserfs, xfs, or jfs) for this mount point\n")
+ if member($mntpoint, qw(/bin /dev /etc /lib /sbin /mnt /media));
+ die N("You need a true filesystem (ext2/3/4, reiserfs, xfs, or jfs) for this mount point\n")
if !isTrueLocalFS($part) && $mntpoint eq '/';
- die N("You need a true filesystem (ext2/ext3, reiserfs, xfs, or jfs) for this mount point\n")
- if !isTrueFS($part) && member($mntpoint, fs::type::directories_needed_to_boot());
- die N("You can not use an encrypted file system for mount point %s", $mntpoint)
+ die N("You need a true filesystem (ext2/3/4, reiserfs, xfs, or jfs) for this mount point\n") . $mntpoint
+ if !isTrueFS($part) && member($mntpoint, '/home', fs::type::directories_needed_to_boot_not_ESP());
+ die N("You cannot use an encrypted filesystem for mount point %s", $mntpoint)
if $part->{options} =~ /encrypted/ && member($mntpoint, qw(/ /usr /var /boot));
local $part->{mntpoint} = $mntpoint;
@@ -422,30 +507,42 @@ sub add {
} else {
partition_table::add($hd, $part, $options->{primaryOrExtended});
}
+ fs::get_major_minor([ $part ]);
}
sub allocatePartitions {
- my ($all_hds, $to_add) = @_;
+ my ($all_hds, $to_add, $o_hd) = @_;
- foreach my $part_ (fs::get::holes($all_hds)) {
+ my @to_add = @$to_add;
+
+ foreach my $part_ (fs::get::holes($all_hds, 'non_readonly')) {
my ($start, $size, $dev) = @$part_{"start", "size", "rootDevice"};
- my $part;
- while (suggest_part($part = { start => $start, size => 0, maxsize => $size, rootDevice => $dev },
- $all_hds, $to_add)) {
+ next if $o_hd && (($o_hd->{device} || $o_hd->{VG_name}) ne $dev);
+ my ($part, $suggested);
+ while ($suggested = suggest_part($part = { start => $start, size => 0, maxsize => $size, rootDevice => $dev },
+ $all_hds, \@to_add, $o_hd)) {
my $hd = fs::get::part2hd($part, $all_hds);
add($hd, $part, $all_hds, { primaryOrExtended => $part->{primaryOrExtended} });
$size -= $part->{size} + $part->{start} - $start;
$start = $part->{start} + $part->{size};
+ @to_add = grep { $_ != $suggested } @to_add;
}
}
}
sub auto_allocate {
- my ($all_hds, $o_suggestions) = @_;
+ my ($all_hds, $o_suggestions, $o_target) = @_;
my $before = listlength(fs::get::fstab($all_hds));
+ #- Make sure we don't finish with more than one /boot/EFI mount point
+ if (is_uefi()) {
+ delete $_->{mntpoint} foreach grep { $_->{mntpoint} eq '/boot/EFI' } fs::get::fstab($all_hds);
+ }
+
+ auto_allocate_bios_boot_parts($all_hds, $o_target) if !is_uefi();
+
my $suggestions = $o_suggestions || $suggestions{simple};
- allocatePartitions($all_hds, $suggestions);
+ allocatePartitions($all_hds, $suggestions, $o_target);
if ($o_suggestions) {
auto_allocate_raids($all_hds, $suggestions);
@@ -467,6 +564,28 @@ sub auto_allocate {
die N("Nothing to do");
}
}
+
+ #- Don't suggest mount points on other drives when installing on a removable disk
+ return if $o_target && $o_target->{is_removable};
+
+ my @fstab = fs::get::fstab($all_hds);
+ fs::mount_point::suggest_mount_points_always(\@fstab);
+}
+
+sub auto_allocate_bios_boot_parts {
+ my ($all_hds, $o_hd) = @_;
+ foreach my $hd (@{$all_hds->{hds}}) {
+ # skip if not the selected device
+ next if $o_hd && ($o_hd->{device} ne $hd->{device});
+ # skip non-GPT disks
+ next if ($hd->{pt_table_type} || partition_table::default_type($hd)) ne 'gpt';
+ # check if a BIOS boot partition already exists
+ my @parts = map { partition_table::get_normal_parts($_) } $hd;
+ next if any { isBIOS_GRUB($_) } @parts;
+ # try to allocate a BIOS boot partition
+ my $suggest = { mntpoint => "", size => MB(1), pt_type => 'BIOS_GRUB', ratio => 1, maxsize => MB(2) };
+ allocatePartitions($all_hds, [ $suggest ], $hd);
+ }
}
sub auto_allocate_raids {
@@ -525,44 +644,33 @@ sub change_type {
my ($type, $hd, $part) = @_;
$type->{pt_type} != $part->{pt_type} || $type->{fs_type} ne $part->{fs_type} or return;
fs::type::check($type->{fs_type}, $hd, $part);
+ delete $part->{device_UUID};
$hd->{isDirty} = 1;
$part->{mntpoint} = '' if isSwap($part) && $part->{mntpoint} eq "swap";
- $part->{mntpoint} = '' if isRawLVM($type) || isRawRAID($type);
+ $part->{mntpoint} = '' if fs::type::cannotBeMountable($part);
set_isFormatted($part, 0);
fs::type::set_type_subpart($part, $type);
fs::mount_options::rationalize($part);
1;
}
-sub rescuept($) {
- my ($hd) = @_;
- my ($ext, @hd);
-
- my $dev = devices::make($hd->{device});
- open(my $F, "rescuept $dev|");
- local $_;
- while (<$F>) {
- my ($st, $si, $id) = /start=\s*(\d+),\s*size=\s*(\d+),\s*Id=\s*(\d+)/ or next;
- my $part = { start => $st, size => $si };
- fs::type::set_pt_type($part, hex($id));
- if (isExtended($part)) {
- $ext = $part;
- } else {
- push @hd, $part;
- }
- }
- close $F or die "rescuept failed";
-
- partition_table::raw::zero_MBR($hd);
- foreach (@hd) {
- my $b = partition_table::verifyInside($_, $ext);
- if ($b) {
- $_->{start}--;
- $_->{size}++;
- }
- local $_->{notFormatted};
+=item partition_table_clear_and_initialize($lvms, $hd, $o_in, $o_type, $b_warn) = @_;
- partition_table::add($hd, $_, ($b ? 'Extended' : 'Primary'), 1);
+wrapper around partition_table::initialize() but which also create a singleton VG
+automatically (so that it's easier for the user)
+
+=cut
+
+sub partition_table_clear_and_initialize {
+ my ($lvms, $hd, $o_in, $o_type, $b_warn) = @_;
+ partition_table::initialize($hd, $o_type);
+ if ($hd->isa('partition_table::lvm')) {
+ if ($b_warn && $o_in) {
+ $o_in->ask_okcancel_('', N("ALL existing partitions and their data will be lost on drive %s", partition_table::description($hd))) or return;
+ }
+ require lvm;
+ lvm::check($o_in ? $o_in->do_pkgs : do_pkgs_standalone->new) if $::isStandalone;
+ lvm::create_singleton_vg($lvms, fs::get::hds_fstab($hd));
}
}