Skip to content

Commit eeaad76

Browse files
taukakaomirkobrombin
authored andcommitted
remove generation of systemd mount information
Since abroot now handles mounting before systemd, this is not required anymore.
1 parent 24c1c14 commit eeaad76

File tree

1 file changed

+14
-198
lines changed

1 file changed

+14
-198
lines changed

core/system.go

+14-198
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ var (
8585
lockFile string = filepath.Join("/tmp", "ABSystem.Upgrade.lock")
8686
stageFile string = filepath.Join("/tmp", "ABSystem.Upgrade.stage")
8787
userLockFile string = filepath.Join("/tmp", "ABSystem.Upgrade.user.lock")
88-
mountUnitDir = "/etc/systemd/system"
8988

9089
// Errors
9190
ErrNoUpdate error = errors.New("no update available")
@@ -135,166 +134,6 @@ func (s *ABSystem) CheckUpdate() (string, bool) {
135134
return s.Registry.HasUpdate(s.CurImage.Digest)
136135
}
137136

138-
// GenerateFstab generates a fstab file for the future root
139-
func (s *ABSystem) GenerateFstab(rootPath string, root ABRootPartition) error {
140-
PrintVerboseInfo("ABSystem.GenerateFstab", "generating fstab")
141-
142-
template := `# /etc/fstab: static file system information.
143-
# Generated by ABRoot
144-
#
145-
# <file system> <mount point> <type> <options> <dump> <pass>
146-
UUID=%s / %s defaults 0 0
147-
/.system/usr /.system/usr none bind,ro
148-
%s /var auto defaults 0 0
149-
`
150-
varSource := ""
151-
if s.RootM.VarPartition.IsDevMapper() {
152-
varSource = fmt.Sprintf("/dev/mapper/%s", s.RootM.VarPartition.Device)
153-
} else {
154-
varSource = fmt.Sprintf("UUID=%s", s.RootM.VarPartition.Uuid)
155-
}
156-
157-
fstab := fmt.Sprintf(
158-
template,
159-
root.Partition.Uuid,
160-
root.Partition.FsType,
161-
varSource,
162-
)
163-
164-
err := os.WriteFile(filepath.Join(rootPath, "/etc/fstab"), []byte(fstab), 0o644)
165-
if err != nil {
166-
PrintVerboseErr("ABSystem.GenerateFstab", 0, err)
167-
return err
168-
}
169-
170-
PrintVerboseInfo("ABSystem.GenerateFstab", "fstab generated")
171-
return nil
172-
}
173-
174-
// GenerateCrypttab identifies which devices are encrypted and generates
175-
// the /etc/crypttab file for the specified root
176-
func (s *ABSystem) GenerateCrypttab(rootPath string) error {
177-
PrintVerboseInfo("ABSystem.GenerateCrypttab", "generating crypttab")
178-
179-
cryptEntries := [][]string{}
180-
181-
// Check for encrypted roots
182-
for _, rootDevice := range s.RootM.Partitions {
183-
if strings.HasPrefix(rootDevice.Partition.Device, "luks-") {
184-
parent := rootDevice.Partition.Parent
185-
PrintVerboseInfo("ABSystem.GenerateCrypttab", "Adding", parent.Device, "to crypttab")
186-
187-
cryptEntries = append(cryptEntries, []string{
188-
fmt.Sprintf("luks-%s", parent.Uuid),
189-
fmt.Sprintf("UUID=%s", parent.Uuid),
190-
"none",
191-
"luks,discard",
192-
})
193-
}
194-
}
195-
196-
// Check for encrypted /var
197-
if strings.HasPrefix(s.RootM.VarPartition.Device, "luks-") {
198-
parent := s.RootM.VarPartition.Parent
199-
PrintVerboseInfo("ABSystem.GenerateCrypttab", "Adding", parent.Device, "to crypttab")
200-
201-
cryptEntries = append(cryptEntries, []string{
202-
fmt.Sprintf("luks-%s", parent.Uuid),
203-
fmt.Sprintf("UUID=%s", parent.Uuid),
204-
"none",
205-
"luks,discard",
206-
})
207-
}
208-
209-
crypttabContent := ""
210-
for _, entry := range cryptEntries {
211-
fmtEntry := strings.Join(entry, " ")
212-
crypttabContent += fmtEntry + "\n"
213-
}
214-
215-
err := os.WriteFile(rootPath+"/etc/crypttab", []byte(crypttabContent), 0o644)
216-
if err != nil {
217-
PrintVerboseErr("ABSystem.GenerateCrypttab", 3, err)
218-
return err
219-
}
220-
221-
return nil
222-
}
223-
224-
// GenerateSystemdUnits generates systemd units that mount the mutable parts
225-
// of the system to their respective mountpoints
226-
func (s *ABSystem) GenerateSystemdUnits(rootPath string, root ABRootPartition) error {
227-
PrintVerboseInfo("ABSystem.GenerateSystemdUnits", "generating units")
228-
229-
extraDepends := ""
230-
if root.Partition.IsEncrypted() || s.RootM.VarPartition.IsEncrypted() {
231-
extraDepends = "cryptsetup.target"
232-
}
233-
234-
type varmount struct {
235-
source string
236-
destination string
237-
fsType string
238-
options string
239-
}
240-
241-
mounts := []varmount{
242-
{"/var/home", "/home", "none", "bind"},
243-
{"/var/opt", "/opt", "none", "bind"},
244-
{"overlay", "/.system/etc", "overlay", "lowerdir=/.system/etc,upperdir=/var/lib/abroot/etc/" + root.Label + ",workdir=/var/lib/abroot/etc/" + root.Label + "-work"},
245-
}
246-
247-
afterVarTemplate := `[Unit]
248-
Description=Mounts %s from var
249-
After=local-fs-pre.target %s
250-
Before=local-fs.target nss-user-lookup.target
251-
RequiresMountsFor=/var
252-
253-
[Mount]
254-
What=%s
255-
Where=%s
256-
Type=%s
257-
Options=%s
258-
`
259-
260-
for _, mount := range mounts {
261-
PrintVerboseInfo("ABSystem.GenerateSystemdUnits", "generating unit for", mount.destination)
262-
263-
unit := fmt.Sprintf(afterVarTemplate, mount.destination, extraDepends, mount.source, mount.destination, mount.fsType, mount.options)
264-
265-
// the unit file needs to have the escaped mount point as its name
266-
out, err := exec.Command("systemd-escape", "--path", mount.destination).Output()
267-
if err != nil {
268-
PrintVerboseErr("ABSystem.GenerateSystemdUnits", 0, "failed to determine escaped path", err)
269-
return err
270-
}
271-
mountUnitFile := "/" + strings.ReplaceAll(string(out), "\n", "") + ".mount"
272-
273-
err = os.WriteFile(filepath.Join(rootPath, mountUnitDir, mountUnitFile), []byte(unit), 0o644)
274-
if err != nil {
275-
PrintVerboseErr("ABSystem.GenerateSystemdUnits", 1, err)
276-
return err
277-
}
278-
279-
const targetRequires string = "/local-fs-pre.target.requires"
280-
281-
err = os.MkdirAll(filepath.Join(rootPath, mountUnitDir, targetRequires), 0o755)
282-
if err != nil {
283-
PrintVerboseErr("ABSystem.GenerateSystemdUnits", 2, err)
284-
return err
285-
}
286-
287-
err = os.Symlink(filepath.Join("../", mountUnitFile), filepath.Join(rootPath, mountUnitDir, targetRequires, mountUnitFile))
288-
if err != nil {
289-
PrintVerboseErr("ABSystem.GenerateSystemdUnits", 3, "failed to create symlink", err)
290-
return err
291-
}
292-
}
293-
294-
PrintVerboseInfo("ABSystem.GenerateSystemdUnits", "units generated")
295-
return nil
296-
}
297-
298137
func (s *ABSystem) CreateRootSymlinks(systemNewPath string) error {
299138
PrintVerboseInfo("ABSystem.CreateRootSymlinks", "creating symlinks")
300139
links := []string{"mnt", "proc", "run", "dev", "media", "root", "sys", "tmp", "var"}
@@ -602,29 +441,6 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
602441
return err
603442
}
604443

605-
// Stage 6: Generate /etc/fstab, /etc/crypttab, and the
606-
// SystemD units to setup mountpoints
607-
// ------------------------------------------------
608-
PrintVerboseSimple("[Stage 6] -------- ABSystemRunOperation")
609-
610-
err = s.GenerateFstab(systemNew, partFuture)
611-
if err != nil {
612-
PrintVerboseErr("ABSystem.RunOperation", 6, err)
613-
return err
614-
}
615-
616-
err = s.GenerateCrypttab(systemNew)
617-
if err != nil {
618-
PrintVerboseErr("ABSystem.RunOperation", 6.1, err)
619-
return err
620-
}
621-
622-
err = s.GenerateSystemdUnits(systemNew, partFuture)
623-
if err != nil {
624-
PrintVerboseErr("ABSystem.RunOperation", 6.2, "Failed to Generate SystemdUnits", err)
625-
return err
626-
}
627-
628444
// Stage (dry): If dry-run, exit here before writing to disk
629445
// ------------------------------------------------
630446
switch operation {
@@ -633,9 +449,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
633449
return nil
634450
}
635451

636-
// Stage 7: Update the bootloader
452+
// Stage 6: Update the bootloader
637453
// ------------------------------------------------
638-
PrintVerboseSimple("[Stage 7] -------- ABSystemRunOperation")
454+
PrintVerboseSimple("[Stage 6] -------- ABSystemRunOperation")
639455

640456
partPresent, err := s.RootM.GetPresent()
641457
if err != nil {
@@ -762,9 +578,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
762578
return err
763579
}
764580

765-
// Stage 8: Sync /etc
581+
// Stage 7: Sync /etc
766582
// ------------------------------------------------
767-
PrintVerboseSimple("[Stage 8] -------- ABSystemRunOperation")
583+
PrintVerboseSimple("[Stage 7] -------- ABSystemRunOperation")
768584

769585
oldEtc := "/.system/sysconf" // The current etc WITHOUT anything overlayed
770586
presentEtc, err := s.RootM.GetPresent()
@@ -786,9 +602,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
786602
return err
787603
}
788604

789-
// Stage 9: Mount boot partition
605+
// Stage 8: Mount boot partition
790606
// ------------------------------------------------
791-
PrintVerboseSimple("[Stage 9] -------- ABSystemRunOperation")
607+
PrintVerboseSimple("[Stage 8] -------- ABSystemRunOperation")
792608

793609
uuid := uuid.New().String()
794610
tmpBootMount := filepath.Join("/tmp", uuid)
@@ -808,9 +624,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
808624
return partBoot.Unmount()
809625
}, nil, 100, &goodies.NoErrorHandler{}, false)
810626

811-
// Stage 10: Atomic swap the rootfs and abimage.abr
627+
// Stage 9: Atomic swap the rootfs and abimage.abr
812628
// ------------------------------------------------
813-
PrintVerboseSimple("[Stage 10] -------- ABSystemRunOperation")
629+
PrintVerboseSimple("[Stage 9] -------- ABSystemRunOperation")
814630

815631
err = AtomicSwap(systemOld, systemNew)
816632
if err != nil {
@@ -842,9 +658,9 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
842658
return os.RemoveAll(newABImage)
843659
}, nil, 30, &goodies.NoErrorHandler{}, false)
844660

845-
// Stage 11: Atomic swap the bootloader
661+
// Stage 10: Atomic swap the bootloader
846662
// ------------------------------------------------
847-
PrintVerboseSimple("[Stage 11] -------- ABSystemRunOperation")
663+
PrintVerboseSimple("[Stage 10] -------- ABSystemRunOperation")
848664

849665
grub, err := NewGrub(partBoot)
850666
if err != nil {
@@ -862,7 +678,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
862678
grubCfgCurrent := filepath.Join(tmpBootMount, "grub/grub.cfg")
863679
grubCfgFuture := filepath.Join(tmpBootMount, "grub/grub.cfg.future")
864680

865-
// Just like in Stage 10, tmpBootMount/grub/grub.cfg.future may not exist.
681+
// Just like in Stage 9, tmpBootMount/grub/grub.cfg.future may not exist.
866682
if _, err = os.Stat(grubCfgFuture); os.IsNotExist(err) {
867683
PrintVerboseInfo("ABSystem.RunOperation", "Creating grub.cfg.future")
868684

@@ -897,7 +713,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
897713
}
898714
}
899715

900-
// Stage 12: Cleanup old kernel images
716+
// Stage 11: Cleanup old kernel images
901717
// ------------------------------------------------
902718
// If Thin-Provisioning set, we have to remove the old kernel images
903719
// from the init partition since it is too small to hold multiple kernels.
@@ -907,7 +723,7 @@ func (s *ABSystem) RunOperation(operation ABSystemOperation) error {
907723
switch operation {
908724
case DRY_RUN_UPGRADE, DRY_RUN_APPLY, DRY_RUN_INITRAMFS:
909725
default:
910-
PrintVerboseSimple("[Stage 12] -------- ABSystemRunOperation")
726+
PrintVerboseSimple("[Stage 11] -------- ABSystemRunOperation")
911727

912728
// since we did the swap, the init partition is now mounted in
913729
// .system instead of .system.new, so we need to update the path
@@ -997,7 +813,7 @@ func (s *ABSystem) Rollback(checkOnly bool) (response ABRollbackResponse, err er
997813
grubCfgCurrent := filepath.Join(tmpBootMount, "grub/grub.cfg")
998814
grubCfgFuture := filepath.Join(tmpBootMount, "grub/grub.cfg.future")
999815

1000-
// Just like in Stage 10, tmpBootMount/grub/grub.cfg.future may not exist.
816+
// Just like in Stage 9, tmpBootMount/grub/grub.cfg.future may not exist.
1001817
if _, err = os.Stat(grubCfgFuture); os.IsNotExist(err) {
1002818
PrintVerboseInfo("ABSystem.Rollback", "Creating grub.cfg.future")
1003819

0 commit comments

Comments
 (0)