2023-03-01 10:42:46 +00:00
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
|
|
|
cnst "github.com/kairos-io/immucore/internal/constants"
|
|
|
|
"github.com/spectrocloud-labs/herd"
|
|
|
|
)
|
|
|
|
|
2023-03-02 15:46:25 +00:00
|
|
|
// RegisterUKI registers the dag for booting from UKI.
|
2023-03-01 10:42:46 +00:00
|
|
|
func (s *State) RegisterUKI(g *herd.Graph) error {
|
2023-03-14 09:33:38 +00:00
|
|
|
// Mount basic mounts
|
|
|
|
s.LogIfError(s.UKIMountBaseSystem(g), "mounting base mounts")
|
|
|
|
|
2023-03-01 10:42:46 +00:00
|
|
|
// Write sentinel
|
2023-03-14 09:33:38 +00:00
|
|
|
s.LogIfError(s.WriteSentinelDagStep(g, cnst.OpUkiBaseMounts), "sentinel")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
2023-03-14 09:33:38 +00:00
|
|
|
// Load needed kernel modules
|
2023-09-22 12:56:26 +00:00
|
|
|
// TODO: This seems to be wrong as it leans on the udev to infer the modules, but at this point we dont have udev
|
|
|
|
// So we dont get all the proper modules needed!
|
2023-03-01 10:42:46 +00:00
|
|
|
s.LogIfError(s.LoadKernelModules(g), "kernel modules")
|
|
|
|
|
|
|
|
// Udev for devices discovery
|
|
|
|
s.LogIfError(s.UKIUdevDaemon(g), "udev")
|
|
|
|
|
2023-09-25 12:14:56 +00:00
|
|
|
// Mount ESP partition under efi if it exists
|
|
|
|
s.LogIfError(s.MountESPPartition(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "mount ESP partition")
|
|
|
|
|
2024-02-08 13:22:44 +00:00
|
|
|
// Mount cdrom under /run/initramfs/livecd if it exists
|
|
|
|
s.LogIfError(s.MountLiveCd(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "Mount LiveCD")
|
|
|
|
|
2023-11-30 21:19:47 +00:00
|
|
|
// Run rootfs stage (doesnt this need to be run after mounting OEM???
|
2023-04-12 14:19:21 +00:00
|
|
|
s.LogIfError(s.RootfsStageDagStep(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "uki rootfs")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
|
|
|
// Remount root RO
|
2023-03-14 09:33:38 +00:00
|
|
|
s.LogIfError(s.UKIRemountRootRODagStep(g), "remount root")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
2023-11-30 21:19:47 +00:00
|
|
|
// Unlock partitions if needed with TPM
|
|
|
|
s.LogIfError(s.UKIUnlock(g, herd.WithDeps(cnst.OpSentinel, cnst.OpRemountRootRO)), "uki unlock")
|
|
|
|
|
|
|
|
s.LogIfError(s.MountOemDagStep(g, herd.WithDeps(cnst.OpRemountRootRO, cnst.OpUkiKcrypt), herd.WeakDeps), "oem mount")
|
2023-09-22 12:56:26 +00:00
|
|
|
|
2023-03-01 10:42:46 +00:00
|
|
|
// Populate state bind mounts, overlay mounts, custom-mounts from /run/cos/cos-layout.env
|
|
|
|
// Requires stage rootfs to have run, which usually creates the cos-layout.env file
|
2023-09-22 12:56:26 +00:00
|
|
|
s.LogIfError(s.LoadEnvLayoutDagStep(g), "loading cos-layout.env")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
2023-03-14 09:33:38 +00:00
|
|
|
// Mount base overlay under /run/overlay
|
|
|
|
s.LogIfError(s.MountBaseOverlayDagStep(g), "base overlay")
|
|
|
|
|
2023-03-01 10:42:46 +00:00
|
|
|
// Mount custom overlays loaded from the /run/cos/cos-layout.env file
|
2023-09-22 12:56:26 +00:00
|
|
|
s.LogIfError(s.MountCustomOverlayDagStep(g, herd.WeakDeps), "custom overlays mount")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
|
|
|
// Mount custom mounts loaded from the /run/cos/cos-layout.env file
|
2023-09-22 12:56:26 +00:00
|
|
|
s.LogIfError(s.MountCustomMountsDagStep(g, herd.WeakDeps), "custom mounts mount")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
|
|
|
// Mount custom binds loaded from the /run/cos/cos-layout.env file
|
|
|
|
// Depends on mount binds as that usually mounts COS_PERSISTENT
|
2023-09-22 12:56:26 +00:00
|
|
|
s.LogIfError(s.MountCustomBindsDagStep(g, herd.WeakDeps), "custom binds mount")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
|
|
|
// run initramfs stage
|
2023-09-22 12:56:26 +00:00
|
|
|
s.LogIfError(s.InitramfsStageDagStep(g, herd.WeakDeps, herd.WithDeps(cnst.OpMountBind)), "uki initramfs")
|
2023-03-01 10:42:46 +00:00
|
|
|
|
|
|
|
s.LogIfError(g.Add(cnst.OpWriteFstab,
|
|
|
|
herd.WithDeps(cnst.OpLoadConfig, cnst.OpCustomMounts, cnst.OpMountBind, cnst.OpOverlayMount),
|
|
|
|
herd.WeakDeps,
|
|
|
|
herd.WithCallback(s.WriteFstab(s.path("/etc/fstab")))), "fstab")
|
|
|
|
|
|
|
|
// Handover to /sbin/init
|
2023-03-14 09:33:38 +00:00
|
|
|
_ = s.UKIBootInitDagStep(g)
|
2023-03-01 10:42:46 +00:00
|
|
|
return nil
|
|
|
|
}
|