diff --git a/pkg/elemental/elemental.go b/pkg/elemental/elemental.go index 27b47ff4..932422e0 100644 --- a/pkg/elemental/elemental.go +++ b/pkg/elemental/elemental.go @@ -308,7 +308,23 @@ func (e Elemental) CreateFileSystemImage(img *v1.Image) error { // DeployImage will deploy the given image into the target. This method // creates the filesystem image file, mounts it and unmounts it as needed. +// Creates the default system dirs by default (/sys,/proc,/dev, etc...) func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interface{}, err error) { + return e.deployImage(img, leaveMounted, true) +} + +// DeployImageNodirs will deploy the given image into the target. This method +// creates the filesystem image file, mounts it and unmounts it as needed. +// Does not create the default system dirs so it can be used to create generic images from any source +func (e *Elemental) DeployImageNodirs(img *v1.Image, leaveMounted bool) (info interface{}, err error) { + return e.deployImage(img, leaveMounted, false) +} + +// deployImage is the real function that does the actual work +// Set leaveMounted to leave the image mounted, otherwise it unmounts before returning +// Set createDirStructure to create the directory structure in the target, which creates the expected dirs +// for a running system. This is so we can reuse this method for creating random images, not only system ones +func (e *Elemental) deployImage(img *v1.Image, leaveMounted, createDirStructure bool) (info interface{}, err error) { target := img.MountPoint if !img.Source.IsFile() { if img.FS != cnst.SquashFs { @@ -338,9 +354,11 @@ func (e *Elemental) DeployImage(img *v1.Image, leaveMounted bool) (info interfac return nil, err } if !img.Source.IsFile() { - err = utils.CreateDirStructure(e.config.Fs, target) - if err != nil { - return nil, err + if createDirStructure { + err = utils.CreateDirStructure(e.config.Fs, target) + if err != nil { + return nil, err + } } if img.FS == cnst.SquashFs { squashOptions := append(cnst.GetDefaultSquashfsOptions(), e.config.SquashFsCompressionConfig...) diff --git a/pkg/utils/grub.go b/pkg/utils/grub.go index cb08ecb5..90b2da62 100644 --- a/pkg/utils/grub.go +++ b/pkg/utils/grub.go @@ -46,6 +46,9 @@ func NewGrub(config *agentConfig.Config) *Grub { } // Install installs grub into the device, copy the config file and add any extra TTY to grub +// TODO: Make it more generic to be able to call it from other places +// i.e.: filepath.Join(cnst.ActiveDir, "etc/kairos-release") seraches for the file in the active dir, we should be looking into the rootdir? +// filepath.Join(cnst.EfiDir, "EFI/boot/grub.cfg") we also write into the efi dir directly, this should be the a var maybe? func (g Grub) Install(target, rootDir, bootDir, grubConf, tty string, efi bool, stateLabel string) (err error) { // nolint:gocyclo var grubargs []string var grubdir, finalContent string