diff --git a/README.md b/README.md index aefa7613c..0b859e921 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/images/disk.go b/lib/images/disk.go index 68184b785..fcd27dcb2 100644 --- a/lib/images/disk.go +++ b/lib/images/disk.go @@ -2,6 +2,7 @@ package images import ( "context" + "errors" "fmt" "io" "os" @@ -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) } diff --git a/lib/images/disk_test.go b/lib/images/disk_test.go new file mode 100644 index 000000000..aa0f7d31c --- /dev/null +++ b/lib/images/disk_test.go @@ -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) +} diff --git a/scripts/install.sh b/scripts/install.sh index 29f305433..329946ecb 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -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