mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
alpine: add script to automatically build state image using nodejs
This commit is contained in:
parent
e1182c08b8
commit
037afdc3d9
4 changed files with 61 additions and 2 deletions
|
|
@ -19,6 +19,7 @@ window.onload = function()
|
|||
autostart: true,
|
||||
bzimage_initrd_from_filesystem: true,
|
||||
cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable",
|
||||
//initial_state: { url: "../images/alpine-state.bin" },
|
||||
});
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ You can build a Alpine Linux 9p image using Docker:
|
|||
1. As needed, kernel flavor (`virt` is smaller than `lts`, but don't have networking) and set of additional packages (community repo is enabled by default) can be edited in `Dockerfile`
|
||||
2. Check and run `./build.sh` with started dockerd (podman works)
|
||||
3. Run local webserver (e.g. `make run`) and open `examples/alpine.html`
|
||||
4. (optional) Run `./build-state.js` and add `initial_state: { url: "../images/alpine-state.bin" }` to `alpine.html`
|
||||
|
|
|
|||
59
tools/docker/alpine/build-state.js
Executable file
59
tools/docker/alpine/build-state.js
Executable file
|
|
@ -0,0 +1,59 @@
|
|||
#!/usr/bin/env node
|
||||
"use strict";
|
||||
|
||||
console.log("Don't forget to run `make all` before running this script");
|
||||
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const V86 = require("./../../../build/libv86.js").V86;
|
||||
|
||||
const V86_ROOT = path.join(__dirname, "../../..");
|
||||
const OUTPUT_FILE = path.join(V86_ROOT, "images/alpine-state.bin");
|
||||
|
||||
var emulator = new V86({
|
||||
bios: { url: path.join(V86_ROOT, "bios/seabios.bin") },
|
||||
vga_bios: { url: path.join(V86_ROOT, "bios/vgabios.bin") },
|
||||
autostart: true,
|
||||
memory_size: 512 * 1024 * 1024,
|
||||
vga_memory_size: 8 * 1024 * 1024,
|
||||
network_relay_url: "<UNUSED>",
|
||||
bzimage_initrd_from_filesystem: true,
|
||||
cmdline: "rw root=host9p rootfstype=9p rootflags=trans=virtio,cache=loose modules=virtio_pci tsc=reliable init_on_free=on",
|
||||
filesystem: {
|
||||
baseurl: path.join(V86_ROOT, "images/alpine-rootfs-flat"),
|
||||
basefs: path.join(V86_ROOT, "images/alpine-fs.json"),
|
||||
},
|
||||
screen_dummy: true,
|
||||
});
|
||||
|
||||
console.log("Now booting, please stand by ...");
|
||||
|
||||
let serial_text = "";
|
||||
let booted = false;
|
||||
|
||||
emulator.add_listener("serial0-output-byte", function(byte)
|
||||
{
|
||||
const c = String.fromCharCode(byte);
|
||||
//process.stdout.write(c);
|
||||
|
||||
serial_text += c;
|
||||
|
||||
if(!booted && serial_text.endsWith("localhost:~# "))
|
||||
{
|
||||
booted = true;
|
||||
|
||||
emulator.serial0_send("sync;echo 3 >/proc/sys/vm/drop_caches\n");
|
||||
|
||||
setTimeout(async function ()
|
||||
{
|
||||
const s = await emulator.save_state();
|
||||
|
||||
fs.writeFile(OUTPUT_FILE, new Uint8Array(s), function(e)
|
||||
{
|
||||
if(e) throw e;
|
||||
console.log("Saved as " + OUTPUT_FILE);
|
||||
emulator.stop();
|
||||
});
|
||||
}, 10 * 1000);
|
||||
}
|
||||
});
|
||||
|
|
@ -27,5 +27,3 @@ mkdir -p "$OUT_ROOTFS_FLAT"
|
|||
../../../tools/copy-to-sha256.py "$OUT_ROOTFS_TAR" "$OUT_ROOTFS_FLAT"
|
||||
|
||||
echo "$OUT_ROOTFS_TAR", "$OUT_ROOTFS_FLAT" and "$OUT_FSJSON" created.
|
||||
|
||||
# TODO: auto-build state, add examples/alpine.html
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue