@@ -32,7 +32,6 @@ use crate::task::Task;
32
32
pub ( crate ) const BOOTPN : u32 = 3 ;
33
33
// This ensures we end up under 512 to be small-sized.
34
34
pub ( crate ) const BOOTPN_SIZE_MB : u32 = 510 ;
35
- pub ( crate ) const ROOTPN : u32 = 4 ;
36
35
pub ( crate ) const EFIPN : u32 = 2 ;
37
36
pub ( crate ) const EFIPN_SIZE_MB : u32 = 512 ;
38
37
@@ -94,6 +93,16 @@ pub(crate) struct InstallBlockDeviceOpts {
94
93
pub ( crate ) root_size : Option < String > ,
95
94
}
96
95
96
+ impl BlockSetup {
97
+ /// Returns true if the block setup requires a separate /boot aka XBOOTLDR partition.
98
+ pub ( crate ) fn requires_bootpart ( & self ) -> bool {
99
+ match self {
100
+ BlockSetup :: Direct => false ,
101
+ BlockSetup :: Tpm2Luks => true ,
102
+ }
103
+ }
104
+ }
105
+
97
106
fn sgdisk_partition (
98
107
sgdisk : & mut Command ,
99
108
n : u32 ,
@@ -274,19 +283,28 @@ pub(crate) fn install_create_rootfs(
274
283
None
275
284
} ;
276
285
277
- sgdisk_partition (
278
- & mut sgdisk. cmd ,
279
- BOOTPN ,
280
- format ! ( "0:+{BOOTPN_SIZE_MB}M" ) ,
281
- "boot" ,
282
- None ,
283
- ) ;
286
+ // Initialize the /boot filesystem. Note that in the future, we may match
287
+ // what systemd/uapi-group encourages and make /boot be FAT32 as well, as
288
+ // it would aid systemd-boot.
289
+ let use_xbootldr = block_setup. requires_bootpart ( ) ;
290
+ let mut partno = EFIPN ;
291
+ if use_xbootldr {
292
+ partno += 1 ;
293
+ sgdisk_partition (
294
+ & mut sgdisk. cmd ,
295
+ partno,
296
+ format ! ( "0:+{BOOTPN_SIZE_MB}M" ) ,
297
+ "boot" ,
298
+ None ,
299
+ ) ;
300
+ }
301
+ let rootpn = if use_xbootldr { BOOTPN + 1 } else { EFIPN + 1 } ;
284
302
let root_size = root_size
285
303
. map ( |v| Cow :: Owned ( format ! ( "0:{v}M" ) ) )
286
304
. unwrap_or_else ( || Cow :: Borrowed ( "0:0" ) ) ;
287
305
sgdisk_partition (
288
306
& mut sgdisk. cmd ,
289
- ROOTPN ,
307
+ rootpn ,
290
308
root_size,
291
309
"root" ,
292
310
Some ( "0FC63DAF-8483-4772-8E79-3D69D8477DE4" ) ,
@@ -321,7 +339,7 @@ pub(crate) fn install_create_rootfs(
321
339
Ok ( devdir. join ( devname) . to_string ( ) )
322
340
} ;
323
341
324
- let base_rootdev = findpart ( ROOTPN ) ?;
342
+ let base_rootdev = findpart ( rootpn ) ?;
325
343
326
344
let ( rootdev, root_blockdev_kargs) = match block_setup {
327
345
BlockSetup :: Direct => ( base_rootdev, None ) ,
@@ -360,23 +378,29 @@ pub(crate) fn install_create_rootfs(
360
378
}
361
379
} ;
362
380
363
- // Initialize the /boot filesystem. Note that in the future, we may match
364
- // what systemd/uapi-group encourages and make /boot be FAT32 as well, as
365
- // it would aid systemd-boot.
366
- let bootdev = & findpart ( BOOTPN ) ?;
367
- let boot_uuid = mkfs ( bootdev, root_filesystem, "boot" , [ ] ) . context ( "Initializing /boot" ) ?;
381
+ // Initialize the /boot filesystem
382
+ let bootdev = if use_xbootldr {
383
+ Some ( findpart ( BOOTPN ) ?)
384
+ } else {
385
+ None
386
+ } ;
387
+ let boot_uuid = if let Some ( bootdev) = bootdev. as_deref ( ) {
388
+ Some ( mkfs ( bootdev, root_filesystem, "boot" , [ ] ) . context ( "Initializing /boot" ) ?)
389
+ } else {
390
+ None
391
+ } ;
368
392
369
393
// Initialize rootfs
370
394
let root_uuid = mkfs ( & rootdev, root_filesystem, "root" , [ ] ) ?;
371
395
let rootarg = format ! ( "root=UUID={root_uuid}" ) ;
372
- let bootsrc = format ! ( "UUID={boot_uuid}" ) ;
373
- let bootarg = format ! ( "boot={bootsrc}" ) ;
374
- let boot = MountSpec {
396
+ let bootsrc = boot_uuid . as_ref ( ) . map ( |uuid| format ! ( "UUID={uuid}" ) ) ;
397
+ let bootarg = bootsrc . as_deref ( ) . map ( |bootsrc| format ! ( "boot={bootsrc}" ) ) ;
398
+ let boot = bootsrc . map ( |bootsrc| MountSpec {
375
399
source : bootsrc,
376
400
target : "/boot" . into ( ) ,
377
401
fstype : MountSpec :: AUTO . into ( ) ,
378
402
options : Some ( "ro" . into ( ) ) ,
379
- } ;
403
+ } ) ;
380
404
let install_config_kargs = state
381
405
. install_config
382
406
. as_ref ( )
@@ -387,7 +411,8 @@ pub(crate) fn install_create_rootfs(
387
411
let kargs = root_blockdev_kargs
388
412
. into_iter ( )
389
413
. flatten ( )
390
- . chain ( [ rootarg, RW_KARG . to_string ( ) , bootarg] . into_iter ( ) )
414
+ . chain ( [ rootarg, RW_KARG . to_string ( ) ] . into_iter ( ) )
415
+ . chain ( bootarg)
391
416
. chain ( install_config_kargs)
392
417
. collect :: < Vec < _ > > ( ) ;
393
418
@@ -398,7 +423,9 @@ pub(crate) fn install_create_rootfs(
398
423
let bootfs = rootfs. join ( "boot" ) ;
399
424
// Create the underlying mount point directory, which should be labeled
400
425
crate :: lsm:: ensure_dir_labeled ( & target_rootfs, "boot" , None , 0o755 . into ( ) , sepolicy) ?;
401
- mount:: mount ( bootdev, & bootfs) ?;
426
+ if let Some ( bootdev) = bootdev. as_deref ( ) {
427
+ mount:: mount ( bootdev, & bootfs) ?;
428
+ }
402
429
// And we want to label the root mount of /boot
403
430
crate :: lsm:: ensure_dir_labeled ( & target_rootfs, "boot" , None , 0o755 . into ( ) , sepolicy) ?;
404
431
@@ -424,7 +451,7 @@ pub(crate) fn install_create_rootfs(
424
451
rootfs,
425
452
rootfs_fd,
426
453
rootfs_uuid : Some ( root_uuid. to_string ( ) ) ,
427
- boot : Some ( boot ) ,
454
+ boot,
428
455
kargs,
429
456
skip_finalize : false ,
430
457
} )
0 commit comments