Kernel: root command line option can be specified as an UUID
Format is the same as in linux root=UUID=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX This makes it easier to boot when computer has multiple disks installed
This commit is contained in:
parent
fd018b32d0
commit
957df08932
|
@ -25,6 +25,8 @@ namespace Kernel
|
||||||
|
|
||||||
virtual BAN::StringView name() const override { return m_name; }
|
virtual BAN::StringView name() const override { return m_name; }
|
||||||
|
|
||||||
|
BAN::StringView uuid() const { return m_guid_string; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Partition(BAN::RefPtr<BlockDevice>, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t, BAN::StringView);
|
Partition(BAN::RefPtr<BlockDevice>, const BAN::GUID&, const BAN::GUID&, uint64_t, uint64_t, uint64_t, const char*, uint32_t, BAN::StringView);
|
||||||
|
|
||||||
|
@ -32,6 +34,7 @@ namespace Kernel
|
||||||
BAN::RefPtr<BlockDevice> m_device;
|
BAN::RefPtr<BlockDevice> m_device;
|
||||||
const BAN::GUID m_type;
|
const BAN::GUID m_type;
|
||||||
const BAN::GUID m_guid;
|
const BAN::GUID m_guid;
|
||||||
|
const BAN::String m_guid_string;
|
||||||
const uint64_t m_first_block;
|
const uint64_t m_first_block;
|
||||||
const uint64_t m_last_block;
|
const uint64_t m_last_block;
|
||||||
const uint64_t m_attributes;
|
const uint64_t m_attributes;
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
#include <kernel/FS/TmpFS/FileSystem.h>
|
#include <kernel/FS/TmpFS/FileSystem.h>
|
||||||
#include <kernel/FS/VirtualFileSystem.h>
|
#include <kernel/FS/VirtualFileSystem.h>
|
||||||
#include <kernel/Lock/LockGuard.h>
|
#include <kernel/Lock/LockGuard.h>
|
||||||
|
#include <kernel/Storage/Partition.h>
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
namespace Kernel
|
namespace Kernel
|
||||||
|
@ -17,13 +19,57 @@ namespace Kernel
|
||||||
ASSERT(!s_instance);
|
ASSERT(!s_instance);
|
||||||
s_instance = MUST(BAN::RefPtr<VirtualFileSystem>::create());
|
s_instance = MUST(BAN::RefPtr<VirtualFileSystem>::create());
|
||||||
|
|
||||||
ASSERT(root_path.size() >= 5 && root_path.substring(0, 5) == "/dev/"_sv);;
|
BAN::RefPtr<BlockDevice> root_device;
|
||||||
root_path = root_path.substring(5);
|
if (root_path.size() >= 5 && root_path.substring(0, 5) == "UUID="_sv)
|
||||||
|
{
|
||||||
|
auto uuid = root_path.substring(5);
|
||||||
|
if (uuid.size() != 36)
|
||||||
|
panic("Invalid UUID specified for root '{}'", uuid);
|
||||||
|
|
||||||
auto root_inode = MUST(DevFileSystem::get().root_inode()->find_inode(root_path));
|
BAN::RefPtr<Partition> root_partition;
|
||||||
if (!root_inode->mode().ifblk())
|
DevFileSystem::get().for_each_inode(
|
||||||
Kernel::panic("Specified root '/dev/{}' does not name a block device", root_path);
|
[&root_partition, uuid](BAN::RefPtr<Inode> inode) -> BAN::Iteration
|
||||||
s_instance->m_root_fs = MUST(FileSystem::from_block_device(static_cast<BlockDevice*>(root_inode.ptr())));
|
{
|
||||||
|
if (!inode->is_device())
|
||||||
|
return BAN::Iteration::Continue;
|
||||||
|
if (!static_cast<Device*>(inode.ptr())->is_partition())
|
||||||
|
return BAN::Iteration::Continue;
|
||||||
|
auto* partition = static_cast<Partition*>(inode.ptr());
|
||||||
|
dprintln("compare '{}' vs '{}'", partition->uuid(), uuid);
|
||||||
|
if (partition->uuid() != uuid)
|
||||||
|
return BAN::Iteration::Continue;
|
||||||
|
dprintln("FOUND");
|
||||||
|
root_partition = partition;
|
||||||
|
return BAN::Iteration::Break;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
if (!root_partition)
|
||||||
|
panic("Could not find partition with UUID '{}'", uuid);
|
||||||
|
root_device = root_partition;
|
||||||
|
}
|
||||||
|
else if (root_path.size() >= 5 && root_path.substring(0, 5) == "/dev/"_sv)
|
||||||
|
{
|
||||||
|
auto device_name = root_path.substring(5);
|
||||||
|
|
||||||
|
auto device_result = DevFileSystem::get().root_inode()->find_inode(device_name);
|
||||||
|
if (device_result.is_error())
|
||||||
|
panic("Could not open root device '{}': {}", root_path, device_result.error());
|
||||||
|
|
||||||
|
auto device_inode = device_result.release_value();
|
||||||
|
if (!device_inode->mode().ifblk())
|
||||||
|
panic("Root inode '{}' is not an block device", root_path);
|
||||||
|
|
||||||
|
root_device = static_cast<BlockDevice*>(device_inode.ptr());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
panic("Unknown root path format '{}' specified", root_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto filesystem_result = FileSystem::from_block_device(root_device);
|
||||||
|
if (filesystem_result.is_error())
|
||||||
|
panic("Could not create filesystem from '{}': {}", root_path, filesystem_result.error());
|
||||||
|
s_instance->m_root_fs = filesystem_result.release_value();
|
||||||
|
|
||||||
Credentials root_creds { 0, 0, 0, 0 };
|
Credentials root_creds { 0, 0, 0, 0 };
|
||||||
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"_sv));
|
MUST(s_instance->mount(root_creds, &DevFileSystem::get(), "/dev"_sv));
|
||||||
|
|
|
@ -18,6 +18,7 @@ namespace Kernel
|
||||||
, m_device(device)
|
, m_device(device)
|
||||||
, m_type(type)
|
, m_type(type)
|
||||||
, m_guid(guid)
|
, m_guid(guid)
|
||||||
|
, m_guid_string(MUST(guid.to_string()))
|
||||||
, m_first_block(first_block)
|
, m_first_block(first_block)
|
||||||
, m_last_block(last_block)
|
, m_last_block(last_block)
|
||||||
, m_attributes(attr)
|
, m_attributes(attr)
|
||||||
|
|
Loading…
Reference in New Issue