mirror of
https://github.com/rancher/os.git
synced 2025-09-02 15:24:32 +00:00
Fix setting up state partition
This commit is contained in:
59
init/root.go
59
init/root.go
@@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
@@ -13,25 +14,67 @@ import (
|
|||||||
"github.com/rancherio/os/config"
|
"github.com/rancherio/os/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func prepareRoot(rootfs string) error {
|
func cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir string) (bool, error) {
|
||||||
usr := path.Join(rootfs, "usr")
|
log.Debugf("Deleting %s", targetUsr)
|
||||||
if err := os.Remove(usr); err != nil && !os.IsNotExist(err) {
|
if err := os.Remove(targetUsr); err != nil && !os.IsNotExist(err) {
|
||||||
log.Errorf("Failed to delete %s, possibly invalid RancherOS state partition: %v", usr, err)
|
log.Errorf("Failed to delete %s, possibly invalid RancherOS state partition: %v", targetUsr, err)
|
||||||
return err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
if err := dockerlaunch.CreateSymlink(usrVer, path.Join(rootfs, "usr")); err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Deleting %s", tmpDir)
|
||||||
|
if err := os.RemoveAll(tmpDir); err != nil {
|
||||||
|
// Don't care if this fails
|
||||||
|
log.Errorf("Failed to cleanup temp directory %s: %v", tmpDir, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasSuffix(usrVer, "dev") {
|
||||||
|
log.Debugf("Deleteing old usr: %s", usr)
|
||||||
|
if err := os.RemoveAll(usr); err != nil {
|
||||||
|
// Don't care if this fails
|
||||||
|
log.Errorf("Failed to remove %s: %v", usr, err)
|
||||||
|
}
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(usrVer); os.IsNotExist(err) {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func copyMoveRoot(rootfs string) error {
|
func copyMoveRoot(rootfs string) error {
|
||||||
usrVer := fmt.Sprintf("usr-%s", config.VERSION)
|
usrVer := fmt.Sprintf("usr-%s", config.VERSION)
|
||||||
usr := path.Join(rootfs, usrVer)
|
usr := path.Join(rootfs, usrVer)
|
||||||
|
targetUsr := path.Join(rootfs, "usr")
|
||||||
|
tmpDir := path.Join(rootfs, "tmp")
|
||||||
|
|
||||||
if err := archive.CopyWithTar("/usr", usr); err != nil {
|
if cont, err := cleanupTarget(rootfs, targetUsr, usr, usrVer, tmpDir); !cont {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := dockerlaunch.CreateSymlink(usrVer, path.Join(rootfs, "usr")); err != nil {
|
log.Debugf("Creating temp dir directory %s", tmpDir)
|
||||||
|
if err := os.MkdirAll(tmpDir, 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
usrVerTmp, err := ioutil.TempDir(tmpDir, usrVer)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Copying to temp dir %s", usrVerTmp)
|
||||||
|
|
||||||
|
if err := archive.CopyWithTar("/usr", usrVerTmp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debugf("Renaming %s => %s", usrVerTmp, usr)
|
||||||
|
if err := os.Rename(usrVerTmp, usr); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user