From 2251733744dae5f18827568e8210163d9dfac050 Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 1 Jan 2022 16:12:44 -0700 Subject: [PATCH] Kernel: Allow specifying partition index with NVMe devices Since NVME devices end with a digit that indicates the node index we cannot simply append a partition index. Instead, there will be a "p" character as separator, e.g. /dev/nvme0n1p3 for the 3rd partition. So, if the early device name ends in a digit we need to add this separater before matching for the partition index. If the partition index is omitted (as is the default) the root file system is on a disk without any partition table (e.g. using QEMU). This enables booting from the correct partition on an NVMe drive by setting the command line variable root to e.g. root=/dev/nvme0n1p1 --- Kernel/Storage/StorageManagement.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/Kernel/Storage/StorageManagement.cpp b/Kernel/Storage/StorageManagement.cpp index c9215ff839..9ea6e914da 100644 --- a/Kernel/Storage/StorageManagement.cpp +++ b/Kernel/Storage/StorageManagement.cpp @@ -142,9 +142,20 @@ UNMAP_AFTER_INIT void StorageManagement::determine_boot_device() m_boot_block_device = storage_device; break; } - auto start_storage_name = storage_name.substring_view(0, min(storage_device.early_storage_name().length(), storage_name.length())); - if (storage_device.early_storage_name().starts_with(start_storage_name)) { + // If the early storage name's last character is a digit (e.g. in the case of NVMe where the last + // number in the device name indicates the node, e.g. /dev/nvme0n1 we need to append a "p" character + // so that we can properly distinguish the partition index from the device itself + char storage_name_last_char = *(storage_device.early_storage_name().end() - 1); + String early_storage_name; + if (storage_name_last_char >= '0' && storage_name_last_char <= '9') + early_storage_name = String::formatted("{}p", storage_device.early_storage_name()); + else + early_storage_name = storage_device.early_storage_name(); + + auto start_storage_name = storage_name.substring_view(0, min(early_storage_name.length(), storage_name.length())); + + if (early_storage_name.starts_with(start_storage_name)) { StringView partition_sign = storage_name.substring_view(start_storage_name.length()); auto possible_partition_number = partition_sign.to_uint(); if (!possible_partition_number.has_value())