Skip to content

Commit

Permalink
Merge pull request #110 from mirkobrombin/v2
Browse files Browse the repository at this point in the history
feat:[close #109] Use fs-local target for mounts in devices with no encryption enabled
  • Loading branch information
mirkobrombin authored Aug 23, 2023
2 parents a0f5e6c + d77eaf3 commit a796df7
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions core/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -423,30 +423,44 @@ 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 {
PrintVerbose("ABSystem.GenerateMountpointsSystemDUnit:err(2): %s", err)
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
Expand Down

0 comments on commit a796df7

Please sign in to comment.