diff --git a/core/system.go b/core/system.go index e3765d66..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" ) @@ -423,16 +423,30 @@ mount -o bind,ro /.system/usr /usr func (s *ABSystem) GenerateMountpointsSystemDUnit(rootPath string, root ABRootPartition) error { PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit: generating script") + depTarget := "local-fs" template := `[Unit] Description=Mount partitions -Requires=cryptsetup.target -After=cryptsetup.target +Requires=%s.target +After=%s.target [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" + 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) if err != nil { @@ -440,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