Closed diegonehab closed 5 months ago
We can get the tools version from the apt database of a running machine with:
$ apt show machine-emulator-tools | awk '/Version/ {print $2}'
0.15.0
Does this work from the outside? I think for @tuler it would be best if it did. This is because you may not be able to boot a machine at all with a given rootfs.
I'm sure the contents are there somewhere, but may be compressed in the apt
database.
The upside of this method, or something equivalent like consulting apt databases directly, is that we can check for other packages as well, such as busybox. This gives an idea if the image was setup properly.
The idea is to make this easy on the outside. I think just adding a file there would be fine, right?
A file with version works but is non standard, breaks the single source of truth concept and won't work for other packages such as busybox.
The incantation to fetch it from the debian database is not that bad, check it out.
T=$(mktemp)
e2cp rootfs.ext2:/var/lib/apt/lists/deb.debian.org_debian_dists_bookworm_main_binary-amd64_Packages.lz4 $T
lz4 $T - |\
sed -n '/Package: machine-emulator-tools/,/^$/p' |\
awk '/Version:/ {print $2}'
rm $T
I think doesn't hurt to have a simple file somewhere with the tools version, to make easy to inspect from outside. Also more fail proof for the day we start having tools available in distributions that aren't .deb based (Alpine for example).
I think doesn't hurt to have a simple file somewhere with the tools version, to make easy to inspect from outside. Also more fail proof for the day we start having tools available in distributions that aren't .deb based (Alpine for example).
We'll have a lot of other changes when that happens. But ok, it is not a big deal.
I understand it is possible to squeeze the information out of the rootfs. :) But I can't go back to our clients with this as a solution. Since we will need to release a new version of tools with the new rollup-http-server soon, I'd like for it to include a file at a standard place with a standard name and containing the version. Pretty please?
To be clear, this is our fig leaf so our clients don't come up with something a lot more creative. It will allow the cartesi cli to diagnose a very common compatibility problem between the cartesi machine and the rootfs and print a nice error message rather than a kernel panic of some such.
@tuler Can you give an OK if this commit solves the issue for you? https://github.com/cartesi/machine-emulator-tools/pull/57/commits/c0b4a68d578b030ed8696d66844b1769d9eb3419
To retrieve the tools version from a ext2
file, do the following (mktemp is optional):
$ T=$(mktemp)
$ e2cp rootfs.ext2:/usr/share/machine-emulator-tools/package.json $T
$ jq '.["version"]' < $T
"0.15.0"
$ rm $T
Context
It seems as though many users have trouble following upgrade instructions and end up with a version of tools installed that is not compatible with either the emulator or the kernel.
It would be much better if there was a way for us to check if the tools are installed in a rootfs and to check what version was installed, both from inside the machine and from the outside.
Possible solutions
The trivial solution to this problem is to create a file containing the version and install it along with the other files in tools. That way, you could simply, say,
cat
the contents of/etc/cartesi/tools-version
or some such. Even from the outside, you could usee2cp rootfs.ext2:/etc/cartesi/tools-version -
, or evene2cp template/0080000000000000-6400000.bin:/etc/cartesi/tools-version -
iftemplate
is a stored machine template and0080000000000000-6400000.bin
is the memory range where it keeps the root filesystem.