Skip to content

Commit 3ed2d55

Browse files
committed
setup: Don't mount devtmpfs if not needed
If we're running in a virtual machine, there is no need to mount /dev in the container (it will be mounted in the vm). This is important because in a rootless container we're not allowed to mount devtmpfs.
1 parent 13a177b commit 3ed2d55

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

cmd/image-builder/bib_main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ func bibCmdBuild(cmd *cobra.Command, args []string) error {
290290
case false:
291291
fmt.Fprintf(os.Stderr, "WARNING: running outside a container, this is an unsupported configuration\n")
292292
case true:
293-
if err := setup.EnsureEnvironment(osbuildStore); err != nil {
293+
if err := setup.EnsureEnvironment(osbuildStore, false); err != nil {
294294
return fmt.Errorf("cannot ensure the environment: %w", err)
295295
}
296296
}

cmd/image-builder/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ func cmdBuild(cmd *cobra.Command, args []string) error {
390390

391391
// Setup osbuild environment if running in a container
392392
if setup.IsContainer() {
393-
if err := setup.EnsureEnvironment(cacheDir); err != nil {
393+
if err := setup.EnsureEnvironment(cacheDir, false); err != nil {
394394
return fmt.Errorf("entrypoint setup failed: %w", err)
395395
}
396396
}

pkg/setup/setup.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717

1818
// EnsureEnvironment mutates external filesystem state as necessary
1919
// to run in a container environment. This function is idempotent.
20-
func EnsureEnvironment(storePath string) error {
20+
func EnsureEnvironment(storePath string, inVm bool) error {
2121
osbuildPath := "/usr/bin/osbuild"
2222
if util.IsMountpoint(osbuildPath) {
2323
return nil
@@ -63,9 +63,11 @@ func EnsureEnvironment(storePath string) error {
6363
}
6464

6565
// Ensure we have devfs inside the container to get dynamic loop
66-
// loop devices inside the container.
67-
if err := util.RunCmdSync("mount", "-t", "devtmpfs", "devtmpfs", "/dev"); err != nil {
68-
return err
66+
// loop devices inside the container. (Not needed if in a vm)
67+
if !inVm {
68+
if err := util.RunCmdSync("mount", "-t", "devtmpfs", "devtmpfs", "/dev"); err != nil {
69+
return err
70+
}
6971
}
7072

7173
// Create a bind mount into our target location; we can't copy it because

0 commit comments

Comments
 (0)