/[fai]/people/michael/experimental/patches/setup-storage_gpt-bios
ViewVC logotype

Contents of /people/michael/experimental/patches/setup-storage_gpt-bios

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5381 - (show annotations) (download)
Tue Apr 28 11:56:01 2009 UTC (4 years, 1 month ago) by mt
File size: 8127 byte(s)
Improved patch for GPT-BIOS stuff
1 2009-04-28 Michael Tautschnig <mt@debian.org>
2
3 * setup-storage/Parser.pm, setup-storage/Sizes.pm, setup-storage/Volumes.pm:
4 Added pseudo-disklabel gpt-bios to support GPT on systems with BIOS instead
5 of EFI. Also installs an additional partition to store whatever doesn't fit
6 into MBR.
7 Index: trunk/lib/setup-storage/Commands.pm
8 ===================================================================
9 --- trunk.orig/lib/setup-storage/Commands.pm
10 +++ trunk/lib/setup-storage/Commands.pm
11 @@ -673,16 +673,17 @@
12 # the list of partitions that must be preserved
13 my @to_preserve = &FAI::get_preserved_partitions($config);
14
15 + my $label = $FAI::configs{$config}{disklabel};
16 + $label = "gpt" if ($label eq "gpt-bios");
17 # A new disk label may only be written if no partitions need to be
18 # preserved
19 - (($FAI::configs{$config}{disklabel} eq
20 - $FAI::current_config{$disk}{disklabel})
21 + (($label eq $FAI::current_config{$disk}{disklabel})
22 || (scalar (@to_preserve) == 0))
23 or die "Can't change disklabel, partitions are to be preserved\n";
24
25 # write the disklabel to drop the previous partition table
26 - &FAI::push_command( "parted -s $disk mklabel " .
27 - $FAI::configs{$config}{disklabel}, "exist_$disk", "cleared1_$disk" );
28 + &FAI::push_command( "parted -s $disk mklabel $label", "exist_$disk",
29 + "cleared1_$disk" );
30
31 &FAI::rebuild_preserved_partitions($config, \@to_preserve);
32
33 @@ -785,9 +786,8 @@
34
35 # write the disklabel again to drop the partition table and create a new one
36 # that has the proper ids
37 - &FAI::push_command( "parted -s $disk mklabel " .
38 - $FAI::configs{$config}{disklabel}, "cleared1_$disk$pre_all_resize",
39 - "cleared2_$disk" );
40 + &FAI::push_command( "parted -s $disk mklabel $label",
41 + "cleared1_$disk$pre_all_resize", "cleared2_$disk" );
42
43 my $prev_id = -1;
44 # generate the commands for creating all partitions
45 @@ -837,6 +837,14 @@
46 &FAI::make_device_name($disk, $FAI::configs{$config}{bootable}),
47 "boot_set_$disk" );
48 }
49 +
50 + # set the bios_grub flag on BIOS compatible GPT tables
51 + if ($FAI::configs{$config}{disklabel} eq "gpt-bios") {
52 + &FAI::push_command( "parted -s $disk set " .
53 + $FAI::configs{$config}{gpt_bios_part} . " bios_grub on", "exist_" .
54 + &FAI::make_device_name($disk, $FAI::configs{$config}{gpt_bios_part}),
55 + "bios_grub_set_$disk" );
56 + }
57 }
58
59
60 Index: trunk/lib/setup-storage/Parser.pm
61 ===================================================================
62 --- trunk.orig/lib/setup-storage/Parser.pm
63 +++ trunk/lib/setup-storage/Parser.pm
64 @@ -431,7 +431,7 @@
65 $FAI::configs{$FAI::device}{partitions}{$_}{size}{resize} = 1 foreach (split(",", $1));
66 $FAI::configs{$FAI::device}{preserveparts} = 1;
67 }
68 - | /^disklabel:(msdos|gpt)/
69 + | /^disklabel:(msdos|gpt-bios|gpt)/
70 {
71 # set the disk label - actually not only the above, but all types
72 # supported by parted could be allowed, but others are not implemented
73 Index: trunk/lib/setup-storage/Sizes.pm
74 ===================================================================
75 --- trunk.orig/lib/setup-storage/Sizes.pm
76 +++ trunk/lib/setup-storage/Sizes.pm
77 @@ -353,7 +353,8 @@
78 }
79
80 # on gpt, ensure that the partition ends at a sector boundary
81 - if ($FAI::configs{$config}{disklabel} eq "gpt") {
82 + if ($FAI::configs{$config}{disklabel} eq "gpt" ||
83 + $FAI::configs{$config}{disklabel} eq "gpt-bios") {
84 (0 == ($current_disk->{partitions}{$part_id}{end_byte} + 1)
85 % $current_disk->{sector_size})
86 or die "Preserved partition $part_id does not end at a sector boundary\n";
87 @@ -548,7 +549,8 @@
88 }
89
90 # on gpt, ensure that the partition ends at a sector boundary
91 - if ($FAI::configs{$config}{disklabel} eq "gpt") {
92 + if ($FAI::configs{$config}{disklabel} eq "gpt" ||
93 + $FAI::configs{$config}{disklabel} eq "gpt-bios") {
94 $end_byte -=
95 ($end_byte + 1) % $current_disk->{sector_size};
96 }
97 @@ -621,18 +623,17 @@
98 # the start byte for the next partition
99 my $next_start = 0;
100
101 - # on msdos disk labels, the first partitions starts at head #1
102 if ($FAI::configs{$config}{disklabel} eq "msdos") {
103 + # on msdos disk labels, the first partitions starts at head #1
104 $next_start = $current_disk->{bios_sectors_per_track} *
105 $current_disk->{sector_size};
106
107 # the MBR requires space, too
108 $min_req_total_space += $current_disk->{bios_sectors_per_track} *
109 $current_disk->{sector_size};
110 - }
111
112 - # on GPT disk labels the first 34 and last 34 sectors must be left alone
113 - if ($FAI::configs{$config}{disklabel} eq "gpt") {
114 + } elsif ($FAI::configs{$config}{disklabel} eq "gpt") {
115 + # on GPT-EFI disk labels the first 34 and last 34 sectors must be left alone
116 $next_start = 34 * $current_disk->{sector_size};
117
118 # modify the disk to claim the space for the second partition table
119 @@ -640,6 +641,35 @@
120
121 # the space required by the GPTs
122 $min_req_total_space += 2 * 34 * $current_disk->{sector_size};
123 +
124 + } elsif ($FAI::configs{$config}{disklabel} eq "gpt-bios") {
125 + # on BIOS-style disk labels, the first partitions starts at head #1
126 + $next_start = $current_disk->{bios_sectors_per_track} *
127 + $current_disk->{sector_size};
128 +
129 + # the MBR requires space, too
130 + $min_req_total_space += $current_disk->{bios_sectors_per_track} *
131 + $current_disk->{sector_size};
132 +
133 + # apparently parted insists in having some space left at the end too
134 + # modify the disk to claim the space for the second partition table
135 + $current_disk->{end_byte} -= 34 * $current_disk->{sector_size};
136 +
137 + # the space required by the GPTs
138 + $min_req_total_space += 34 * $current_disk->{sector_size};
139 +
140 + # on gpt-bios we'll need an additional partition to store what doesn't fit
141 + # in the MBR
142 + $FAI::device = $config;
143 + &FAI::init_part_config("primary");
144 + $FAI::configs{$config}{gpt_bios_part} = $FAI::partition_pointer->{number};
145 + my $s = &FAI::convert_unit("120k");
146 + # enter the range into the hash
147 + $FAI::partition_pointer->{size}->{range} = "$s-$s";
148 + # set proper defaults
149 + $FAI::partition_pointer->{encrypt} = 0;
150 + $FAI::partition_pointer->{filesystem} = "-";
151 + $FAI::partition_pointer->{mountpoint} = "-";
152 }
153
154 # the list of partitions that we need to find start and end bytes for
155 @@ -690,7 +720,7 @@
156
157 # msdos does not support partitions larger than 2TB
158 ($part->{size}->{eff_size} > (&FAI::convert_unit("2TB") * 1024.0 *
159 - 1024.0)) and die "msdos disklabel does not support partitions > 2TB, please use disklabel:gpt\n"
160 + 1024.0)) and die "msdos disklabel does not support partitions > 2TB, please use disklabel:gpt or gpt-bios\n"
161 if ($FAI::configs{$config}{disklabel} eq "msdos");
162 # partition done
163 shift @worklist;
164 Index: trunk/man/setup-storage.8
165 ===================================================================
166 --- trunk.orig/man/setup-storage.8
167 +++ trunk/man/setup-storage.8
168 @@ -216,7 +216,7 @@
169 .br
170 /* attempt to resize partitions */
171 .br
172 - | disklabel:(msdos|gpt)
173 + | disklabel:(msdos|gpt|gpt-bios)
174 .br
175 /* write a disklabel - default is msdos */
176 .br
177 Index: trunk/lib/setup-storage/Volumes.pm
178 ===================================================================
179 --- trunk.orig/lib/setup-storage/Volumes.pm
180 +++ trunk/lib/setup-storage/Volumes.pm
181 @@ -78,8 +78,9 @@
182 "Can't run on test-only mode on this system because there is no disklabel on $disk\n";
183
184 # write the disk label as configured
185 - $error = &FAI::execute_command("parted -s $disk mklabel "
186 - . $FAI::configs{"PHY_$disk"}{disklabel});
187 + my $label = $FAI::configs{"PHY_$disk"}{disklabel};
188 + $label = "gpt" if ($label eq "gpt-bios");
189 + $error = &FAI::execute_command("parted -s $disk mklabel $label");
190 ($error eq "") or die "Failed to write disk label\n";
191 # retry partition-table print
192 $error =

  ViewVC Help
Powered by ViewVC 1.1.5