Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
## Requirements

### Linux
**KVM** virtualization support required. Supports Cloud Hypervisor, Firecracker, and QEMU as hypervisors.
- **KVM** virtualization support. Supported hypervisors: Cloud Hypervisor, Firecracker, and QEMU.
- **erofs-utils** provides `mkfs.erofs` for converting OCI images into VM disks.

### macOS
**macOS 11.0+** on Apple Silicon. Uses Apple's Virtualization.framework via the `vz` hypervisor.
Expand Down
8 changes: 8 additions & 0 deletions lib/images/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package images

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -254,6 +255,13 @@ func convertToErofs(ctx context.Context, rootfsDir, diskPath string) (int64, err
cmd := exec.CommandContext(ctx, "mkfs.erofs", "-zlz4", diskPath, rootfsDir)
output, err := cmd.CombinedOutput()
if err != nil {
if errors.Is(err, exec.ErrNotFound) {
return 0, fmt.Errorf(
"required tool mkfs.erofs not found in the API server's PATH; "+
"on Ubuntu/Debian, install it with: sudo apt-get install erofs-utils: %w",
err,
)
}
return 0, fmt.Errorf("mkfs.erofs failed: %w, output: %s", err, output)
}

Expand Down
24 changes: 24 additions & 0 deletions lib/images/disk_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package images

import (
"context"
"os/exec"
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
)

func TestExportRootfsWithContextMissingErofsTool(t *testing.T) {
// Isolate command lookup even when mkfs.erofs is installed on the host.
t.Setenv("PATH", t.TempDir())
rootfsDir := t.TempDir()
diskPath := filepath.Join(t.TempDir(), "rootfs.erofs")

_, err := ExportRootfsWithContext(context.Background(), rootfsDir, diskPath, FormatErofs)

require.ErrorIs(t, err, exec.ErrNotFound)
require.Contains(t, err.Error(), "mkfs.erofs")
require.Contains(t, err.Error(), "sudo apt-get install erofs-utils")
require.NoFileExists(t, diskPath)
}
2 changes: 2 additions & 0 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ else
SUDO="sudo"
fi
command -v systemctl >/dev/null 2>&1 || error "systemctl is required but not installed (systemd not available?)"
command -v mkfs.erofs >/dev/null 2>&1 || error \
"mkfs.erofs is required to convert OCI images into VM disks. On Ubuntu/Debian, install it with: sudo apt-get install erofs-utils"
fi

# Common checks
Expand Down