mkosi icon indicating copy to clipboard operation
mkosi copied to clipboard

BaseImage doesn't play well with build script

Open kapouer opened this issue 3 years ago • 4 comments

Hi,

using mkosi 13 (on debian/bookworm), I can't use BaseImage and mkosi.build together. I tried BaseImage without build script and it works, but as soon as I add a build script I get:

‣ Detaching namespace
‣ Setting up temporary workspace.
‣ Temporary workspace set up in /home/work/mydir/.mkosi-ut6cs_l6
‣ Running first (development) stage…
‣  Using /var/lib/machines/bookworm as the base image
‣   Mounting image…
‣   Setting up basic OS tree…
‣   (Cleaning up overlayfs)
‣    (Removing overlay whiteout files…)
‣   (Unmounting image)
Traceback (most recent call last):
  File "/usr/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/usr/lib/python3/dist-packages/mkosi/__main__.py", line 36, in <module>
    main()
  File "/usr/lib/python3/dist-packages/mkosi/__main__.py", line 27, in main
    run_verb(a)
  File "/usr/lib/python3/dist-packages/mkosi/__init__.py", line 8409, in run_verb
    manifest = build_stuff(args)
  File "/usr/lib/python3/dist-packages/mkosi/__init__.py", line 7764, in build_stuff
    image = build_image(args, root, do_run_build_script=True)
  File "/usr/lib/python3/dist-packages/mkosi/__init__.py", line 7491, in build_image
    prepare_tree(args, root, do_run_build_script, cached)
  File "/usr/lib/python3/dist-packages/mkosi/__init__.py", line 1852, in prepare_tree
    root_home(args, root).mkdir(mode=0o750)
  File "/usr/lib/python3.10/pathlib.py", line 1175, in mkdir
    self._accessor.mkdir(self, mode)
FileExistsError: [Errno 17] File exists: '/home/work/mydir/.mkosi-ut6cs_l6/root/root'

That I can fix, by adding exist_ok=True to mkdir parameters where appropriate. But the issue is deeper, as the overlay is unmounted right before the build script is called, apparently:

‣   Unmounting Package Cache
‣   Copying in build script…
‣   Copying in sources…
warning: impossible d'accéder à '/root/.config/git/ignore': Permission non accordée
‣   Copying in extra file trees…
‣   Mounting Package Cache
‣   Running postinstall script…
‣   Unmounting Package Cache
‣   Cleaning up overlayfs
‣    Removing overlay whiteout files…
‣   Unmounting image
‣  Running build script…
execv(/root/mkosi.build) failed: No such file or directory

kapouer avatar Jul 27 '22 13:07 kapouer

Yeah we should run the build script earlier to fix this.

DaanDeMeyer avatar Jul 27 '22 13:07 DaanDeMeyer

It's slightly unclear to me how you would except build scripts and --base-image to interact though. Could you explain a bit more about your usecase?

DaanDeMeyer avatar Jul 27 '22 13:07 DaanDeMeyer

BuildImage = (BaseImage + BuildOverlay) so the build script runs on BuildImage to fill DEST_DIR which is then installed into FinalImage = (BaseImage + FinalOverlay) ? The BuildOverlay, in this picture, (greatly) accelerates construction of the BuildImage - it isn't strictly needed for the final image.

kapouer avatar Jul 27 '22 13:07 kapouer

Maybe a solution is to use systemd-nspawn --overlay switch in run_build_script(), mirroring mount_overlay behavior ?

kapouer avatar Jul 27 '22 16:07 kapouer

This should work now on git main, please report back if it doesn't.

DaanDeMeyer avatar Apr 11 '23 18:04 DaanDeMeyer