From 14e0faaceefd42fe907e639b49c9a7ed8a06e1b8 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Mon, 6 Feb 2023 21:45:01 +0100 Subject: [PATCH 1/8] Fix dracut service install Signed-off-by: Itxaka --- Earthfile | 2 +- dracut/28immucore/generator.sh | 14 -------------- dracut/28immucore/module-setup.sh | 13 ++----------- 3 files changed, 3 insertions(+), 26 deletions(-) diff --git a/Earthfile b/Earthfile index f99182d..ba51906 100644 --- a/Earthfile +++ b/Earthfile @@ -78,7 +78,7 @@ build-dracut: RUN rm /etc/dracut.conf.d/02-cos-immutable-rootfs.conf END RUN kernel=$(ls /lib/modules | head -n1) && \ - dracut -f "/boot/initrd-${kernel}" "${kernel}" && \ + dracut -v -f "/boot/initrd-${kernel}" "${kernel}" && \ ln -sf "initrd-${kernel}" /boot/initrd ARG INITRD=$(readlink -f /boot/initrd) SAVE ARTIFACT $INITRD Initrd AS LOCAL build/initrd-$VERSION diff --git a/dracut/28immucore/generator.sh b/dracut/28immucore/generator.sh index e1b086f..0911250 100644 --- a/dracut/28immucore/generator.sh +++ b/dracut/28immucore/generator.sh @@ -7,8 +7,6 @@ GENERATOR_DIR="$2" [ -z "$GENERATOR_DIR" ] && exit 1 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" -oem_label=$(getarg rd.cos.oemlabel=) - # See https://github.com/kairos-io/packages/blob/d12b12b043a71d8471454f7b4fc84c3181d2bf60/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh#L29 { echo "[Unit]" @@ -16,18 +14,6 @@ oem_label=$(getarg rd.cos.oemlabel=) echo "Before=initrd-fs.target" echo "Conflicts=initrd-switch-root.target" echo "Requires=initrd-root-fs.target" - if getargbool 0 rd.neednet; then - echo "Wants=network-online.target" - echo "After=network-online.target" - echo "Description=immucore online mount" - else - echo "Description=immucore mount" - fi - # Itxaka: oem is mounted by immucore? - # OEM is special as immucore plugins might need that in order to unlock other partitions and plugins can reside in /oem as well and immucore needs to find them - #if [ -n "${oem_label}" ]; then - # echo "After=oem.mount" - #fi echo "After=initrd-root-fs.target cos-setup-rootfs.service" echo "[Service]" echo "Type=oneshot" diff --git a/dracut/28immucore/module-setup.sh b/dracut/28immucore/module-setup.sh index d25ecaa..1b5b298 100755 --- a/dracut/28immucore/module-setup.sh +++ b/dracut/28immucore/module-setup.sh @@ -23,18 +23,9 @@ install() { declare moddir=${moddir} declare systemdutildir=${systemdutildir} declare systemdsystemunitdir=${systemdsystemunitdir} - declare initdir="${initdir}" # Add missing elemental binary, drop once we get yip lib inside immucore as its only needed to run the stages - inst_multiple \ - immucore elemental - - inst_script "${moddir}/generator.sh" \ - "${systemdutildir}/system-generators/immucore-generator" - - mkdir -p "${initdir}/${systemdsystemunitdir}/initrd-fs.target.requires" - ln_r "../immucore.service" \ - "${systemdsystemunitdir}/initrd-fs.target.requires/immucore.service" - + inst_multiple immucore elemental + inst_script "${moddir}/generator.sh" "${systemdutildir}/system-generators/immucore-generator" dracut_need_initqueue } \ No newline at end of file From 717851b0b268799f76b5e05f62b5531551c94d09 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Mon, 6 Feb 2023 22:06:31 +0100 Subject: [PATCH 2/8] +x generator.sh Signed-off-by: Itxaka --- Earthfile | 8 ++++--- dracut/28immucore/generator.sh | 34 ++++++++++++------------------ dracut/28immucore/immucore.service | 14 ++++++++++++ dracut/28immucore/module-setup.sh | 4 ++++ dracut/dracut.conf | 3 ++- pkg/mount/mount.go | 18 ++++++++++------ 6 files changed, 50 insertions(+), 31 deletions(-) mode change 100644 => 100755 dracut/28immucore/generator.sh create mode 100644 dracut/28immucore/immucore.service diff --git a/Earthfile b/Earthfile index ba51906..c3445a3 100644 --- a/Earthfile +++ b/Earthfile @@ -55,14 +55,16 @@ lint: build-immucore: FROM +golang-image - COPY +version/VERSION ./ - ARG VERSION=$(cat VERSION) WORKDIR /work COPY go.mod go.sum /work COPY main.go /work COPY --dir internal /work COPY --dir pkg /work - RUN CGO_ENABLED=0 go build -o immucore -ldflags "-X internal/version.Version=$VERSION" + COPY +version/VERSION ./ + ARG VERSION=$(cat VERSION) + ARG LDFLAGS="-s -w -X github.com/kairos-io/immucore/internal/version.Version=$VERSION" + RUN echo ${LDFLAGS} + RUN CGO_ENABLED=0 go build -o immucore -ldflags "${LDFLAGS}" SAVE ARTIFACT /work/immucore AS LOCAL build/immucore-$VERSION build-dracut: diff --git a/dracut/28immucore/generator.sh b/dracut/28immucore/generator.sh old mode 100644 new mode 100755 index 0911250..5c3f77e --- a/dracut/28immucore/generator.sh +++ b/dracut/28immucore/generator.sh @@ -1,32 +1,26 @@ #!/bin/bash +set +x + type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh GENERATOR_DIR="$2" - [ -z "$GENERATOR_DIR" ] && exit 1 [ -d "$GENERATOR_DIR" ] || mkdir "$GENERATOR_DIR" -# See https://github.com/kairos-io/packages/blob/d12b12b043a71d8471454f7b4fc84c3181d2bf60/packages/system/dracut/immutable-rootfs/30cos-immutable-rootfs/cos-generator.sh#L29 + +## GENERATE SYSROOT +cos_img=$(getarg cos-img/filename=) +[ -z "${cos_img}" ] && exit 0 + { echo "[Unit]" + echo "Before=initrd-root-fs.target" echo "DefaultDependencies=no" - echo "Before=initrd-fs.target" - echo "Conflicts=initrd-switch-root.target" - echo "Requires=initrd-root-fs.target" - echo "After=initrd-root-fs.target cos-setup-rootfs.service" - echo "[Service]" - echo "Type=oneshot" - echo "RemainAfterExit=yes" - echo "ExecStart=/usr/bin/immucore start" + echo "[Mount]" + echo "Where=/sysroot" + echo "What=/run/initramfs/cos-state/${cos_img#/}" + echo "Options=ro,suid,dev,exec,auto,nouser,async" +} > "$GENERATOR_DIR"/sysroot.mount - echo "[Install]" - echo "RequiredBy=initrd-fs.target" -} > "$GENERATOR_DIR"/immucore.service - - -if [ ! -e "$GENERATOR_DIR/initrd-fs.target.requires/immucore.service" ]; then - mkdir -p "$GENERATOR_DIR"/initrd-fs.target.requires - ln -s "$GENERATOR_DIR"/immucore.service \ - "$GENERATOR_DIR"/initrd-fs.target.requires/immucore.service -fi \ No newline at end of file +## END GENERATE SYSROOT \ No newline at end of file diff --git a/dracut/28immucore/immucore.service b/dracut/28immucore/immucore.service new file mode 100644 index 0000000..00b70d0 --- /dev/null +++ b/dracut/28immucore/immucore.service @@ -0,0 +1,14 @@ +[Unit] +Description=immucore +DefaultDependencies=no +After=systemd-udev-settle.service +Requires=systemd-udev-settle.service +Before=dracut-initqueue.service +Conflicts=initrd-switch-root.target + +[Service] +Type=oneshot +RemainAfterExit=yes +StandardOutput=journal+console +ExecStartPre=-/usr/bin/systemctl stop oem.mount +ExecStart=/usr/bin/immucore start \ No newline at end of file diff --git a/dracut/28immucore/module-setup.sh b/dracut/28immucore/module-setup.sh index 1b5b298..4fd8160 100755 --- a/dracut/28immucore/module-setup.sh +++ b/dracut/28immucore/module-setup.sh @@ -23,9 +23,13 @@ install() { declare moddir=${moddir} declare systemdutildir=${systemdutildir} declare systemdsystemunitdir=${systemdsystemunitdir} + declare initdir=${initdir} # Add missing elemental binary, drop once we get yip lib inside immucore as its only needed to run the stages inst_multiple immucore elemental inst_script "${moddir}/generator.sh" "${systemdutildir}/system-generators/immucore-generator" + inst_simple "${moddir}/immucore.service" "${systemdsystemunitdir}/immucore.service" + mkdir -p "${initdir}/${systemdsystemunitdir}/initrd-fs.target.requires" + ln_r "../immucore.service" "${systemdsystemunitdir}/initrd-fs.target.requires/immucore.service" dracut_need_initqueue } \ No newline at end of file diff --git a/dracut/dracut.conf b/dracut/dracut.conf index 6f1a85b..35aa080 100644 --- a/dracut/dracut.conf +++ b/dracut/dracut.conf @@ -2,5 +2,6 @@ # so at the end, just before we let init do the switch_root # Note that initramfs run with RootDirectory=/sysroot install_items+=" /etc/systemd/system/cos-setup-initramfs.service /etc/systemd/system/initrd.target.requires/cos-setup-initramfs.service " -install_items+=" /etc/systemd/system/cos-setup-rootfs.service /etc/systemd/system/initrd-fs.target.requires/cos-setup-rootfs.service " +# RUN BY IMMUCORE BUT FAILING +#install_items+=" /etc/systemd/system/cos-setup-rootfs.service /etc/systemd/system/initrd-fs.target.requires/cos-setup-rootfs.service " add_dracutmodules+=" immucore " \ No newline at end of file diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 8587463..03b819e 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -87,9 +87,11 @@ func (s *State) WriteFstab(fstabFile string) func(context.Context) error { // ln -sf -t / /sysroot/system func (s *State) RunStageOp(stage string) func(context.Context) error { return func(ctx context.Context) error { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() cmd := fmt.Sprintf("elemental run-stage %s", stage) - s.Logger.Debug().Str("cmd", cmd) - _, err := utils.SH(cmd) + log.Logger.Debug().Str("cmd", cmd).Msg("") + output, err := utils.SH(cmd) + log.Logger.Debug().Str("output", output).Msg("") return err } } @@ -183,8 +185,10 @@ func (s *State) Register(g *herd.Graph) error { runtime, err := state.NewRuntime() if err != nil { + s.Logger.Debug().Err(err).Msg("") return err } + s.Logger.Debug().Str("state", litter.Sdump(runtime)).Msg("Register") // TODO: add hooks, fstab (might have missed some), systemd compat // TODO: We should also set tmpfs here (not -related) @@ -250,7 +254,7 @@ func (s *State) Register(g *herd.Graph) error { // "auto", //"nouser", "async", - }, 60*time.Second), + }, 10*time.Second), ), ) if err != nil { @@ -389,7 +393,7 @@ func (s *State) Register(g *herd.Graph) error { []string{ "ro", // or rw }, - 60*time.Second, + 10*time.Second, )(ctx)) } @@ -435,7 +439,7 @@ func (s *State) Register(g *herd.Graph) error { mountRootCondition, herd.WithCallback( s.MountOP( - runtime.OEM.Label, + runtime.OEM.Name, s.path("/oem"), runtime.OEM.Type, []string{ @@ -443,8 +447,8 @@ func (s *State) Register(g *herd.Graph) error { "suid", "dev", "exec", - "noauto", - "nouser", + //"noauto", + //"nouser", "async", }, 10*time.Second), ), From 63679b6df1a2dbd5cc1fe0a07959991f4032becb Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 20:16:02 +0100 Subject: [PATCH 3/8] Add missing modules and fix rootfs stage Signed-off-by: Itxaka --- dracut/28immucore/module-setup.sh | 2 ++ pkg/mount/mount.go | 11 +++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/dracut/28immucore/module-setup.sh b/dracut/28immucore/module-setup.sh index 4fd8160..f27b5ef 100755 --- a/dracut/28immucore/module-setup.sh +++ b/dracut/28immucore/module-setup.sh @@ -27,6 +27,8 @@ install() { # Add missing elemental binary, drop once we get yip lib inside immucore as its only needed to run the stages inst_multiple immucore elemental + # add utils used by elemental or stages + inst_multiple partprobe sync udevadm parted mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.vfat mkfs.fat mkfs.xfs blkid e2fsck resize2fs mount xfs_growfs umount sgdisk inst_script "${moddir}/generator.sh" "${systemdutildir}/system-generators/immucore-generator" inst_simple "${moddir}/immucore.service" "${systemdsystemunitdir}/immucore.service" mkdir -p "${initdir}/${systemdsystemunitdir}/initrd-fs.target.requires" diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 03b819e..b2907d2 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -84,10 +84,17 @@ func (s *State) WriteFstab(fstabFile string) func(context.Context) error { } } -// ln -sf -t / /sysroot/system func (s *State) RunStageOp(stage string) func(context.Context) error { return func(ctx context.Context) error { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() + if stage == "rootfs" { + err := os.Symlink("/sysroot/system/", "/system/") + if err != nil { + s.Logger.Err(err).Msg("creating symlink") + return err + } + } + cmd := fmt.Sprintf("elemental run-stage %s", stage) log.Logger.Debug().Str("cmd", cmd).Msg("") output, err := utils.SH(cmd) @@ -273,7 +280,7 @@ func (s *State) Register(g *herd.Graph) error { s.Logger.Debug().Str("what", opRootfsHook).Msg("Add operation") err = g.Add(opRootfsHook, mountRootCondition, herd.WithDeps(opMountOEM), herd.WithCallback(s.RunStageOp("rootfs"))) if err != nil { - s.Logger.Err(err) + s.Logger.Err(err).Msg("") } // /run/cos-layout.env From b62a1f2e993097799d84a037895a59256b6735e0 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 20:27:31 +0100 Subject: [PATCH 4/8] fix deps of rootfs stage, not working modules, symlink Signed-off-by: Itxaka --- dracut/28immucore/module-setup.sh | 3 ++- dracut/dracut.conf | 5 +++-- pkg/mount/mount.go | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/dracut/28immucore/module-setup.sh b/dracut/28immucore/module-setup.sh index f27b5ef..0fd3d73 100755 --- a/dracut/28immucore/module-setup.sh +++ b/dracut/28immucore/module-setup.sh @@ -28,7 +28,8 @@ install() { # Add missing elemental binary, drop once we get yip lib inside immucore as its only needed to run the stages inst_multiple immucore elemental # add utils used by elemental or stages - inst_multiple partprobe sync udevadm parted mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.vfat mkfs.fat mkfs.xfs blkid e2fsck resize2fs mount xfs_growfs umount sgdisk + inst_multiple partprobe sync udevadm parted mkfs.ext2 mkfs.ext3 mkfs.ext4 mkfs.vfat mkfs.fat blkid e2fsck resize2fs mount umount sgdisk + # missing mkfs.xfs xfs_growfs in image? inst_script "${moddir}/generator.sh" "${systemdutildir}/system-generators/immucore-generator" inst_simple "${moddir}/immucore.service" "${systemdsystemunitdir}/immucore.service" mkdir -p "${initdir}/${systemdsystemunitdir}/initrd-fs.target.requires" diff --git a/dracut/dracut.conf b/dracut/dracut.conf index 35aa080..bbe6458 100644 --- a/dracut/dracut.conf +++ b/dracut/dracut.conf @@ -1,5 +1,6 @@ -# This services should be run from immucore directly, rootfs at start of immucore and initramfs once we mount everything, -# so at the end, just before we let init do the switch_root +# This services should be run from immucore directly, rootfs once we mount /sysroot and initramfs once we mount everything, +# so at the end, just before we let init do the switch_root. Notice that we run really early in the boot with immucore so +# maybe by this time some things are not ready... # Note that initramfs run with RootDirectory=/sysroot install_items+=" /etc/systemd/system/cos-setup-initramfs.service /etc/systemd/system/initrd.target.requires/cos-setup-initramfs.service " # RUN BY IMMUCORE BUT FAILING diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index b2907d2..d35c2e7 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -88,7 +88,7 @@ func (s *State) RunStageOp(stage string) func(context.Context) error { return func(ctx context.Context) error { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() if stage == "rootfs" { - err := os.Symlink("/sysroot/system/", "/system/") + err := os.Symlink("/sysroot/system", "/system") if err != nil { s.Logger.Err(err).Msg("creating symlink") return err @@ -278,7 +278,7 @@ func (s *State) Register(g *herd.Graph) error { // TODO: add symlink if Rootdir != "" // TODO: chroot? s.Logger.Debug().Str("what", opRootfsHook).Msg("Add operation") - err = g.Add(opRootfsHook, mountRootCondition, herd.WithDeps(opMountOEM), herd.WithCallback(s.RunStageOp("rootfs"))) + err = g.Add(opRootfsHook, mountRootCondition, herd.WithDeps(opMountRoot), herd.WithCallback(s.RunStageOp("rootfs"))) if err != nil { s.Logger.Err(err).Msg("") } From bd5c1f1f552784502eb639ff7a8224860d9dba67 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 21:52:40 +0100 Subject: [PATCH 5/8] Fix depends for rootfs, proper path for layout Signed-off-by: Itxaka --- pkg/mount/mount.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index d35c2e7..9daf311 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -274,24 +274,23 @@ func (s *State) Register(g *herd.Graph) error { // This is building the mountRoot dependendency if it was enabled mountRootCondition := herd.ConditionalOption(func() bool { return s.MountRoot }, herd.WithDeps(opMountRoot)) - // TODO: this needs to be run after state is discovered - // TODO: add symlink if Rootdir != "" - // TODO: chroot? + // TODO: this needs to be run after sysroot so we can link to /sysroot/system/oem and after /oem mounted s.Logger.Debug().Str("what", opRootfsHook).Msg("Add operation") - err = g.Add(opRootfsHook, mountRootCondition, herd.WithDeps(opMountRoot), herd.WithCallback(s.RunStageOp("rootfs"))) + err = g.Add(opRootfsHook, mountRootCondition, herd.WithDeps(opMountRoot, opMountOEM), herd.WithCallback(s.RunStageOp("rootfs"))) if err != nil { - s.Logger.Err(err).Msg("") + s.Logger.Err(err).Msg("running rootfs stage") } - // /run/cos-layout.env + // /run/cos/cos-layout.env // populate state bindmounts, overlaymounts, custommounts s.Logger.Debug().Str("what", opLoadConfig).Msg("Add operation") err = g.Add(opLoadConfig, herd.WithDeps(opRootfsHook), herd.WithCallback(func(ctx context.Context) error { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() - env, err := readEnv("/run/cos-layout.env") + env, err := readEnv("/run/cos/cos-layout.env") if err != nil { + s.Logger.Err(err).Msg("Reading env") return err } log.Logger.Debug().Str("envfile", litter.Sdump(env)).Msg("loading cos layout") From 9dcf453764d5bc80bb0fb5bafcafc0e4344c8b46 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 21:58:53 +0100 Subject: [PATCH 6/8] Add a note to the generator sysroot.mount Signed-off-by: Itxaka --- dracut/28immucore/generator.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dracut/28immucore/generator.sh b/dracut/28immucore/generator.sh index 5c3f77e..5afca84 100755 --- a/dracut/28immucore/generator.sh +++ b/dracut/28immucore/generator.sh @@ -13,6 +13,12 @@ GENERATOR_DIR="$2" cos_img=$(getarg cos-img/filename=) [ -z "${cos_img}" ] && exit 0 +# This is necessary because otherwise systemd-fstab-generator will se the cmdline with the root=LABEL=X stanza and +# say, hey this is the ROOT where we need to boot! so it auto creates a sysroot.mount with the content of the value +# passed in the cmdline. But because we usually pass the label of the img (COS_ACTIVE) it will create the wrong mount +# service and be stuck in there forever. +# by generating it ourselves we get the sysroot.mount intot he generators.early dir, which tells systemd to not generate it +# as it already exists and the rest is history { echo "[Unit]" echo "Before=initrd-root-fs.target" From 856b01c540519c28e99f13046dfc53520fe7e20c Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 22:12:37 +0100 Subject: [PATCH 7/8] i dunno lol Signed-off-by: Itxaka --- pkg/mount/mount.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/mount/mount.go b/pkg/mount/mount.go index 9daf311..ae7ed4f 100644 --- a/pkg/mount/mount.go +++ b/pkg/mount/mount.go @@ -288,9 +288,12 @@ func (s *State) Register(g *herd.Graph) error { herd.WithDeps(opRootfsHook), herd.WithCallback(func(ctx context.Context) error { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() + if s.CustomMounts == nil { + s.CustomMounts = map[string]string{} + } env, err := readEnv("/run/cos/cos-layout.env") if err != nil { - s.Logger.Err(err).Msg("Reading env") + log.Logger.Err(err).Msg("Reading env") return err } log.Logger.Debug().Str("envfile", litter.Sdump(env)).Msg("loading cos layout") From 306d5c3e668e09a771f2c1d9a3ee05ffcb35f6a4 Mon Sep 17 00:00:00 2001 From: Itxaka Date: Tue, 7 Feb 2023 22:25:28 +0100 Subject: [PATCH 8/8] fix not initialized map and check for already mounted mounts instead of failing Signed-off-by: Itxaka --- pkg/mount/operation.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/mount/operation.go b/pkg/mount/operation.go index 9982bfe..176b2f8 100644 --- a/pkg/mount/operation.go +++ b/pkg/mount/operation.go @@ -3,6 +3,10 @@ package mount import ( "github.com/containerd/containerd/mount" "github.com/deniswernert/go-fstab" + "github.com/moby/sys/mountinfo" + "github.com/rs/zerolog" + "github.com/rs/zerolog/log" + "os" ) type mountOperation struct { @@ -13,11 +17,22 @@ type mountOperation struct { } func (m mountOperation) run() error { + log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).With().Caller().Logger() if m.PrepareCallback != nil { if err := m.PrepareCallback(); err != nil { + log.Logger.Err(err).Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Msg("executing mount callback") return err } } - + //TODO: not only check if mounted but also if the type,options and source are the same? + mounted, err := mountinfo.Mounted(m.Target) + if err != nil { + log.Logger.Err(err).Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Msg("checking mount status") + return err + } + if mounted { + log.Logger.Debug().Str("what", m.MountOption.Source).Str("where", m.Target).Str("type", m.MountOption.Type).Msg("Already mounted") + return nil + } return mount.All([]mount.Mount{m.MountOption}, m.Target) }