Repository navigation
Implement /dev/disk/by-parttype - #28894
AdrianVovk wants to merge 4 commits into
Conversation
|
Maybe go for /dev/gpt-auto for the whole disk for consistency? I don't think we use /dev/gpt-auto for anything already right? |
|
That might imply a connection to the gpt-auto generator that isn't there... /dev/boot-disk is a bit more descriptive. I can change it anyway if you prefer |
Also create a symlink in /dev/boot-disk
b1e2fc1 to
22b32f2
Compare
| } LIBSYSTEMD_253; | ||
|
|
||
| LIBSYSTEMD_255 { | ||
| sd_gpt_uuid_from_name; |
There was a problem hiding this comment.
So that apps looking for the "root-x86-64" partition can just get the UUID instead of maintaining their own lookup table of name->uuid for the DPS
| ENV{.PART_NAME}=="", ENV{ID_FS_LABEL_ENC}=="?*", ENV{.PART_NAME}="$env{ID_FS_LABEL_ENC}" | ||
| ENV{.PART_NAME}=="", ENV{ID_PART_ENTRY_UUID}=="?*", ENV{.PART_NAME}="$env{ID_PART_ENTRY_UUID}" | ||
| ENV{.PART_NAME}=="", GOTO="persistent_storage_by_parttype_end" | ||
| ENV{ID_PART_ENTRY_TYPE}=="?*", SYMLINK+="disk/by-parttype/$env{ID_PART_ENTRY_TYPE}/$env{.PART_NAME}" |
There was a problem hiding this comment.
this symlink should probably carry "boot" in the name somewhere.
And I think it would make sense to patch block_id, to look up the id we maintain for partition type uuids and simply append it as yet another property onto the device. Then use that property here to create a named symlink.
That said, for compat I think we should always create the uuid-based symlink, and the id-based symlink if we have one. That way, people can use the uuid always without having to rely us to register the part type they need one day.
also, this should initialize link_priority from the partno somehow, so that we get the guarantee that the first partitoin always gets the symlink if multiple partitions have the same type on the same disk.
There was a problem hiding this comment.
this symlink should probably carry "boot" in the name somewhere.
👍
And I think it would make sense to patch block_id, to look up the id we maintain for partition type uuids and simply append it as yet another property onto the device. Then use that property here to create a named symlink.
So in bkid we export ID_BOOT_DEV_SYMLINKS="disk/by-parttype/{uuid}/{label} disk/by-parttype/{name1}/{label} ...", then in the rule add SYMLINK+="$env{ID_BOOT_DEV_SYMLINKS}"?
That said, for compat I think we should always create the uuid-based symlink, and the id-based symlink if we have one. That way, people can use the uuid always without having to rely us to register the part type they need one day.
The problem w/ the id-based symlinks we came across is that there are many IDs for one partition type... and it's not a fixed number either.
also, this should initialize link_priority from the partno somehow, so that we get the guarantee that the first partitoin always gets the symlink if multiple partitions have the same type on the same disk.
Same type and label, you mean?
There was a problem hiding this comment.
hmm, so i was thinking the symlink wouldn't also contain the label, but just the parttype. i.e. that you have a stable link to the first partition of a specific type, and the label doesn't matter. e.g. a stable reference to ESP, XBOOTLDR, swap and other partitions could be maintained that way, that just always works, and where multiple partitions of the same type on the same disk doesn't make sense.
but your usecase seems different if you want to include the label too. can you elaborate?
There was a problem hiding this comment.
Basically the idea is that for some partitions, we do want multiple of them (i.e. we'll have two /usr trees). Including the label lets you access all the partitions on the disk
I agree that it doesn't make sense for many partition types (i.e. swap, /var, etc). However, the idea is that this mechanism is also generic, not just for partition types defined by systemd/uapi-group. So if Vanilla OS wants to define 08e5611e-7996-4a0b-b793-0cb63b2a3e14 = grub installation, and they have two grub installations, they'd be able to find both installations of grub in /dev/disk/by-parttype/08e5611e-7996-4a0b-b793-0cb63b2a3e14/* (this is not a contrived example. I'm pretty sure that Vanilla does have grub installed 2x)
However, perhaps picking the first partition we find on the disk might be a good tradeoff. Anyone who needs anything more than that should dissect the GPT table and find the partition themselves?
Something else to consider: sometimes we don't want the first partition we find. Sometimes we want the latest partition by version number
There was a problem hiding this comment.
hmm, we could simply add both kinds of symlinks i guess. i.e. with the label, and without it. i think that might be quite nice actually. key is that we format them into a strong that has a clear delimiter where the label begins so that there could never be confusion. and we should suppress the additional with-label symlinks for cases where the label is empty anyway.
This lets shell scripts do: `ENVVAR=$(systemd-id128 -m show root)`
|
|
||
| <listitem><para>When paired with the <command>show</command> command, prints the ID in a machine-readable | ||
| format. This is useful for shell scripts, where you might want to put the UUID of a partition type into | ||
| an environment variable.</para></listitem> |
There was a problem hiding this comment.
this already exists:
systemd-id128 -P machine-id
| if (found_esp_or_xbootldr && !sd_id128_is_null(root_id)) | ||
| udev_builtin_add_property(dev, test, "ID_PART_GPT_AUTO_ROOT_UUID", SD_ID128_TO_UUID_STRING(root_id)); | ||
| if (is_boot_disk) { | ||
| udev_builtin_add_property(dev, test, "ID_BOOT_DISK", "1"); |
There was a problem hiding this comment.
this is lovely btw. We should have done this from the beginning.
|
|
||
| # add symlink to GPT root disk | ||
| # Add a stable symlink for the disk that we're booting from | ||
| SUBSYSTEM=="block", ENV{ID_BOOT_DISK}=="1", SYMLINK+="boot-disk" |
There was a problem hiding this comment.
i think we should add ENV{DEVTYPE}=="disk" here, as safety check. We currently don't set the property on per-partition devices, but we might eventually import the property from the whole block device onto the partition devices (or we might not, but somebody else might in a udev rule), and that shouldn't fuck up our symlink here.
I think this symlink should probably be called /dev/disk/boot, i.e. be placed where the other /dev/disk/by-*/ symlinks are, but as a singleton right inside /dev/disk/
There was a problem hiding this comment.
actually, this one symlink is so generic, it should really be in rules.d/60-persistent-storage.rules.in I think.
|
I think the ID_BOOT_DISK thing and symlink we can do in a separate PR and already merge. i.e. the first commit. Seems almost good to go. |
|
regarding the translation of gpt type uuids to names, I'd propose the following: in builtin_blkid() whenever we encounter a partition table entry which has ID_PART_ENTRY_TYPE= set to a parsable uuid, we'll synthesize optionally two additional fields ID_PART_ENTRY_TYPE_NAME= and ID_PART_ENTRY_TYPE_NAME_NOARCH=. These names are generated from the existing gpt_partition_type_uuid_to_string() and from a new function gpt_partition_type_uuid_to_noarch_string(). The latter would be very similar to gpt_partition_type_uuid_to_string() but only return a string if the Net result, we could then in udev rules generated three symlinks for each partition: one based on ID_PART_ENTRY_TYPE= directly, one pased on ID_PART_ENTRY_TYPE_NAME= and one on ID_PART_ENTRY_TYPE_NAME_NOARCH=. e.g. /dev/disk/by-parttype/4f68bce3-e8cd-4db1-96e7-fbcaf984b709, /dev/disk/by-parttype/root, /dev/disk/by-parttype/root-x86_64 would all point to the same partition device, and programs can rely on them |
|
also, please add a commit that drops this entry from TODO: as well as this one: which are kinda the same |
Also implements a /dev/boot-disk device node, so we can implement
root=ddi