Full OS
Run bash on a custom disk image
This tutorial will guide you through creating a custom filesystem from scratch and using it with CheerpX.
1. Create an Ext2 image
We will create an Ext2 image, which will serve as the root filesystem for CheerpX.
To ensure consistency in preparing the image contents, we will use a Dockerfile, you can edit the Dockerfile to add custom packages or change the base to the distro of your choosing. Itβs important to select the i386
architecture, since CheerpX does not currently support 64-bit executables.
Create a container out of your Dockerfile:
Copy the filesystem from the container into a local directory:
Create an ext2 image from the specified directory:
2. Load CheerpX from your index.html
Loading CheerpX is very simple. Create a new file called index.html
and populate it with the following HTML code.
3. Setup a Web server
We recommend always choosing nginx
as your Web server when using with CheerpX.
This basic configuration should get you up and running. Please note that CheerpX requires cross-origin isolation, which is enabled via the Cross-Origin-Opener-Policy
and Cross-Origin-Embedder-Policy
headers. For more information see the dedicated Nginx guide.
Run nginx with the following command:
You can now see your page at http://localhost:8080
Make sure the cheerpXImage.ext2
and the index.html
files are both in the same directory where nginx
was started.
4. Create a device for the filesystem
Add a new <script>
tag with the type="module"
. Having the script as a module is convenient to use top-level awaits.
Create a HttpBytesDevice
from the just created Ext2 image. OverlayDevice
makes it possible to make changes to the image, that are overlayed and saved in an IndexedDB persisted by the browser.
For more information on HttpBytesDevice
and OverlayDevice
, see our Files and filesystem guide.
5. Create a CheerpX instance
In the same script tag, pass the overlayDevice
as a new mount point to the Cheerpx.Linux.create
method. This option will initialize CheerpX with the newly created device mounted as /
.
To learn more about Cheerpx.Linux.create
, see the CheerpX.Linux.create reference.
6. Attach a console
Create a console element for the output of your program.
And configure CheerpX to use it by adding this snippet at the end of the script.
Learn more about the console setup in the setConsole reference.
7. Execute a shell
Use the cx.run
API to execute the bash
shell. This setup is very similar to what we use for WebVM!
Learn more about cx.run
in the CheerpX.Linux.run reference.