-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
probe: Add support to determine if a device uses a GPT table or not
In accordance with issue #53, we must only use the PartUUID for root= entries when we *know* that the partition definitely resides on a GPT disk. Whilst an EFI System Partition must live on a GPT disk to be considered a valid ESP, there is no such constraint on the rootfs itself. Cases emerged during testing of an MBR rootfs partition, with a GPT disk used to house the ESP itself. This change ensures we only ever write a root=PARTUUID if we're fully certain of the topology, otherwise all bootloaders will automatically fall back to root=UUID entries. Signed-off-by: Ikey Doherty <[email protected]>
- Loading branch information
Showing
10 changed files
with
438 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ check_os_release | |
check_uefi | ||
check_grub2 | ||
check_select_bootloader | ||
check_probe | ||
|
||
*.log | ||
*.trs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include <unistd.h> | ||
|
||
#include "blkid_stub.h" | ||
#include "files.h" | ||
#include "log.h" | ||
#include "probe.h" | ||
#include "system_stub.h" | ||
|
@@ -123,6 +124,68 @@ static char *cbm_get_luks_uuid(const char *part) | |
return ret; | ||
} | ||
|
||
/** | ||
* Determine whether the probe lives on a GPT disk or not, | ||
* which is the only instance in which we'll use PartUUID | ||
*/ | ||
static bool cbm_probe_is_gpt(const char *path) | ||
{ | ||
autofree(char) *parent_disk = NULL; | ||
blkid_probe probe = NULL; | ||
blkid_partlist parts = NULL; | ||
blkid_parttable table = NULL; | ||
bool ret = false; | ||
const char *table_type = NULL; | ||
|
||
/* Could be a weird image type or --path into chroot */ | ||
parent_disk = get_parent_disk((char *)path); | ||
if (!parent_disk) { | ||
return false; | ||
} | ||
|
||
probe = cbm_blkid_new_probe_from_filename(parent_disk); | ||
if (!probe) { | ||
LOG_ERROR("Unable to blkid probe %s", parent_disk); | ||
return NULL; | ||
} | ||
|
||
cbm_blkid_probe_enable_superblocks(probe, 1); | ||
cbm_blkid_probe_set_superblocks_flags(probe, BLKID_SUBLKS_TYPE); | ||
cbm_blkid_probe_enable_partitions(probe, 1); | ||
cbm_blkid_probe_set_partitions_flags(probe, BLKID_PARTS_ENTRY_DETAILS); | ||
|
||
if (cbm_blkid_do_safeprobe(probe) != 0) { | ||
LOG_ERROR("Error probing filesystem of %s: %s", parent_disk, strerror(errno)); | ||
goto clean; | ||
} | ||
|
||
parts = cbm_blkid_probe_get_partitions(probe); | ||
if (cbm_blkid_partlist_numof_partitions(parts) <= 0) { | ||
/* No partitions */ | ||
goto clean; | ||
} | ||
|
||
/* Grab the partition table */ | ||
table = cbm_blkid_partlist_get_table(parts); | ||
if (!table) { | ||
LOG_ERROR("Unable to discover partitiojn table for %s: %s", | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jamesmshaker
via email
|
||
parent_disk, | ||
strerror(errno)); | ||
goto clean; | ||
} | ||
|
||
/* Determine the partition table type. We only care if its GPT. */ | ||
table_type = cbm_blkid_parttable_get_type(table); | ||
if (table_type && streq(table_type, "gpt")) { | ||
ret = true; | ||
} | ||
|
||
clean: | ||
cbm_blkid_free_probe(probe); | ||
errno = 0; | ||
return ret; | ||
} | ||
|
||
CbmDeviceProbe *cbm_probe_path(const char *path) | ||
{ | ||
CbmDeviceProbe probe = { 0 }; | ||
|
@@ -177,6 +240,14 @@ CbmDeviceProbe *cbm_probe_path(const char *path) | |
} | ||
} | ||
|
||
/* If the device isn't GPT, clear out the the PartUUID */ | ||
probe.gpt = cbm_probe_is_gpt(path); | ||
if (!probe.gpt && probe.part_uuid) { | ||
free(probe.part_uuid); | ||
probe.part_uuid = NULL; | ||
} | ||
|
||
/* Now check we have at least one UUID value */ | ||
if (!probe.part_uuid && !probe.uuid) { | ||
LOG_ERROR("Unable to find UUID for %s: %s", devnode, strerror(errno)); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
partitiojn