diff --git a/Kernel/Arch/init.cpp b/Kernel/Arch/init.cpp index 477f17a5c6..8454479862 100644 --- a/Kernel/Arch/init.cpp +++ b/Kernel/Arch/init.cpp @@ -420,7 +420,13 @@ void init_stage2(void*) for (auto* init_function = driver_init_table_start; init_function != driver_init_table_end; init_function++) (*init_function)(); - StorageManagement::the().initialize(kernel_command_line().root_device(), kernel_command_line().is_force_pio(), kernel_command_line().is_nvme_polling_enabled()); + StorageManagement::the().initialize(kernel_command_line().is_force_pio(), kernel_command_line().is_nvme_polling_enabled()); + for (int i = 0; i < 5; ++i) { + if (StorageManagement::the().determine_boot_device(kernel_command_line().root_device())) + break; + dbgln_if(STORAGE_DEVICE_DEBUG, "Boot device {} not found, sleeping 2 seconds", kernel_command_line().root_device()); + (void)Thread::current()->sleep(Duration::from_seconds(2)); + } if (VirtualFileSystem::the().mount_root(StorageManagement::the().root_filesystem()).is_error()) { PANIC("VirtualFileSystem::mount_root failed"); } diff --git a/Kernel/Devices/Storage/StorageManagement.cpp b/Kernel/Devices/Storage/StorageManagement.cpp index 4a7d9c8a5d..8203abf539 100644 --- a/Kernel/Devices/Storage/StorageManagement.cpp +++ b/Kernel/Devices/Storage/StorageManagement.cpp @@ -376,38 +376,39 @@ UNMAP_AFTER_INIT void StorageManagement::determine_boot_device_with_logical_unit resolve_partition_from_boot_device_parameter(*chosen_storage_device, logical_unit_number_device_prefix); } -UNMAP_AFTER_INIT void StorageManagement::determine_boot_device() +UNMAP_AFTER_INIT bool StorageManagement::determine_boot_device(StringView boot_argument) { VERIFY(!m_controllers.is_empty()); + m_boot_argument = boot_argument; if (m_boot_argument.starts_with(block_device_prefix)) { determine_block_boot_device(); - return; + return m_boot_block_device; } if (m_boot_argument.starts_with(partition_uuid_prefix)) { determine_boot_device_with_partition_uuid(); - return; + return m_boot_block_device; } if (m_boot_argument.starts_with(logical_unit_number_device_prefix)) { determine_boot_device_with_logical_unit_number(); - return; + return m_boot_block_device; } if (m_boot_argument.starts_with(ata_device_prefix)) { determine_ata_boot_device(); - return; + return m_boot_block_device; } if (m_boot_argument.starts_with(nvme_device_prefix)) { determine_nvme_boot_device(); - return; + return m_boot_block_device; } if (m_boot_argument.starts_with(sd_device_prefix)) { determine_sd_boot_device(); - return; + return m_boot_block_device; } PANIC("StorageManagement: Invalid root boot parameter."); } @@ -476,10 +477,9 @@ NonnullRefPtr StorageManagement::root_filesystem() const return file_system; } -UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool force_pio, bool poll) +UNMAP_AFTER_INIT void StorageManagement::initialize(bool force_pio, bool poll) { VERIFY(s_storage_device_minor_number == 0); - m_boot_argument = root_device; if (PCI::Access::is_disabled()) { #if ARCH(X86_64) // Note: If PCI is disabled, we assume that at least we have an ISA IDE controller @@ -502,12 +502,6 @@ UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool enumerate_storage_devices(); enumerate_disk_partitions(); - - determine_boot_device(); - if (m_boot_block_device.is_null()) { - dump_storage_devices_and_partitions(); - PANIC("StorageManagement: boot device {} not found", m_boot_argument); - } } StorageManagement& StorageManagement::the() diff --git a/Kernel/Devices/Storage/StorageManagement.h b/Kernel/Devices/Storage/StorageManagement.h index 9f2d1fc261..56a3382aa8 100644 --- a/Kernel/Devices/Storage/StorageManagement.h +++ b/Kernel/Devices/Storage/StorageManagement.h @@ -24,9 +24,10 @@ class StorageManagement { public: StorageManagement(); - void initialize(StringView boot_argument, bool force_pio, bool nvme_poll); + void initialize(bool force_pio, bool nvme_poll); static StorageManagement& the(); + bool determine_boot_device(StringView boot_argument); NonnullRefPtr root_filesystem() const; static MajorNumber storage_type_major_number(); @@ -49,7 +50,6 @@ private: ErrorOr enumerate_device_partitions(StorageDevice&); void enumerate_disk_partitions(); - void determine_boot_device(); void determine_boot_device_with_partition_uuid(); void resolve_partition_from_boot_device_parameter(StorageDevice const& chosen_storage_device, StringView boot_device_prefix);