Skip to content

An open-source, faster Devin alternative

TypeScript

virtio-mem fixes

Brian Reardon7de93065257f
diff --git a/deploy/azure/setup-azure-host.sh b/deploy/azure/setup-azure-host.sh
index 867b0911..e52e5439 100755
--- a/deploy/azure/setup-azure-host.sh
+++ b/deploy/azure/setup-azure-host.sh
@@ -62,7 +62,7 @@ if [ -n "$GENERIC_VMLINUZ" ]; then
GENERIC_KVER=$(basename "$GENERIC_VMLINUZ" | sed 's/vmlinuz-//')
echo "Guest kernel: $GENERIC_VMLINUZ ($GENERIC_KVER)"
- # Extract vsock and overlay modules for the guest rootfs (loaded via insmod at boot)
+ # Extract vsock, overlay, and virtio_mem modules for the guest rootfs
MODDIR="/lib/modules/$GENERIC_KVER"
GUEST_MODDIR="$KERNEL_DIR/guest-modules"
mkdir -p "$GUEST_MODDIR"
@@ -70,7 +70,8 @@ if [ -n "$GENERIC_VMLINUZ" ]; then
"$MODDIR/kernel/fs/overlayfs/overlay.ko"* \
"$MODDIR/kernel/net/vmw_vsock/vsock.ko"* \
"$MODDIR/kernel/net/vmw_vsock/vmw_vsock_virtio_transport_common.ko"* \
- "$MODDIR/kernel/net/vmw_vsock/vmw_vsock_virtio_transport.ko"*; do
+ "$MODDIR/kernel/net/vmw_vsock/vmw_vsock_virtio_transport.ko"* \
+ "$MODDIR/kernel/drivers/virtio/virtio_mem.ko"*; do
[ -f "$mod" ] || continue
base=$(basename "$mod")
if [[ "$base" == *.zst ]]; then
@@ -81,6 +82,14 @@ if [ -n "$GENERIC_VMLINUZ" ]; then
done
echo "Guest modules extracted to $GUEST_MODDIR:"
ls "$GUEST_MODDIR/"
+
+ # Validate virtio_mem.ko was extracted — fail fast if missing
+ if ! ls "$GUEST_MODDIR"/virtio_mem.ko* >/dev/null 2>&1; then
+ echo "FATAL: virtio_mem.ko not found for kernel $GENERIC_KVER"
+ echo " Looked in: $MODDIR/kernel/drivers/virtio/virtio_mem.ko*"
+ echo " Memory scaling will not work. Check that linux-image-generic includes virtio_mem."
+ exit 1
+ fi
else
echo "WARNING: No generic kernel found. Guest VMs may not boot correctly."
fi
diff --git a/deploy/ec2/build-rootfs-docker.sh b/deploy/ec2/build-rootfs-docker.sh
index d408b18c..bbe943fb 100755
--- a/deploy/ec2/build-rootfs-docker.sh
+++ b/deploy/ec2/build-rootfs-docker.sh
@@ -80,14 +80,19 @@ if [ -d /lib/modules/vsock ]; then
fi
# Load virtio-mem module (for dynamic memory scaling)
-# Check both the standard kernel path and our guest-modules dir
-for vmem in "/lib/modules/$(uname -r)/kernel/drivers/virtio/virtio_mem.ko" "/lib/modules/vsock/virtio_mem.ko"; do
- if [ -f "$vmem" ]; then
- insmod "$vmem" 2>/dev/null || true
- echo "init: virtio_mem module loaded ($vmem)"
- break
- fi
-done
+# Try modprobe first (handles signatures + deps), fall back to insmod.
+# This is best-effort at boot — golden snapshot creation will fail hard if not loaded.
+if command -v modprobe >/dev/null 2>&1; then
+ modprobe virtio_mem 2>/dev/null && echo "init: virtio_mem loaded (modprobe)" || true
+else
+ for vmem in "/lib/modules/$(uname -r)/kernel/drivers/virtio/virtio_mem.ko" "/lib/modules/vsock/virtio_mem.ko"; do
+ if [ -f "$vmem" ]; then
+ insmod "$vmem" 2>/dev/null || true
+ echo "init: virtio_mem loaded ($vmem)"
+ break
+ fi
+ done
+fi
# ── Mount workspace: data disk at /workspace (persistent user data) ──
mkdir -p /workspace
@@ -236,6 +241,28 @@ for dir in proc sys dev dev/pts dev/shm tmp workspace run; do
mkdir -p "$MNT_DIR/$dir"
done
+# Inject host kernel modules (virtio_mem, vsock, overlay) into rootfs.
+# The Docker image has modules for the container kernel, but the guest runs
+# the host kernel — so we need the host's matching .ko files.
+GUEST_MODDIR="/opt/opensandbox/guest-modules"
+if [ -d "$GUEST_MODDIR" ] && ls "$GUEST_MODDIR"/*.ko >/dev/null 2>&1; then
+ # Detect guest kernel version from the kernel binary
+ GUEST_KVER=$(ls -d /lib/modules/*-generic 2>/dev/null | head -1 | xargs basename)
+ if [ -n "$GUEST_KVER" ]; then
+ DEST="$MNT_DIR/lib/modules/$GUEST_KVER/kernel/extra"
+ mkdir -p "$DEST"
+ cp "$GUEST_MODDIR"/*.ko "$DEST/"
+ # Run depmod so modprobe works inside the guest
+ depmod -b "$MNT_DIR" "$GUEST_KVER" 2>/dev/null || log "depmod failed (non-fatal)"
+ log "Injected guest modules into rootfs for kernel $GUEST_KVER:"
+ ls "$DEST/"
+ else
+ log "WARNING: Could not detect guest kernel version — guest modules not injected"
+ fi
+else
+ log "WARNING: No guest modules at $GUEST_MODDIR — virtio_mem may not load"
+fi
+
sync
umount "$MNT_DIR"
diff --git a/internal/qemu/manager.go b/internal/qemu/manager.go
index f436347f..d39e01fa 100644
--- a/internal/qemu/manager.go
+++ b/internal/qemu/manager.go
@@ -333,17 +333,17 @@ func (m *Manager) PrepareGoldenSnapshot() error {
// Load virtio_mem kernel module for memory scaling support.
// The module must be loaded before the golden snapshot so that restored
// VMs can use virtio-mem for dynamic memory add/remove.
- modCtx, modCancel := context.WithTimeout(context.Background(), 5*time.Second)
+ // Try modprobe first (handles signed modules + dependencies), fall back to insmod.
+ modCtx, modCancel := context.WithTimeout(context.Background(), 10*time.Second)
modResp, modErr := agentClient.Exec(modCtx, &pb.ExecRequest{
Command: "/bin/sh",
- Args: []string{"-c", "insmod /lib/modules/$(uname -r)/kernel/drivers/virtio/virtio_mem.ko 2>/dev/null; grep -q virtio_mem /proc/modules"},
+ Args: []string{"-c", "modprobe virtio_mem 2>/dev/null || insmod /lib/modules/$(uname -r)/kernel/drivers/virtio/virtio_mem.ko 2>/dev/null; grep -q virtio_mem /proc/modules"},
})
modCancel()
if modErr != nil || (modResp != nil && modResp.ExitCode != 0) {
- log.Printf("qemu: golden: WARNING: virtio_mem module not loaded (memory scaling may not work): err=%v", modErr)
- } else {
- log.Printf("qemu: golden: virtio_mem module loaded")
+ return fmt.Errorf("virtio_mem module failed to load (memory scaling will not work) — ensure the rootfs has kmod installed and virtio_mem.ko is present: %v", modErr)
}
+ log.Printf("qemu: golden: virtio_mem module loaded")
// Unmount /workspace and sync before snapshot — the golden migration state
// includes virtio-blk device state (ring buffers, pending I/O). If /workspace