container2wasm icon indicating copy to clipboard operation
container2wasm copied to clipboard

Adding arbitrary files not possible when compiled with Emscripten.

Open pateljoel opened this issue 10 months ago • 4 comments

I followed this guide in attempting to add some files into the wasm container and it doesn't seem to work in this example here: https://github.com/ktock/qemu-wasm/tree/master/examples/virtfs when compiling the container with emscripten.

After building the container and adding the -virtfs flag, I always get this error in the emulator when running the container with the flag:

this.program: -virtfs local,path=/share,mount_tag=share0,security_model=passthrough,id=share0: cannot initialize fsdev 'share0': failed to open '/share': No such file or directory

Even when using the modules.js to attempt to modify the existing /pack folder to write a file into that patch as shown in the example, I don't see the files in the emulator when I write a file to the directory.

Is there a way to add files to the container when compiled with Emscripten so that they appear in the emulator?

pateljoel avatar Apr 13 '25 21:04 pateljoel

Is there a solution to this? @ktock

pateljoel avatar Apr 14 '25 18:04 pateljoel

@pateljoel

it doesn't seem to work in this example here: https://github.com/ktock/qemu-wasm/tree/master/examples/virtfs

I've just tried this step but coudn't reproduce the error. Can you provide steps to reproduce this error so that I can debug the problem?

ktock avatar Apr 16 '25 12:04 ktock

@ktock Yeah sure, I used these following steps below, but managed to get past the initial error but still could not access the file system / mount or write a new file before booting the VM:

  1. I followed this guide to build for emscripten: https://github.com/container2wasm/container2wasm/tree/main/examples/emscripten#step-1-converting-an-image-to-wasm

  2. After it was built, I then modified the module.js file it created to create a mounted directory before booting the container as shown in: https://github.com/ktock/qemu-wasm/tree/master/examples/virtfs

I added this line into the Module['arguments'] array in module.js

Module['arguments'] = [
     ....
    '-virtfs', 'local,path=/share,mount_tag=share0,security_model=passthrough,id=share0',
];
  1. My index.html adds this code to write to the share folder:
Module['preRun'].push((mod) => {
            mod.FS.mkdir('/share');
            mod.FS.writeFile('/share/file', 'test');
  });
  1. Finally I refreshed and booted the VM without the -incoming flag and it booted to the shell, but still could not access the mounted path even after attempting to mount the path.

Here is the log of this here: https://gist.github.com/pateljoel/bd27a4f73422a301b3bdf2d8944ee493

pateljoel avatar Apr 16 '25 20:04 pateljoel

@ktock Any luck reproducing this issue with these steps?

pateljoel avatar Apr 22 '25 12:04 pateljoel