mirror of
https://github.com/kairos-io/immucore.git
synced 2025-04-27 11:12:30 +00:00
Add missing cmdline stanzas (#69)
Adds support for: - rd.cos.oemtimeout= - rd.cos.overlay=tmpfs:SIZE - rd.cos.overlay=LABEL=DEVICE_LABEL - rd.cos.overlay=UUID=DEVICE_UUID Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
parent
68fc3afa24
commit
73c4c3e0af
@ -5,6 +5,7 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/deniswernert/go-fstab"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
@ -182,3 +183,28 @@ func MountProc() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// GetOemTimeout parses the cmdline to get the oem timeout to use. Defaults to 5 (converted into seconds afterwards)
|
||||
func GetOemTimeout() int {
|
||||
time := ReadCMDLineArg("rd.cos.oemtimeout=")
|
||||
if len(time) == 0 {
|
||||
return 5
|
||||
}
|
||||
converted, err := strconv.Atoi(time[1])
|
||||
if err != nil {
|
||||
return 5
|
||||
}
|
||||
return converted
|
||||
}
|
||||
|
||||
// GetOverlayBase parses the cdmline and gets the overlay config
|
||||
// Format is rd.cos.overlay=tmpfs:20% or rd.cos.overlay=LABEL=$LABEL or rd.cos.overlay=UUID=$UUID
|
||||
func GetOverlayBase() string {
|
||||
overlayConfig := ReadCMDLineArg("rd.cos.overlay=")
|
||||
if len(overlayConfig) == 0 {
|
||||
return "tmpfs:20%"
|
||||
}
|
||||
|
||||
return overlayConfig[1]
|
||||
|
||||
}
|
||||
|
2
main.go
2
main.go
@ -39,6 +39,8 @@ func main() {
|
||||
TargetDevice: targetDevice,
|
||||
TargetImage: targetImage,
|
||||
RootMountMode: utils.RootRW(),
|
||||
OemTimout: utils.GetOemTimeout(),
|
||||
OverlayBase: utils.GetOverlayBase(),
|
||||
}
|
||||
|
||||
if utils.DisableImmucore() {
|
||||
|
@ -184,7 +184,7 @@ func (s *State) MountOemDagStep(g *herd.Graph, deps ...string) error {
|
||||
//"noauto",
|
||||
//"nouser",
|
||||
"async",
|
||||
}, 10*time.Second),
|
||||
}, time.Duration(s.OemTimout)*time.Second),
|
||||
),
|
||||
)
|
||||
}
|
||||
@ -196,7 +196,7 @@ func (s *State) MountBaseOverlayDagStep(g *herd.Graph) error {
|
||||
func(ctx context.Context) error {
|
||||
op, err := baseOverlay(Overlay{
|
||||
Base: "/run/overlay",
|
||||
BackingBase: "tmpfs:20%",
|
||||
BackingBase: s.OverlayBase,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -12,14 +12,28 @@ import (
|
||||
|
||||
// https://github.com/kairos-io/packages/blob/94aa3bef3d1330cb6c6905ae164f5004b6a58b8c/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-mount-layout.sh#L129
|
||||
func baseOverlay(overlay Overlay) (mountOperation, error) {
|
||||
var dat []string
|
||||
if err := os.MkdirAll(overlay.Base, 0700); err != nil {
|
||||
return mountOperation{}, err
|
||||
}
|
||||
|
||||
dat := strings.Split(overlay.BackingBase, ":")
|
||||
// BackingBase can be a device (LABEL=COS_PERSISTENT) or a tmpfs+size (tmpfs:20%)
|
||||
// We need to properly parse to understand what it is
|
||||
// We probably should deprecate changing the overlay but leave the size, I don't see much use of this
|
||||
|
||||
// Load both separated
|
||||
datTmpfs := strings.Split(overlay.BackingBase, ":")
|
||||
datDevice := strings.Split(overlay.BackingBase, "=")
|
||||
|
||||
// Add whichever has 2 len as that indicates that it's the correct one
|
||||
if len(datDevice) == 2 {
|
||||
dat = datDevice
|
||||
}
|
||||
if len(datTmpfs) == 2 {
|
||||
dat = datTmpfs
|
||||
}
|
||||
if len(dat) != 2 {
|
||||
return mountOperation{}, fmt.Errorf("invalid backing base. must be a tmpfs with a size or a block device. e.g. tmpfs:30%%, block:/dev/sda1. Input: %s", overlay.BackingBase)
|
||||
return mountOperation{}, fmt.Errorf("invalid backing base. must be a tmpfs with a size or a LABEL/UUID device. e.g. tmpfs:30%%, LABEL:COS_PERSISTENT. Input: %s", overlay.BackingBase)
|
||||
}
|
||||
|
||||
t := dat[0]
|
||||
@ -33,8 +47,9 @@ func baseOverlay(overlay Overlay) (mountOperation, error) {
|
||||
FstabEntry: *tmpFstab,
|
||||
Target: overlay.Base,
|
||||
}, nil
|
||||
case "block":
|
||||
blockMount := mount.Mount{Type: "auto", Source: dat[1]}
|
||||
case "LABEL", "UUID":
|
||||
fsType := internalUtils.DiskFSType(internalUtils.ParseMount(overlay.BackingBase))
|
||||
blockMount := mount.Mount{Type: fsType, Source: internalUtils.ParseMount(overlay.BackingBase)}
|
||||
tmpFstab := internalUtils.MountToFstab(blockMount)
|
||||
// TODO: Check if this is properly written to fstab, currently have no examples
|
||||
tmpFstab.File = internalUtils.CleanSysrootForFstab(overlay.Base)
|
||||
|
@ -28,6 +28,9 @@ type State struct {
|
||||
BindMounts []string // e.g. /etc/kubernetes
|
||||
CustomMounts map[string]string // e.g. diskid : mountpoint
|
||||
|
||||
OverlayBase string // Overlay config, defaults to tmpfs:20%
|
||||
OemTimout int // Time to wait for the oem to time out if not found, defaults to 5s
|
||||
|
||||
StateDir string // e.g. "/usr/local/.state"
|
||||
fstabs []*fstab.Mount
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user