You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggested layout for sysroot for bootc integration #38
Talking with Allison, when flushed the following potential design for the sysroot layout which would allow us to transition existing ostree based bootc systems to pure composefs ones:
we're not sure if /state should be toplevel or if it should live in /composefs/. This is considered an open question.
we normally want the composefs ID alone to select the state as well. Things get complicated with UKIs if we have the ability to have multiple sets of state that should be accessible from a single bootable image.
but, for unusual situations where we can modify the kernel commandline, we might consider a state= argument that explicitly selects a different state directory
we assume that a given composefs image will correspond to a single OS (in the ostree stateroot sense). That lets us consolidate all deployments in a single namespace.
on boot, we open the /state/ directory that corresponds to the composefs= argument (or maybe state= argument). Inside of that directory might exist etc and var either as directories or symlinks. If they are directories, we mount them. If they are symlinks, we mount what they point at. That supports flexibility over different scenarios:
the usual situation is that we want to share one /var per OS. The diagram above illustrates how that would look (/state/os/fedora, with symlinks from each deployment pointing to it eg. composefshash1)
sharing a /var with a sysroot from ostree, very useful for migrating or sharing (eg. composefshash0)
per-deployment /var (possibly created using btrfs snapshots on the sysroot filesystem directly)
no /var: if /var is mounted from a separate partition using /etc/fstab or GPT or otherwise by systemd
we could even mount the entire /sysroot itself as /var if we wanted
the main point here is that this is decided/managed by deployment code. As the system is booting it just looks in the state directory and does what it's told.
About /etc
In theory /etc is handled in exactly the same way as /var during boot. In practice, we expect there to be really only one way this is done at deployment: the usual three-way merge as currently performed by ostree, and in a very similar way. We can support migrating from an existing ostree system in this way, since this is inherently a copy in any case. @travier thinks that we should rewrite this algorithm ("it's not so hard...") in Rust as part of bootc, and that seems reasonable to me — it also sounds like he was volunteering me for the job.
To support the three-way merge, we plan to move /etc to /usr/etc in the in-memory filesystem tree during creation of the composefs, creating an empty /etc in its place — similar to what bootc does now when importing to ostree. That will happen probably just after the SELinux relabelling process. This is another way that "bootable" composefs will vary wrt. composefs that we create for running containers. See #35.
I'm not sure what the merge process will look like exactly. Obviously we'll read the existing /etc from the filesystem and also write the new merged /etc to the filesystem, but how will we find the new /usr/etc from the new system image? There are two main options:
access them via the in-memory filesystem API
mount the composefs of the to-be-booted OS image and access them that way
Note: depending on how we approach this, it might be possible to avoid having /usr/etc. For example, we could leave it at /etc and mount over top of it at run time (but still see it during deploy time) or we could exclude /etc/ entirely from the created image, replacing it with just the empty directory (since we'd still have access to the files via the in-memory filesystem image).
About kernels/bootloader entries
This might be difficult because apparently ostree doesn't like to share access to /boot. This is the part that we fleshed out the least. Probably we need bootc to mediate here.
I've read this comment. It's a good sort of "state of the art" overview. I think it would indeed be worth looking into the flatcar approach a bit and seeing if we can use that instead of writing our own merge code. I hadn't considered that ostree is maybe the way that it is only because overlayfs wasn't around at the time...
In any case, whatever we spec out, it ought to accommodate this approach.
The way this works is that it gets copied into the initramfs during build time and consulted by ostree-prepare-root before it does any work. We should do exactly the same for composefs initramfs and pivot.
This is an issue I've been struggling with for ages (what determines the kinds of mounts we do? the deployment? the image? the initramfs?) and this sort of gives us a nicely working template that we should follow. I'm going to start working on this stuff — getting the ssh keys out of the image creation process would be a good test for transient /etc for example.
Is there a technical reason that /state is at the top-level? Otherwise, having it live under /composefs seems cleaner. It becomes immediately obvious that it's managed by composefs and not ostree.
I think /state is to be managed by bootc, which is the thing that will ultimately stitch all of this together and be responsible for reconciling both worlds and (hopefully) eventually allow migrating existing deployments from ostree to composefs (as provided by composefs-rs).
we're not sure if /state should be toplevel or if it should live in /composefs/. This is considered an open question.
But some background to the decision: composefs isn't the same thing as ostree. It's more like a way to store a bunch of OS-like filesystem data on a disk. ostree was always concerned about deployments and stuff, right from the start. Of course, the biggest user of this at first will be bootc, but the /state thing is really entirely about bootable systems. We don't expect that we'd use the same setup for flatpak or containers setups.
Indeed, nothing in the composefs crate knows anything about /state and probably never will. The state doesn't conceptually belong to composefs. The /state stuff in this git repository is implemented only in the build scripts (which are to be considered proof of concept hacks, at best) and the code in composefs-setup-root, which is heavily in the "boot" world...
So although this was an "open question" when we first discussed it I'd say I've become more and more comfortable with the idea of it staying a separate directory. Not set in stone, of course, but that's where we are...
Ack, thanks for clarifying. I realize I'm somewhat bikeshedding here, I'm mostly pointing out that "state" is quite ambiguous and generic.
The first point in the first comment is
we're not sure if /state should be toplevel or if it should live in /composefs/. This is considered an open question.
Heh. :) I did see that FWIW, but it's also about 7 months old now and in the early days of this design so seems fair to ask as things firm up. I should've referenced it though.
But some background to the decision: composefs isn't the same thing as ostree. It's more like a way to store a bunch of OS-like filesystem data on a disk. ostree was always concerned about deployments and stuff, right from the start.
This is true, however there is a relatively clear separation in the code between OstreeRepo and OstreeSysroot. The latter owns an instance of the former. And flatpak only uses OstreeRepo today, so the split is there.
One argument here to avoid toplevel filesystem pollution is to have the directory structure be /bootc/{composefs,state}.
I don't have a really strong opinion here, but if I had to pick it'd probably be that...unless someone has an argument for why two toplevels is better.
Talking with Pragyan, we landed on an updated layout that includes the origin files for each composefs image
One thing I feel was a mistake with ostree is having those origin files be mutable. I wonder if instead we could try to always say that if you want to change your origin, that involves a new bootloader entry? Which speaking of, bootloader state is omitted from that layout but I think we need it there, and I think having the bootloader entries as "source of truth" has worked out decently well.
From a discussion with Pragyan, target composefs native layout when composefshash0 is booted and we're staging an update under composehash1, with boot entries management:
/sysroot
├── composefs
│ ├── images
│ ├── objects
│ └── streams
└── state
├── deploy
│ ├── composefshash0
│ │ ├── composefshash0.origin <-- composefs native variant
│ │ ├── etc
│ │ └── var -> ../../os/fedora/var
│ └── composefshash1
│ ├── composefshash1.origin
│ ├── etc <-- empty when staged, populated on poweroff
│ └── var -> ../../os/fedora/var
└── os
└── fedora
└── var
As we can not change anything in those UKIs or it will break their signature, it might be that we will have to also write small Type 1 BLS entries even for UKIs in order to be able to control the boot order.
They would look like:
<composefshash0>.conf:
title My bootc OS ...
sort-key 1 <-- To sort after 0
efi /EFI/Linux/<composefshash0>.efi
<composefshash1>.conf:
title My bootc OS ...
sort-key 0 <-- To sort first
efi /EFI/Linux/<composefshash1>.efi
Like ostreedev/ostree#3359 ? I think that's probably fine but that said, it'd likely be cleaner to reconcile on boot instead. That's where I was thinking of going with ostree-boot-complete.service, we'd perform GC then.
As we can not change anything in those UKIs or it will break their signature, it might be that we will have to also write small Type 1 BLS entries even for UKIs in order to be able to control the boot order.
Doesn't the boot counting spec apply here? For the use case of "revert to previous OS image" I think we'd implement that by setting the tries counter for any newer image to zero or so. (Not totally sure about this one, but I think so)
Like ostreedev/ostree#3359 ? I think that's probably fine but that said, it'd likely be cleaner to reconcile on boot instead. That's where I was thinking of going with ostree-boot-complete.service, we'd perform GC then.
This looks very similar indeed fro a quick look.
As we can not change anything in those UKIs or it will break their signature, it might be that we will have to also write small Type 1 BLS entries even for UKIs in order to be able to control the boot order.
Doesn't the boot counting spec apply here? For the use case of "revert to previous OS image" I think we'd implement that by setting the tries counter for any newer image to zero or so. (Not totally sure about this one, but I think so)
That should work as well but that would not let us fully control the order however, only which entry would be displayed first. We would have to mark all previous entries as 'bad' to ensure that the entry that we want to boot is indeed seleted first.
/boot (GRUB + UKI case)
└── grub2
├── grub.cfg <-- Static GRUB config that includes uki.cfg
├── uki.cfg <-- Where the UKI chainloader entries are written for GRUB
├── uki.cfg.staged <-- Where the staged UKI chainloader entries are written for GRUB
└── user.cfg
ESP (GRUB + UKI case)
└─── EFI
├── BOOT
│ ├── BOOTX64.EFI
│ └── fbx64.efi
├── Linux <-- Could be in /boot as well
│ ├── <composefshash0>.efi
│ └── <composefshash1>.efi.staged <-- staged deployment (.staged extension optional)
└── fedora
├── BOOTX64.CSV
├── bootuuid.cfg
├── grub.cfg <-- Points to the GRUB config in /boot
├── grubx64.efi
├── mmx64.efi
├── shim.efi
└── shimx64.efi
We need to do this dance (generate GRUB config snippets) as GRUB does not support the efi key in BLS Type 1 boot entries in it's blsconfig module (ostreedev/ostree#2753 (comment)), thus we need to chainload UKIs instead.
Note that this setup currently does not work with Secure Boot enabled due to a bug in GRUB that I still have to file.
Overall, this is the least interesting case for us as we have the limitations of UKIs and not the benefits as we still have a GRUB config in the boot path.
We need a way to figure out the order of the boot entry to be able to tell which one is the rollback one and in general to be able to order them the way we want, independently of the versions stored in the UKI.
This is a "solved" problem in the classic kernel/initrd BLS case as we write BLS configs and we can rely on those to read the order and write the version in those to set the order that we want.
In the GRUB case, we are not writing BLS entries but a small GRUB config snippet, which we don't really want to have to parse.
Thus to be able to control the order in the systemd-boot case, we would have to manually use BLS entries and not rely on the sorting logic from systemd-boot. The UKIs would be stored in a /bootc folder in the ESP and the BLS entries written in the order that we want as /loader/entries/bootc-x.conf.
And finally in the GRUB case, we could either:
parse the GRUB config snippets that we write to get the order back and write it again (as detailed above):
not great as we have to learn to parse enough GRUB config file format to do it
easier as we only care about this file to update on shutdown
or also write the BLS entries and use that as source of truth, only syncing the GRUB config bit on shutdown.
we don't have to care about the GRUB config file, we always directly overwrite it
we have to keep the BLS entry and the GRUB config bit in sync, and verify the logic in case of unexpected shutdowns, etc.
That should work as well but that would not let us fully control the order however, only which entry would be displayed first. We would have to mark all previous entries as 'bad' to ensure that the entry that we want to boot is indeed seleted first.
Yes; what would be the issue with marking them as bad?
That should work as well but that would not let us fully control the order however, only which entry would be displayed first. We would have to mark all previous entries as 'bad' to ensure that the entry that we want to boot is indeed seleted first.
Yes; what would be the issue with marking them as bad?
They would still not be in the order that we want. We would only be able to control which one goes first unfortunately. There would thus be no way of reliably knowing which one is the rollback deployment. It also means that we would mark as bad, entries that are actually good, which would be confusing. That would something like that:
First entry: Only entry marked as good / with a boot counter
All the other boot entries: Marked as bad to make sure they are not sorted earlier, but they would be sorted in order depending on the version that is part of the UKI name/os-release, so not under our control
In the GRUB case, we are not writing BLS entries but a small GRUB config snippet, which we don't really want to have to parse.
The BLS entry + GRUB snippet approach is a bit more complicated, and now when I think about it, I don't like the idea of having two sources of truths. Writing an (extremely) simple parser for the GRUB menuentry file wouldn't be too difficult
I think we need to decide how stateroots are discovered. In the unsealed case we could easily add it to the kernel command line. e.g. composefs.mount.stateroot=foo. The sealed case is more interesting because ideally we support it as local state.
I think we need to decide how stateroots are discovered. In the unsealed case we could easily add it to the kernel command line. e.g. composefs.mount.stateroot=foo. The sealed case is more interesting because ideally we support it as local state.
That's indeed a good point that we need to figure out. We will likely need to create a mapping between boot entries and stateroots that lives in the composefs repo somewhere, so that it would be part of the encrypted rootfs for the UKI case. If there is only one then bootc can default to it without configuration.
Activity
allisonkarlitskaya commentedon Nov 20, 2024
Notes
/stateshould be toplevel or if it should live in/composefs/. This is considered an open question.state=argument that explicitly selects a different state directory/state/directory that corresponds to thecomposefs=argument (or maybestate=argument). Inside of that directory might existetcandvareither as directories or symlinks. If they are directories, we mount them. If they are symlinks, we mount what they point at. That supports flexibility over different scenarios:/varper OS. The diagram above illustrates how that would look (/state/os/fedora, with symlinks from each deployment pointing to it eg.composefshash1)/varwith a sysroot from ostree, very useful for migrating or sharing (eg.composefshash0)/var(possibly created using btrfs snapshots on the sysroot filesystem directly)/var: if/varis mounted from a separate partition using/etc/fstabor GPT or otherwise by systemd/sysrootitself as/varif we wantedAbout /etc
In theory
/etcis handled in exactly the same way as/varduring boot. In practice, we expect there to be really only one way this is done at deployment: the usual three-way merge as currently performed by ostree, and in a very similar way. We can support migrating from an existing ostree system in this way, since this is inherently a copy in any case. @travier thinks that we should rewrite this algorithm ("it's not so hard...") in Rust as part of bootc, and that seems reasonable to me — it also sounds like he was volunteering me for the job.To support the three-way merge, we plan to move
/etcto/usr/etcin the in-memory filesystem tree during creation of the composefs, creating an empty/etcin its place — similar to what bootc does now when importing to ostree. That will happen probably just after the SELinux relabelling process. This is another way that "bootable" composefs will vary wrt. composefs that we create for running containers. See #35.I'm not sure what the merge process will look like exactly. Obviously we'll read the existing
/etcfrom the filesystem and also write the new merged/etcto the filesystem, but how will we find the new/usr/etcfrom the new system image? There are two main options:Note: depending on how we approach this, it might be possible to avoid having
/usr/etc. For example, we could leave it at/etcand mount over top of it at run time (but still see it during deploy time) or we could exclude/etc/entirely from the created image, replacing it with just the empty directory (since we'd still have access to the files via the in-memory filesystem image).About kernels/bootloader entries
This might be difficult because apparently ostree doesn't like to share access to
/boot. This is the part that we fleshed out the least. Probably we needbootcto mediate here.allisonkarlitskaya commentedon Nov 20, 2024
I'm starting to look into
merge_configuration_from()in libostree.cgwalters commentedon Nov 20, 2024
Related to merging /etc see also uapi-group/specifications#76 (comment) - I've been meaning to look at the Flatcar use of overlayfs here.
allisonkarlitskaya commentedon Nov 20, 2024
I've read this comment. It's a good sort of "state of the art" overview. I think it would indeed be worth looking into the flatcar approach a bit and seeing if we can use that instead of writing our own merge code. I hadn't considered that ostree is maybe the way that it is only because overlayfs wasn't around at the time...
In any case, whatever we spec out, it ought to accommodate this approach.
allisonkarlitskaya commentedon Mar 26, 2025
https://bootc-dev.github.io/bootc/filesystem.html documents
/usr/lib/ostree/prepare-root.confwhich I think is a very nice starting point for deciding how we should approach putting together the image from the standpoint of the pivot command.The way this works is that it gets copied into the initramfs during build time and consulted by ostree-prepare-root before it does any work. We should do exactly the same for composefs initramfs and pivot.
This is an issue I've been struggling with for ages (what determines the kinds of mounts we do? the deployment? the image? the initramfs?) and this sort of gives us a nicely working template that we should follow. I'm going to start working on this stuff — getting the ssh keys out of the image creation process would be a good test for transient /etc for example.
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
mount: substantially rework mounting code
11 remaining items
jeckersb commentedon Jun 24, 2025
I think
/stateis to be managed by bootc, which is the thing that will ultimately stitch all of this together and be responsible for reconciling both worlds and (hopefully) eventually allow migrating existing deployments from ostree to composefs (as provided by composefs-rs).allisonkarlitskaya commentedon Jun 24, 2025
The first point in the first comment is
But some background to the decision: composefs isn't the same thing as ostree. It's more like a way to store a bunch of OS-like filesystem data on a disk. ostree was always concerned about deployments and stuff, right from the start. Of course, the biggest user of this at first will be bootc, but the
/statething is really entirely about bootable systems. We don't expect that we'd use the same setup for flatpak or containers setups.Indeed, nothing in the
composefscrate knows anything about/stateand probably never will. The state doesn't conceptually belong to composefs. The/statestuff in this git repository is implemented only in the build scripts (which are to be considered proof of concept hacks, at best) and the code incomposefs-setup-root, which is heavily in the "boot" world...So although this was an "open question" when we first discussed it I'd say I've become more and more comfortable with the idea of it staying a separate directory. Not set in stone, of course, but that's where we are...
jlebon commentedon Jun 24, 2025
Ack, thanks for clarifying. I realize I'm somewhat bikeshedding here, I'm mostly pointing out that "state" is quite ambiguous and generic.
Heh. :) I did see that FWIW, but it's also about 7 months old now and in the early days of this design so seems fair to ask as things firm up. I should've referenced it though.
cgwalters commentedon Jun 24, 2025
This is true, however there is a relatively clear separation in the code between
OstreeRepoandOstreeSysroot. The latter owns an instance of the former. And flatpak only usesOstreeRepotoday, so the split is there.One argument here to avoid toplevel filesystem pollution is to have the directory structure be
/bootc/{composefs,state}.I don't have a really strong opinion here, but if I had to pick it'd probably be that...unless someone has an argument for why two toplevels is better.
cgwalters commentedon Jun 24, 2025
One thing I feel was a mistake with ostree is having those origin files be mutable. I wonder if instead we could try to always say that if you want to change your origin, that involves a new bootloader entry? Which speaking of, bootloader state is omitted from that layout but I think we need it there, and I think having the bootloader entries as "source of truth" has worked out decently well.
travier commentedon Jun 25, 2025
From a discussion with Pragyan, target composefs native layout when
composefshash0is booted and we're staging an update undercomposehash1, with boot entries management:On poweroff, similarly to ostree-finalized-staged:
We're not sure how we could make the origin files non mutable however. Did you have something in mind?
One potential limitation in systemd-boot right now is that Type 2 boot entries (UKIs) are first sorted by elements that are fixed / part of the UKI (i.e. version etc.) and only by their filename as a last resort: https://uapi-group.org/specifications/specs/boot_loader_specification/#sorting
As we can not change anything in those UKIs or it will break their signature, it might be that we will have to also write small Type 1 BLS entries even for UKIs in order to be able to control the boot order.
They would look like:
<composefshash0>.conf:<composefshash1>.conf:cgwalters commentedon Jun 25, 2025
Like ostreedev/ostree#3359 ? I think that's probably fine but that said, it'd likely be cleaner to reconcile on boot instead. That's where I was thinking of going with
ostree-boot-complete.service, we'd perform GC then.Doesn't the boot counting spec apply here? For the use case of "revert to previous OS image" I think we'd implement that by setting the tries counter for any newer image to zero or so. (Not totally sure about this one, but I think so)
travier commentedon Jun 26, 2025
This looks very similar indeed fro a quick look.
That should work as well but that would not let us fully control the order however, only which entry would be displayed first. We would have to mark all previous entries as 'bad' to ensure that the entry that we want to boot is indeed seleted first.
travier commentedon Jun 26, 2025
And we missed a case: UKI with GRUB:
We need to do this dance (generate GRUB config snippets) as GRUB does not support the
efikey in BLS Type 1 boot entries in it's blsconfig module (ostreedev/ostree#2753 (comment)), thus we need to chainload UKIs instead.Note that this setup currently does not work with Secure Boot enabled due to a bug in GRUB that I still have to file.
Overall, this is the least interesting case for us as we have the limitations of UKIs and not the benefits as we still have a GRUB config in the boot path.
travier commentedon Jul 8, 2025
We need a way to figure out the order of the boot entry to be able to tell which one is the rollback one and in general to be able to order them the way we want, independently of the versions stored in the UKI.
versionin those to set the order that we want.Thus to be able to control the order in the systemd-boot case, we would have to manually use BLS entries and not rely on the sorting logic from systemd-boot. The UKIs would be stored in a
/bootcfolder in the ESP and the BLS entries written in the order that we want as/loader/entries/bootc-x.conf.And finally in the GRUB case, we could either:
cgwalters commentedon Jul 8, 2025
Yes; what would be the issue with marking them as bad?
travier commentedon Jul 10, 2025
They would still not be in the order that we want. We would only be able to control which one goes first unfortunately. There would thus be no way of reliably knowing which one is the rollback deployment. It also means that we would mark as bad, entries that are actually good, which would be confusing. That would something like that:
Johan-Liebert1 commentedon Jul 14, 2025
The BLS entry + GRUB snippet approach is a bit more complicated, and now when I think about it, I don't like the idea of having two sources of truths. Writing an (extremely) simple parser for the GRUB menuentry file wouldn't be too difficult
cgwalters commentedon Jul 28, 2025
I think we need to decide how stateroots are discovered. In the unsealed case we could easily add it to the kernel command line. e.g.
composefs.mount.stateroot=foo. The sealed case is more interesting because ideally we support it as local state.travier commentedon Aug 1, 2025
That's indeed a good point that we need to figure out. We will likely need to create a mapping between boot entries and stateroots that lives in the composefs repo somewhere, so that it would be part of the encrypted rootfs for the UKI case. If there is only one then bootc can default to it without configuration.