@@ -26,10 +26,14 @@ impl Image {
26
26
. create ( true )
27
27
. truncate ( true )
28
28
. open ( path) ?) ;
29
+ // make sure the image size is a multiple of 512
30
+ // gdisk warns otherwise and OVMF seems to ignore the disk in some cases
31
+ // also, keep a spare megabyte for the partition table and alignment
32
+ let size = size. next_multiple_of ( 512 ) + 1024 * 1024 ;
29
33
file. set_len ( size) ?;
30
34
// protective MBR
31
35
let mbr = ProtectiveMBR :: with_lb_size (
32
- u32:: try_from ( ( size / 512 ) - 1 ) . unwrap_or ( 0xFF_FF_FF_FF )
36
+ u32:: try_from ( ( size / 512 ) - 1 ) ?
33
37
) ;
34
38
mbr. overwrite_lba0 ( & mut file) ?;
35
39
let mut disk = GptConfig :: new ( )
@@ -38,7 +42,10 @@ impl Image {
38
42
. create_from_device ( file, None ) ?;
39
43
disk. update_partitions ( BTreeMap :: new ( ) ) ?;
40
44
debug ! ( "creating partition" ) ;
41
- disk. add_partition ( "towboot" , size - 1024 * 1024 , partition_types:: EFI , 0 , None ) ?;
45
+ // the partition needs to be slightly smaller than the disk image
46
+ disk. add_partition (
47
+ "towboot" , size - 64 * 1024 , partition_types:: EFI , 0 , None ,
48
+ ) ?;
42
49
let partitions = disk. partitions ( ) . clone ( ) ;
43
50
let ( _, partition) = partitions. iter ( ) . next ( ) . unwrap ( ) ;
44
51
let file = disk. write ( ) ?;
0 commit comments