-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
123 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package filesystem | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/opencontainers/runtime-spec/specs-go" | ||
) | ||
|
||
var ( | ||
defaultFileMode = os.FileMode(0666) | ||
defaultUID uint32 = 0 | ||
defaultGID uint32 = 0 | ||
) | ||
|
||
var DefaultSymlinks = map[string]string{ | ||
"/proc/self/fd": "dev/fd", | ||
"/proc/self/fd/0": "dev/stdin", | ||
"/proc/self/fd/1": "dev/stdout", | ||
"/proc/self/fd/2": "dev/stderr", | ||
"pts/ptmx": "dev/ptmx", | ||
} | ||
|
||
var DefaultDevices = []specs.LinuxDevice{ | ||
{ | ||
Path: "/dev/null", | ||
Type: CharDevice, | ||
Major: 1, | ||
Minor: 3, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
{ | ||
Type: CharDevice, | ||
Path: "/dev/zero", | ||
Major: 1, | ||
Minor: 5, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
{ | ||
Type: CharDevice, | ||
Path: "/dev/full", | ||
Major: 1, | ||
Minor: 7, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
{ | ||
Type: CharDevice, | ||
Path: "/dev/random", | ||
Major: 1, | ||
Minor: 8, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
{ | ||
Type: CharDevice, | ||
Path: "/dev/urandom", | ||
Major: 1, | ||
Minor: 9, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
{ | ||
Type: CharDevice, | ||
Path: "/dev/tty", | ||
Major: 5, | ||
Minor: 0, | ||
FileMode: &defaultFileMode, | ||
UID: &defaultUID, | ||
GID: &defaultGID, | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package filesystem | ||
|
||
var ( | ||
AllDevices = "a" | ||
BlockDevice = "b" | ||
CharDevice = "c" | ||
UnbufferedCharDevice = "u" | ||
FifoDevice = "p" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package filesystem | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"syscall" | ||
) | ||
|
||
func PivotRootfs(containerRootfs string) error { | ||
oldroot := filepath.Join(containerRootfs, "oldroot") | ||
|
||
if err := os.MkdirAll(oldroot, 0700); err != nil { | ||
return fmt.Errorf("make old root dir: %w", err) | ||
} | ||
|
||
if err := syscall.PivotRoot(containerRootfs, oldroot); err != nil { | ||
return fmt.Errorf("pivot to new root: %w", err) | ||
} | ||
|
||
if err := os.Chdir("/"); err != nil { | ||
return fmt.Errorf("chdir to new root: %w", err) | ||
} | ||
|
||
if err := syscall.Unmount("oldroot", syscall.MNT_DETACH); err != nil { | ||
return fmt.Errorf("unmount old root: %w", err) | ||
} | ||
|
||
if err := os.RemoveAll("oldroot"); err != nil { | ||
return fmt.Errorf("remove old root: %w", err) | ||
} | ||
|
||
return nil | ||
} |