From b6301c3214e0a69d77d5c6321407742d604bcfc5 Mon Sep 17 00:00:00 2001 From: Tau Date: Fri, 8 Nov 2024 19:47:32 +0100 Subject: [PATCH] moves all data folders to /var --- cmd/mount-sys.go | 39 +++++++++++++++++++++++++++++++++++++-- core/integrity.go | 15 ++++++++++----- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/cmd/mount-sys.go b/cmd/mount-sys.go index 40988402..78add7ee 100644 --- a/cmd/mount-sys.go +++ b/cmd/mount-sys.go @@ -100,6 +100,12 @@ func mountSys(cmd *cobra.Command, _ []string) error { os.Exit(5) } + err = compatBindMounts(dryRun) + if err != nil { + cmdr.Error.Println(err) + return err + } + err = mountBindMounts(dryRun) if err != nil { cmdr.Error.Println(err) @@ -157,8 +163,6 @@ func mountBindMounts(dryRun bool) error { } binds := []bindMount{ - {"/var/home", "/home", 0}, - {"/var/opt", "/opt", 0}, {"/.system/usr", "/.system/usr", syscall.MS_RDONLY}, } @@ -272,3 +276,34 @@ func adjustFstab(uuid string, dryRun bool) error { return nil } + +// this is here to keep compatibility with older systems +// e.g. /home was a bind mount instead of a symlink to /var/home +func compatBindMounts(dryRun bool) (err error) { + type bindMount struct { + from, to string + options uintptr + } + + binds := []bindMount{ + {"/var/home", "/home", 0}, + {"/var/opt", "/opt", 0}, + } + + for _, bind := range binds { + if info, err := os.Lstat(bind.to); err == nil && !info.IsDir() { + // path has been migrated already + continue + } + + cmdr.FgDefault.Println("bind-mounting " + bind.from + " to " + bind.to) + if !dryRun { + err := syscall.Mount(bind.from, bind.to, "", syscall.MS_BIND|bind.options, "") + if err != nil { + return err + } + } + } + + return nil +} diff --git a/core/integrity.go b/core/integrity.go index 9fa527f2..10e66015 100644 --- a/core/integrity.go +++ b/core/integrity.go @@ -29,6 +29,11 @@ var linksToRepair = [...][2]string{ {".system/libx32", "libx32"}, {".system/sbin", "sbin"}, {".system/usr", "usr"}, + {"var/home", "home"}, + {"var/media", "media"}, + {"var/mnt", "mnt"}, + {"var/opt", "opt"}, + {"var/root", "root"}, } // paths that must exist in the root partition @@ -36,18 +41,18 @@ var pathsToRepair = [...]string{ ".system", "boot", "dev", - "home", - "media", - "mnt", - "opt", "part-future", "proc", - "root", "run", "srv", "sys", "tmp", "var", + "var/home", + "var/media", + "var/mnt", + "var/opt", + "var/root", } func RepairRootIntegrity(rootPath string) (err error) {