@@ -1816,6 +1816,11 @@ def prepare_tree(args: MkosiArgs, root: Path, do_run_build_script: bool, cached:
1816
1816
else :
1817
1817
# If this is not enabled, let's create an empty directory on /boot
1818
1818
root .joinpath ("boot" ).mkdir (mode = 0o700 )
1819
+ # Make sure kernel-install actually runs when needed by creating the machine-id subdirectory
1820
+ # under /boot. For "bios" on Debian/Ubuntu, it's required for grub to pick up the generated
1821
+ # initrd.
1822
+ if args .distribution in (Distribution .debian , Distribution .ubuntu ) and "bios" in args .boot_protocols :
1823
+ root .joinpath ("boot" , args .machine_id ).mkdir (mode = 0o700 )
1819
1824
1820
1825
if args .get_partition (PartitionIdentifier .esp ):
1821
1826
root .joinpath ("efi/EFI" ).mkdir (mode = 0o700 )
@@ -2117,7 +2122,7 @@ def invoke_dnf(
2117
2122
cmdline += [command , * sort_packages (packages )]
2118
2123
2119
2124
with mount_api_vfs (args , root ):
2120
- run (cmdline )
2125
+ run (cmdline , env = dict ( KERNEL_INSTALL_BYPASS = "1" ) )
2121
2126
2122
2127
distribution , release = detect_distribution ()
2123
2128
if distribution not in (Distribution .debian , Distribution .ubuntu ):
@@ -2378,7 +2383,7 @@ def install_fedora(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No
2378
2383
add_packages (args , packages , "glibc-minimal-langpack" , conditional = "glibc" )
2379
2384
2380
2385
if not do_run_build_script and args .bootable :
2381
- add_packages (args , packages , "kernel-core" , "kernel-modules" , "dracut" , "binutils" )
2386
+ add_packages (args , packages , "kernel-core" , "kernel-modules" , "dracut" )
2382
2387
add_packages (args , packages , "systemd-udev" , conditional = "systemd" )
2383
2388
configure_dracut (args , packages , root )
2384
2389
if do_run_build_script :
@@ -2413,7 +2418,7 @@ def install_mageia(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No
2413
2418
packages = {* args .packages }
2414
2419
add_packages (args , packages , "basesystem-minimal" )
2415
2420
if not do_run_build_script and args .bootable :
2416
- add_packages (args , packages , "kernel-server-latest" , "dracut" , "binutils" )
2421
+ add_packages (args , packages , "kernel-server-latest" , "dracut" )
2417
2422
configure_dracut (args , packages , root )
2418
2423
# Mageia ships /etc/50-mageia.conf that omits systemd from the initramfs and disables hostonly.
2419
2424
# We override that again so our defaults get applied correctly on Mageia as well.
@@ -2462,7 +2467,7 @@ def install_openmandriva(args: MkosiArgs, root: Path, do_run_build_script: bool)
2462
2467
add_packages (args , packages , "basesystem-minimal" , "systemd" )
2463
2468
if not do_run_build_script and args .bootable :
2464
2469
add_packages (args , packages , "systemd-boot" , "systemd-cryptsetup" , conditional = "systemd" )
2465
- add_packages (args , packages , "kernel-release-server" , "dracut" , "binutils" , " timezone" )
2470
+ add_packages (args , packages , "kernel-release-server" , "dracut" , "timezone" )
2466
2471
configure_dracut (args , packages , root )
2467
2472
if args .netdev :
2468
2473
add_packages (args , packages , "systemd-networkd" , conditional = "systemd" )
@@ -2684,7 +2689,7 @@ def install_centos(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No
2684
2689
packages = {* args .packages }
2685
2690
add_packages (args , packages , "centos-release" , "systemd" )
2686
2691
if not do_run_build_script and args .bootable :
2687
- add_packages (args , packages , "kernel" , "dracut" , "binutils" )
2692
+ add_packages (args , packages , "kernel" , "dracut" )
2688
2693
configure_dracut (args , packages , root )
2689
2694
if epel_release <= 7 :
2690
2695
add_packages (
@@ -2736,7 +2741,7 @@ def install_rocky(args: MkosiArgs, root: Path, do_run_build_script: bool) -> Non
2736
2741
packages = {* args .packages }
2737
2742
add_packages (args , packages , "rocky-release" , "systemd" )
2738
2743
if not do_run_build_script and args .bootable :
2739
- add_packages (args , packages , "kernel" , "dracut" , "binutils" )
2744
+ add_packages (args , packages , "kernel" , "dracut" )
2740
2745
configure_dracut (args , packages , root )
2741
2746
add_packages (args , packages , "systemd-udev" , conditional = "systemd" )
2742
2747
@@ -2768,7 +2773,7 @@ def install_alma(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None
2768
2773
packages = {* args .packages }
2769
2774
add_packages (args , packages , "almalinux-release" , "systemd" )
2770
2775
if not do_run_build_script and args .bootable :
2771
- add_packages (args , packages , "kernel" , "dracut" , "binutils" )
2776
+ add_packages (args , packages , "kernel" , "dracut" )
2772
2777
configure_dracut (args , packages , root )
2773
2778
add_packages (args , packages , "systemd-udev" , conditional = "systemd" )
2774
2779
@@ -2800,10 +2805,11 @@ def invoke_apt(
2800
2805
) -> None :
2801
2806
2802
2807
cmdline = ["/usr/bin/apt-get" , "--assume-yes" , command , * extra ]
2803
- env = {
2804
- "DEBIAN_FRONTEND" : "noninteractive" ,
2805
- "DEBCONF_NONINTERACTIVE_SEEN" : "true" ,
2806
- }
2808
+ env = dict (
2809
+ DEBIAN_FRONTEND = "noninteractive" ,
2810
+ DEBCONF_NONINTERACTIVE_SEEN = "true" ,
2811
+ INITRD = "No" ,
2812
+ )
2807
2813
2808
2814
run_workspace_command (args , root , cmdline , network = True , env = env )
2809
2815
@@ -2853,7 +2859,7 @@ def install_debian_or_ubuntu(args: MkosiArgs, root: Path, *, do_run_build_script
2853
2859
extra_packages .update (args .build_packages )
2854
2860
2855
2861
if not do_run_build_script and args .bootable :
2856
- add_packages (args , extra_packages , "dracut" , "binutils" )
2862
+ add_packages (args , extra_packages , "dracut" )
2857
2863
configure_dracut (args , extra_packages , root )
2858
2864
2859
2865
if args .distribution == Distribution .ubuntu :
@@ -2944,10 +2950,6 @@ def install_debian_or_ubuntu(args: MkosiArgs, root: Path, *, do_run_build_script
2944
2950
root .joinpath ("etc/resolv.conf" ).symlink_to ("../run/systemd/resolve/resolv.conf" )
2945
2951
run (["systemctl" , "--root" , root , "enable" , "systemd-resolved" ])
2946
2952
2947
- if args .bootable and not do_run_build_script and "uefi" in args .boot_protocols :
2948
- for kver , kimg in gen_kernel_images (args , root ):
2949
- run_workspace_command (args , root , ["kernel-install" , "add" , kver , Path ("/" ) / kimg ])
2950
-
2951
2953
2952
2954
@complete_step ("Installing Debian…" )
2953
2955
def install_debian (args : MkosiArgs , root : Path , do_run_build_script : bool ) -> None :
@@ -2959,8 +2961,8 @@ def install_ubuntu(args: MkosiArgs, root: Path, do_run_build_script: bool) -> No
2959
2961
install_debian_or_ubuntu (args , root , do_run_build_script = do_run_build_script )
2960
2962
2961
2963
2962
- def run_pacman (root : Path , pacman_conf : Path , packages : Set [str ]) -> None :
2963
- run (["pacman" , "--config" , pacman_conf , "--noconfirm" , "-Sy" , * sort_packages (packages )])
2964
+ def invoke_pacman (root : Path , pacman_conf : Path , packages : Set [str ]) -> None :
2965
+ run (["pacman" , "--config" , pacman_conf , "--noconfirm" , "-Sy" , * sort_packages (packages )], env = dict ( KERNEL_INSTALL_BYPASS = "1" ) )
2964
2966
2965
2967
2966
2968
@complete_step ("Installing Arch Linux…" )
@@ -3103,7 +3105,7 @@ def install_arch(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None
3103
3105
if args .get_partition (PartitionIdentifier .bios ):
3104
3106
add_packages (args , packages , "grub" )
3105
3107
3106
- add_packages (args , packages , "dracut" , "binutils" )
3108
+ add_packages (args , packages , "dracut" )
3107
3109
configure_dracut (args , packages , root )
3108
3110
3109
3111
packages .update (args .packages )
@@ -3127,7 +3129,7 @@ def install_arch(args: MkosiArgs, root: Path, do_run_build_script: bool) -> None
3127
3129
add_packages (args , packages , "openssh" )
3128
3130
3129
3131
with mount_api_vfs (args , root ):
3130
- run_pacman (root , pacman_conf , packages )
3132
+ invoke_pacman (root , pacman_conf , packages )
3131
3133
3132
3134
# Arch still uses pam_securetty which prevents root login into
3133
3135
# systemd-nspawn containers. See https://bugs.archlinux.org/task/45903.
@@ -3173,7 +3175,7 @@ def install_opensuse(args: MkosiArgs, root: Path, do_run_build_script: bool) ->
3173
3175
add_packages (args , packages , "patterns-base-minimal_base" )
3174
3176
3175
3177
if not do_run_build_script and args .bootable :
3176
- add_packages (args , packages , "kernel-default" , "dracut" , "binutils" )
3178
+ add_packages (args , packages , "kernel-default" , "dracut" )
3177
3179
configure_dracut (args , packages , root )
3178
3180
3179
3181
if args .get_partition (PartitionIdentifier .bios ):
@@ -3224,11 +3226,6 @@ def jj(line: str) -> str:
3224
3226
# copy now, patch later (in set_autologin())
3225
3227
shutil .copy2 (root / "usr/etc/pam.d/login" , root / "etc/pam.d/login" )
3226
3228
3227
- # Zypper doesn't run dracut automatically so we have to do it manually.
3228
- if args .bootable and not do_run_build_script and "uefi" in args .boot_protocols :
3229
- for kver , kimg in gen_kernel_images (args , root ):
3230
- run_workspace_command (args , root , ["kernel-install" , "add" , kver , Path ("/" ) / kimg ])
3231
-
3232
3229
3233
3230
@complete_step ("Installing Gentoo…" )
3234
3231
def install_gentoo (
@@ -4261,7 +4258,7 @@ def extract_partition(
4261
4258
def gen_kernel_images (args : MkosiArgs , root : Path ) -> Iterator [Tuple [str , Path ]]:
4262
4259
# Apparently openmandriva hasn't yet completed its usrmerge so we use lib here instead of usr/lib.
4263
4260
for kver in root .joinpath ("lib/modules" ).iterdir ():
4264
- if not ( kver .is_dir () and os . path . isfile ( os . path . join ( kver , "modules.dep" ))): # type: ignore
4261
+ if not kver .is_dir ():
4265
4262
continue
4266
4263
4267
4264
if args .distribution == Distribution .gentoo :
@@ -4333,11 +4330,11 @@ def install_unified_kernel(
4333
4330
partlabel = None
4334
4331
4335
4332
if args .image_version :
4336
- boot_binary = Path ( prefix ) / f"EFI/Linux/{ image_id } _{ args .image_version } .efi"
4333
+ boot_binary = root / prefix / f"EFI/Linux/{ image_id } _{ args .image_version } .efi"
4337
4334
elif root_hash :
4338
- boot_binary = Path ( prefix ) / f"EFI/Linux/{ image_id } -{ kver } -{ root_hash } .efi"
4335
+ boot_binary = root / prefix / f"EFI/Linux/{ image_id } -{ kver } -{ root_hash } .efi"
4339
4336
else :
4340
- boot_binary = Path ( prefix ) / f"EFI/Linux/{ image_id } -{ kver } .efi"
4337
+ boot_binary = root / prefix / f"EFI/Linux/{ image_id } -{ kver } .efi"
4341
4338
4342
4339
if root .joinpath ("etc/kernel/cmdline" ).exists ():
4343
4340
boot_options = root .joinpath ("etc/kernel/cmdline" ).read_text ().strip ()
@@ -4352,17 +4349,24 @@ def install_unified_kernel(
4352
4349
elif partlabel :
4353
4350
boot_options = f"{ boot_options } root=PARTLABEL={ partlabel } "
4354
4351
4352
+ osrelease = root / "usr/lib/os-release"
4353
+ cmdline = workspace (root ) / "cmdline"
4354
+ cmdline .write_text (boot_options )
4355
+ initrd = root / prefix / args .machine_id / kver / "initrd"
4356
+
4355
4357
cmd : Sequence [PathString ] = [
4356
- "dracut " ,
4357
- "--uefi " ,
4358
- "--kver " , kver ,
4359
- "--kernel-image " , Path ( "/" ) / kimg ,
4360
- "--kernel-cmdline " , boot_options ,
4361
- "--force " ,
4358
+ "objcopy " ,
4359
+ "--add-section" , f".osrel= { osrelease } " , "--change-section-vma" , ".osrel=0x20000 " ,
4360
+ "--add-section " , f".cmdline= { cmdline } " , "--change-section-vma" , ".cmdline=0x30000" ,
4361
+ "--add-section " , f".linux= { root / kimg } " , "--change-section-vma" , ".linux=0x2000000" ,
4362
+ "--add-section " , f".initrd= { initrd } " , "--change-section-vma" , ".initrd=0x3000000" ,
4363
+ root / "lib/systemd/boot/efi/linuxx64.efi.stub " ,
4362
4364
boot_binary ,
4363
4365
]
4364
4366
4365
- run_workspace_command (args , root , cmd )
4367
+ run (cmd )
4368
+
4369
+ cmdline .unlink ()
4366
4370
4367
4371
4368
4372
def secure_boot_sign (
@@ -7277,6 +7281,21 @@ def setup_netdev(args: MkosiArgs, root: Path, do_run_build_script: bool, cached:
7277
7281
run (["systemctl" , "--root" , root , "enable" , "systemd-networkd" ])
7278
7282
7279
7283
7284
+ def run_kernel_install (args : MkosiArgs , root : Path , do_run_build_script : bool , for_cache : bool ) -> None :
7285
+ if not args .bootable or do_run_build_script or for_cache :
7286
+ return
7287
+
7288
+ with complete_step ("Generating initramfs images…" ):
7289
+ # Running kernel-install on Debian/Ubuntu doesn't regenerate the initramfs. Instead, we can trigger
7290
+ # regeneration of the initramfs via "dpkg-reconfigure dracut". kernel-install can then be called to put
7291
+ # the generated initrds in the right place.
7292
+ if args .distribution in (Distribution .debian , Distribution .ubuntu ):
7293
+ run_workspace_command (args , root , ["dpkg-reconfigure" , "dracut" ])
7294
+
7295
+ for kver , kimg in gen_kernel_images (args , root ):
7296
+ run_workspace_command (args , root , ["kernel-install" , "add" , kver , Path ("/" ) / kimg ])
7297
+
7298
+
7280
7299
@dataclasses .dataclass
7281
7300
class BuildOutput :
7282
7301
raw : Optional [BinaryIO ]
@@ -7368,11 +7387,12 @@ def build_image(
7368
7387
install_distribution (args , root , do_run_build_script , cached_tree )
7369
7388
install_etc_locale (args , root , cached_tree )
7370
7389
install_etc_hostname (args , root , cached_tree )
7371
- install_boot_loader (args , root , loopdev , do_run_build_script , cached_tree )
7372
7390
run_prepare_script (args , root , do_run_build_script , cached_tree )
7373
7391
install_build_src (args , root , do_run_build_script , for_cache )
7374
7392
install_build_dest (args , root , do_run_build_script , for_cache )
7375
7393
install_extra_trees (args , root , for_cache )
7394
+ run_kernel_install (args , root , do_run_build_script , for_cache )
7395
+ install_boot_loader (args , root , loopdev , do_run_build_script , cached_tree )
7376
7396
set_root_password (args , root , do_run_build_script , cached_tree )
7377
7397
set_serial_terminal (args , root , do_run_build_script , cached_tree )
7378
7398
set_autologin (args , root , do_run_build_script , cached_tree )
0 commit comments