Command to write file in BFS image file

Is there any good way to automatically write file to BFS disk image by using script? I want to speedup kernel debugging cycle, building full disk image on each test is slow.

I don’t know if such command exists, but I created a small script (, hope that helps :).

Copy of source:


# Simple script that mounts specified BFS disk image file to temporary directory,
# copies specified file there, unmounts the image and removes temporary directory.
# Usage: cp2bfs my-file-to-copy my-test-disk.bfs


if [ -z "$BFSFILE" ] || [ ! -f "$BFSFILE" ] ; then
	echo "BFS image file not specified" >&2
	exit 1

cleanup () {
	if [ -z "$MOUNTDIR" ] || [ ! -d "$MOUNTDIR" ] ; then

	unmount "$MOUNTDIR" &>/dev/null || true
	rm -rf "$MOUNTDIR"

MOUNTDIR=$(mktemp -d)
trap 'cleanup' EXIT INT TERM

mount "$BFSFILE" "$MOUNTDIR" || (echo "Could not mount '$BFSFILE', are you sure it's valid?" >&2 && exit 1)
cp -a "$FROM" "$MOUNTDIR"

Just write it as text file, mark as executable and it should work for copying single file or directory.

There is bfs_shell tool

I’m with @ahwayakchih. I’ve always just mounted the file as at a mount point, then you can do whatever you need. In the past, I’ve done this quite a lot of system building with BeOS and also BeIA (though BeIA’s CFS it is a slightly different file system, the principal is the same.) Building a new image each time is quite inefficient as a OS builder.

1 Like

Mounting image seems to be dangerous on current Haiku. On unmount it often claim that “Device/File/Resource busy” and cause KDL (#12847).

Okay - that’s not ideal. Mounting an image file should be the answer. It was always pretty stable under R5.03. I’ve even done it recently when I was messing about with the BeIA SDK in R5 under an emulator.

I got KDL right now. It have quite high probability to occur.


@X512 yeah, i even posted bug reports there too :). But if you’re copying just a single file, it should be OK (i tested the script today, on a months old nightly). I think the problem happens when multiple operations are done on the image without a break or maybe from multiple threads? Or may operations in longer period of time. For me it was usually some compilation, git statuses, commits, etc… Once it happens, reboot is necessary.

Anyway, just backup image before, so even if operation fails, you still happen both BFS image and file to copy intact.

Oh, that’s too bad :(.

Running mounting and data copy from a script also cause KDL.

I managed to extract packages (so package_fs is not used, hopefully this is still supported) and make kernel copy script using bfs_shell. Now test cycle is much faster.

1 Like

My first idea is the “jam update-image” feature, maybe I misunderstood what you’d like to do.

I want to update only selected files (kernel_riscv64 etc) to reduce test cycle time.

“jam -q update-image kernel” handles this usecase IMO.