diff --git a/fs_mgr/libfstab/fstab.cpp b/fs_mgr/libfstab/fstab.cpp index 6e4cae18f..43547eaf4 100644 --- a/fs_mgr/libfstab/fstab.cpp +++ b/fs_mgr/libfstab/fstab.cpp @@ -950,6 +950,22 @@ std::set GetBootDevices() { return ExtraBootDevices(fstab); } +std::string GetBootPartUuid() { + std::string boot_part_uuid; + + if (GetBootconfig("androidboot.boot_part_uuid", &boot_part_uuid)) { + return boot_part_uuid; + } + + ImportKernelCmdline([&](std::string key, std::string value) { + if (key == "androidboot.boot_part_uuid") { + boot_part_uuid = value; + } + }); + + return boot_part_uuid; +} + std::string GetVerityDeviceName(const FstabEntry& entry) { std::string base_device; if (entry.mount_point == "/") { diff --git a/fs_mgr/libfstab/include/fstab/fstab.h b/fs_mgr/libfstab/include/fstab/fstab.h index 070dd9178..0ff3188d4 100644 --- a/fs_mgr/libfstab/include/fstab/fstab.h +++ b/fs_mgr/libfstab/include/fstab/fstab.h @@ -126,6 +126,16 @@ void TransformFstabForDsu(Fstab* fstab, const std::string& dsu_slot, std::set GetBootDevices(); +// Get the Partition UUID the kernel loaded from if the bootloader passed it. +// +// If the kernel's Partition UUID is provided then we can use this to help +// identify which block device contains the filesystems we care about. +// +// NOTE: Nothing secures a UUID other than the convention that two disks +// aren't supposed to both have the same UUID. We still need other mechanisms +// to ensure we've got the right disk. +std::string GetBootPartUuid(); + // Return the name of the dm-verity device for the given fstab entry. This does // not check whether the device is valid or exists; it merely returns the // expected name. diff --git a/init/devices.cpp b/init/devices.cpp index f2bb9d276..0af843f10 100644 --- a/init/devices.cpp +++ b/init/devices.cpp @@ -376,7 +376,13 @@ std::vector DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uev std::string partition; std::string uuid; - if (FindPlatformDevice(uevent.path, &device)) { + if (FindDmDevice(uevent, &partition, &uuid)) { + std::vector symlinks = {"/dev/block/mapper/" + partition}; + if (!uuid.empty()) { + symlinks.emplace_back("/dev/block/mapper/by-uuid/" + uuid); + } + return symlinks; + } else if (FindPlatformDevice(uevent.path, &device)) { // Skip /devices/platform or /devices/ if present static constexpr std::string_view devices_platform_prefix = "/devices/platform/"; static constexpr std::string_view devices_prefix = "/devices/"; @@ -392,12 +398,6 @@ std::vector DeviceHandler::GetBlockDeviceSymlinks(const Uevent& uev type = "pci"; } else if (FindVbdDevicePrefix(uevent.path, &device)) { type = "vbd"; - } else if (FindDmDevice(uevent, &partition, &uuid)) { - std::vector symlinks = {"/dev/block/mapper/" + partition}; - if (!uuid.empty()) { - symlinks.emplace_back("/dev/block/mapper/by-uuid/" + uuid); - } - return symlinks; } else { return {}; } diff --git a/init/uevent.h b/init/uevent.h index dc35fd968..c8ca52aaf 100644 --- a/init/uevent.h +++ b/init/uevent.h @@ -28,6 +28,7 @@ struct Uevent { std::string subsystem; std::string firmware; std::string partition_name; + std::string partition_uuid; std::string device_name; std::string modalias; int partition_num; diff --git a/init/uevent_listener.cpp b/init/uevent_listener.cpp index 5da67777d..97f3de640 100644 --- a/init/uevent_listener.cpp +++ b/init/uevent_listener.cpp @@ -66,6 +66,9 @@ static void ParseEvent(const char* msg, Uevent* uevent) { } else if (!strncmp(msg, "PARTNAME=", 9)) { msg += 9; uevent->partition_name = msg; + } else if (!strncmp(msg, "PARTUUID=", 9)) { + msg += 9; + uevent->partition_uuid = msg; } else if (!strncmp(msg, "DEVNAME=", 8)) { msg += 8; uevent->device_name = msg; @@ -82,7 +85,7 @@ static void ParseEvent(const char* msg, Uevent* uevent) { if (LOG_UEVENTS) { LOG(INFO) << "event { '" << uevent->action << "', '" << uevent->path << "', '" << uevent->subsystem << "', '" << uevent->firmware << "', " << uevent->major - << ", " << uevent->minor << " }"; + << ", " << uevent->minor << ", " << uevent->partition_uuid << " }"; } }