Skip to content

Commit

Permalink
moves all data folders to /var
Browse files Browse the repository at this point in the history
  • Loading branch information
taukakao committed Nov 21, 2024
1 parent 2b3efdb commit b6301c3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
39 changes: 37 additions & 2 deletions cmd/mount-sys.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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},
}

Expand Down Expand Up @@ -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
}
15 changes: 10 additions & 5 deletions core/integrity.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ 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
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) {
Expand Down

0 comments on commit b6301c3

Please sign in to comment.