mirror of
https://github.com/kairos-io/immucore.git
synced 2025-04-27 19:16:59 +00:00
Mount livecd in /run/initramfs/live under uki (#223)
This commit is contained in:
parent
f3f2b71e4f
commit
a2874ca3ee
@ -45,6 +45,11 @@ const (
|
||||
OpKcryptUnlock = "unlock-all"
|
||||
OpKcryptUpgrade = "upgrade-kcrypt"
|
||||
OpUkiKcrypt = "uki-unlock"
|
||||
OpUkiMountLivecd = "mount-livecd"
|
||||
UkiLivecdMountPoint = "/run/initramfs/live"
|
||||
UkiLivecdPath = "/dev/disk/by-label/UKI_ISO_INSTALL"
|
||||
UkiDefaultcdrom = "/dev/sr0"
|
||||
UkiDefaultcdromFsType = "iso9660"
|
||||
PersistentStateTarget = "/usr/local/.state"
|
||||
LogDir = "/run/immucore"
|
||||
LinuxFs = "ext4"
|
||||
|
@ -65,7 +65,7 @@ func RunStage(stage string) (bytes.Buffer, error) {
|
||||
if debug || debugFromEnv {
|
||||
level = zerolog.DebugLevel
|
||||
}
|
||||
log := MiddleLog{zerolog.New(zerolog.ConsoleWriter{Out: &buffer, TimeFormat: time.RFC3339}).With().Timestamp().Logger().Level(level)}
|
||||
log := MiddleLog{zerolog.New(zerolog.ConsoleWriter{Out: &buffer, TimeFormat: time.RFC3339, NoColor: true}).With().Timestamp().Logger().Level(level)}
|
||||
// Set debug logger
|
||||
yip := NewYipExecutor(log)
|
||||
c := ImmucoreConsole{}
|
||||
|
@ -25,7 +25,7 @@ func SetLogger() {
|
||||
_ = os.MkdirAll(constants.LogDir, os.ModeDir|os.ModePerm)
|
||||
logFile, err := os.Create(filepath.Join(constants.LogDir, "immucore.log"))
|
||||
if err == nil {
|
||||
loggers = append(loggers, zerolog.ConsoleWriter{Out: logFile, TimeFormat: time.RFC3339})
|
||||
loggers = append(loggers, zerolog.ConsoleWriter{Out: logFile, TimeFormat: time.RFC3339, NoColor: true})
|
||||
}
|
||||
|
||||
loggers = append(loggers, zerolog.NewConsoleWriter(func(w *zerolog.ConsoleWriter) {
|
||||
|
@ -715,3 +715,44 @@ func (s *State) UKIUnlock(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return kcrypt.UnlockAll(true)
|
||||
}))...)
|
||||
}
|
||||
|
||||
// MountLiveCd tries to mount the livecd if we are booting from one into /run/initramfs/live
|
||||
// to mimic the same behavior as the livecd on non-uki boot.
|
||||
func (s *State) MountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
||||
return g.Add(cnst.OpUkiMountLivecd, append(opts, herd.WithCallback(func(ctx context.Context) error {
|
||||
// If we are booting from Install Media
|
||||
if internalUtils.EfiBootFromInstall() {
|
||||
internalUtils.Log.Debug().Msg("Not mounting livecd as we think we are booting from removable media")
|
||||
return nil
|
||||
}
|
||||
|
||||
err := os.MkdirAll(s.path(cnst.UkiLivecdMountPoint), 0755)
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiLivecdMountPoint))
|
||||
return nil
|
||||
}
|
||||
// Try to find the CDROM device by label /dev/disk/by-label/UKI_ISO_INSTALL
|
||||
_, err = os.Stat(cnst.UkiLivecdPath)
|
||||
// if found, mount it
|
||||
if err == nil {
|
||||
err = syscall.Mount(cnst.UkiLivecdPath, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cnst.UkiLivecdPath))
|
||||
}
|
||||
} else {
|
||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No %s device found", cnst.UkiLivecdPath))
|
||||
// Try to find if /dev/sr0 exists and mount it
|
||||
_, err = os.Stat(cnst.UkiDefaultcdrom)
|
||||
if err == nil {
|
||||
err = syscall.Mount(cnst.UkiDefaultcdrom, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
||||
if err != nil {
|
||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cnst.UkiDefaultcdrom))
|
||||
}
|
||||
} else {
|
||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No %s found", cnst.UkiDefaultcdrom))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}))...)
|
||||
}
|
||||
|
@ -24,6 +24,9 @@ func (s *State) RegisterUKI(g *herd.Graph) error {
|
||||
// Mount ESP partition under efi if it exists
|
||||
s.LogIfError(s.MountESPPartition(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "mount ESP partition")
|
||||
|
||||
// Mount cdrom under /run/initramfs/livecd if it exists
|
||||
s.LogIfError(s.MountLiveCd(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "Mount LiveCD")
|
||||
|
||||
// Run rootfs stage (doesnt this need to be run after mounting OEM???
|
||||
s.LogIfError(s.RootfsStageDagStep(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "uki rootfs")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user