mirror of
https://github.com/kairos-io/immucore.git
synced 2025-08-16 21:27:28 +00:00
Mount cdrom efiboot contents under /run/rootfsbase (#224)
Signed-off-by: Itxaka <itxaka@kairos.io>
This commit is contained in:
parent
a2874ca3ee
commit
c9c9edb261
@ -11,11 +11,11 @@ func GetCloudInitPaths() []string {
|
|||||||
return []string{"/system/oem", "/oem/", "/usr/local/cloud-config/"}
|
return []string{"/system/oem", "/oem/", "/usr/local/cloud-config/"}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenericKernelDrivers retusn a list of generic kernel drivers to insmod during uki mode
|
// GenericKernelDrivers returns a list of generic kernel drivers to insmod during uki mode
|
||||||
// as they could be useful for a lot of situations.
|
// as they could be useful for a lot of situations.
|
||||||
func GenericKernelDrivers() []string {
|
func GenericKernelDrivers() []string {
|
||||||
return []string{"virtio", "ata_piix", "cdrom", "ext4", "iso9660", "usb_storage", "ahci",
|
return []string{"virtio", "ata_piix", "cdrom", "ext4", "iso9660", "usb_storage", "ahci", "fat", "vfat",
|
||||||
"virtio_blk", "virtio_scsi", "virtio_net", "nvme", "overlay", "libata", "sr_mod", "simpledrm"}
|
"virtio_blk", "virtio_scsi", "virtio_net", "nvme", "overlay", "libata", "sr_mod", "simpledrm", "loop"}
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrAlreadyMounted = errors.New("already mounted")
|
var ErrAlreadyMounted = errors.New("already mounted")
|
||||||
@ -47,10 +47,12 @@ const (
|
|||||||
OpUkiKcrypt = "uki-unlock"
|
OpUkiKcrypt = "uki-unlock"
|
||||||
OpUkiMountLivecd = "mount-livecd"
|
OpUkiMountLivecd = "mount-livecd"
|
||||||
UkiLivecdMountPoint = "/run/initramfs/live"
|
UkiLivecdMountPoint = "/run/initramfs/live"
|
||||||
|
UkiIsoBaseTree = "/run/rootfsbase"
|
||||||
|
UkiIsoBootImage = "efiboot.img"
|
||||||
UkiLivecdPath = "/dev/disk/by-label/UKI_ISO_INSTALL"
|
UkiLivecdPath = "/dev/disk/by-label/UKI_ISO_INSTALL"
|
||||||
UkiDefaultcdrom = "/dev/sr0"
|
UkiDefaultcdrom = "/dev/sr0"
|
||||||
UkiDefaultcdromFsType = "iso9660"
|
UkiDefaultcdromFsType = "iso9660"
|
||||||
|
UkiDefaultEfiimgFsType = "vfat"
|
||||||
PersistentStateTarget = "/usr/local/.state"
|
PersistentStateTarget = "/usr/local/.state"
|
||||||
LogDir = "/run/immucore"
|
LogDir = "/run/immucore"
|
||||||
LinuxFs = "ext4"
|
|
||||||
)
|
)
|
||||||
|
@ -720,6 +720,8 @@ func (s *State) UKIUnlock(g *herd.Graph, opts ...herd.OpOption) error {
|
|||||||
// to mimic the same behavior as the livecd on non-uki boot.
|
// to mimic the same behavior as the livecd on non-uki boot.
|
||||||
func (s *State) MountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
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 {
|
return g.Add(cnst.OpUkiMountLivecd, append(opts, herd.WithCallback(func(ctx context.Context) error {
|
||||||
|
internalUtils.CloseLogFiles()
|
||||||
|
|
||||||
// If we are booting from Install Media
|
// If we are booting from Install Media
|
||||||
if internalUtils.EfiBootFromInstall() {
|
if internalUtils.EfiBootFromInstall() {
|
||||||
internalUtils.Log.Debug().Msg("Not mounting livecd as we think we are booting from removable media")
|
internalUtils.Log.Debug().Msg("Not mounting livecd as we think we are booting from removable media")
|
||||||
@ -729,28 +731,56 @@ func (s *State) MountLiveCd(g *herd.Graph, opts ...herd.OpOption) error {
|
|||||||
err := os.MkdirAll(s.path(cnst.UkiLivecdMountPoint), 0755)
|
err := os.MkdirAll(s.path(cnst.UkiLivecdMountPoint), 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiLivecdMountPoint))
|
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiLivecdMountPoint))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(s.path(cnst.UkiIsoBaseTree), 0755)
|
||||||
|
if err != nil {
|
||||||
|
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Creating %s", cnst.UkiIsoBaseTree))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Select the correct device to mount
|
||||||
// Try to find the CDROM device by label /dev/disk/by-label/UKI_ISO_INSTALL
|
// Try to find the CDROM device by label /dev/disk/by-label/UKI_ISO_INSTALL
|
||||||
_, err = os.Stat(cnst.UkiLivecdPath)
|
_, err = os.Stat(cnst.UkiLivecdPath)
|
||||||
|
var cdrom string
|
||||||
// if found, mount it
|
// if found, mount it
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = syscall.Mount(cnst.UkiLivecdPath, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
cdrom = cnst.UkiLivecdPath
|
||||||
if err != nil {
|
|
||||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cnst.UkiLivecdPath))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No %s device found", cnst.UkiLivecdPath))
|
|
||||||
// Try to find if /dev/sr0 exists and mount it
|
// Try to find if /dev/sr0 exists and mount it
|
||||||
_, err = os.Stat(cnst.UkiDefaultcdrom)
|
_, err = os.Stat(cnst.UkiDefaultcdrom)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = syscall.Mount(cnst.UkiDefaultcdrom, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
cdrom = cnst.UkiDefaultcdrom
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Mount it
|
||||||
|
if cdrom != "" {
|
||||||
|
err = syscall.Mount(cdrom, s.path(cnst.UkiLivecdMountPoint), cnst.UkiDefaultcdromFsType, syscall.MS_RDONLY, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cnst.UkiDefaultcdrom))
|
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s", cdrom))
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
internalUtils.Log.Debug().Msg(fmt.Sprintf("Mounted %s", cdrom))
|
||||||
internalUtils.Log.Debug().Msg(fmt.Sprintf("No %s found", cnst.UkiDefaultcdrom))
|
syscall.Sync()
|
||||||
|
|
||||||
|
// This needs the loop module to be inserted in the kernel!
|
||||||
|
cmd := fmt.Sprintf("losetup --show -f %s", s.path(filepath.Join(cnst.UkiLivecdMountPoint, cnst.UkiIsoBootImage)))
|
||||||
|
out, err := internalUtils.CommandWithPath(cmd)
|
||||||
|
loop := strings.TrimSpace(out)
|
||||||
|
|
||||||
|
if err != nil || loop == "" {
|
||||||
|
internalUtils.Log.Err(err).Str("out", out).Msg(cmd)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
syscall.Sync()
|
||||||
|
err = syscall.Mount(loop, s.path(cnst.UkiIsoBaseTree), cnst.UkiDefaultEfiimgFsType, syscall.MS_RDONLY, "")
|
||||||
|
if err != nil {
|
||||||
|
internalUtils.Log.Err(err).Msg(fmt.Sprintf("Mounting %s into %s", loop, s.path(cnst.UkiIsoBaseTree)))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
syscall.Sync()
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -24,11 +24,11 @@ func (s *State) RegisterUKI(g *herd.Graph) error {
|
|||||||
// Mount ESP partition under efi if it exists
|
// Mount ESP partition under efi if it exists
|
||||||
s.LogIfError(s.MountESPPartition(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "mount ESP partition")
|
s.LogIfError(s.MountESPPartition(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "mount ESP partition")
|
||||||
|
|
||||||
// Mount cdrom under /run/initramfs/livecd if it exists
|
// Mount cdrom under /run/initramfs/livecd and /run/rootfsbase for the efiboot.img contents
|
||||||
s.LogIfError(s.MountLiveCd(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev)), "Mount LiveCD")
|
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???
|
// 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")
|
s.LogIfError(s.RootfsStageDagStep(g, herd.WithDeps(cnst.OpSentinel, cnst.OpUkiUdev), herd.WithWeakDeps(cnst.OpUkiMountLivecd)), "uki rootfs")
|
||||||
|
|
||||||
// Remount root RO
|
// Remount root RO
|
||||||
s.LogIfError(s.UKIRemountRootRODagStep(g), "remount root")
|
s.LogIfError(s.UKIRemountRootRODagStep(g), "remount root")
|
||||||
|
Loading…
Reference in New Issue
Block a user