From 3ed257fd9f128ca606fc48f81889f41eda513ab7 Mon Sep 17 00:00:00 2001 From: mirkobrombin Date: Mon, 21 Aug 2023 23:39:54 +0200 Subject: [PATCH 1/3] switch target for non encrypted devices --- core/system.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/core/system.go b/core/system.go index e3765d66..ac4cae18 100644 --- a/core/system.go +++ b/core/system.go @@ -423,16 +423,25 @@ mount -o bind,ro /.system/usr /usr func (s *ABSystem) GenerateMountpointsSystemDUnit(rootPath string, root ABRootPartition) error { PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit: generating script") + depTarget := "local-fs.target" template := `[Unit] Description=Mount partitions -Requires=cryptsetup.target -After=cryptsetup.target +Requires=%s +After=%s [Service] Type=oneshot ExecStart=%s ` - unit := fmt.Sprintf(template, MountScriptPath) + // Check for encrypted roots + for _, rootDevice := range s.RootM.Partitions { + if strings.HasPrefix(rootDevice.Partition.Device, "luks-") { + depTarget = "cryptsetup.target" + break + } + } + + unit := fmt.Sprintf(template, depTarget, depTarget, MountScriptPath) err := os.WriteFile(rootPath+MountUnitDir+MountUnitFile, []byte(unit), 0755) if err != nil { From 516db5fd2e80a7a62a2df16a4ed9871a10602aae Mon Sep 17 00:00:00 2001 From: Mateus Melchiades Date: Tue, 22 Aug 2023 18:06:04 -0300 Subject: [PATCH 2/3] Check for encrypted var --- core/system.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/core/system.go b/core/system.go index ac4cae18..4b926270 100644 --- a/core/system.go +++ b/core/system.go @@ -423,11 +423,11 @@ mount -o bind,ro /.system/usr /usr func (s *ABSystem) GenerateMountpointsSystemDUnit(rootPath string, root ABRootPartition) error { PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit: generating script") - depTarget := "local-fs.target" + depTarget := "local-fs" template := `[Unit] Description=Mount partitions -Requires=%s -After=%s +Requires=%s.target +After=%s.target [Service] Type=oneshot @@ -436,11 +436,16 @@ ExecStart=%s // Check for encrypted roots for _, rootDevice := range s.RootM.Partitions { if strings.HasPrefix(rootDevice.Partition.Device, "luks-") { - depTarget = "cryptsetup.target" + depTarget = "cryptsetup" break } } + // Check for encrypted var + if strings.HasPrefix(s.RootM.VarPartition.Device, "luks-") { + depTarget = "cryptsetup" + } + unit := fmt.Sprintf(template, depTarget, depTarget, MountScriptPath) err := os.WriteFile(rootPath+MountUnitDir+MountUnitFile, []byte(unit), 0755) From 9b2b0374007c9a55f51bbb9b82813cf308a87519 Mon Sep 17 00:00:00 2001 From: Mateus Melchiades Date: Tue, 22 Aug 2023 18:37:41 -0300 Subject: [PATCH 3/3] Use proper target directory for SystemD unit --- core/system.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/system.go b/core/system.go index 4b926270..8bc54a0f 100644 --- a/core/system.go +++ b/core/system.go @@ -49,7 +49,7 @@ const ( const ( MountScriptPath = "/usr/sbin/.abroot-mountpoints" MountUnitDir = "/etc/systemd/system" - SystemDTargetDir = "/etc/systemd/system/cryptsetup.target.wants" + SystemDTargetDir = "/etc/systemd/system/%s.target.wants" MountUnitFile = "/abroot-mount.service" ) @@ -454,13 +454,13 @@ ExecStart=%s return err } - err = os.MkdirAll(rootPath+SystemDTargetDir, 0755) + err = os.MkdirAll(rootPath+fmt.Sprintf(SystemDTargetDir, depTarget), 0755) if err != nil { PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit:err(3): %s", err) return err } - err = os.Symlink(rootPath+MountUnitDir+MountUnitFile, rootPath+SystemDTargetDir+MountUnitFile) + err = os.Symlink(rootPath+MountUnitDir+MountUnitFile, rootPath+fmt.Sprintf(SystemDTargetDir, depTarget)+MountUnitFile) if err != nil { PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit:err(4): %s", err) return err