create-image: use mtools to populate image

Use the `mtools` set of utilities to populate the image without the need
to run mount the image (requring sudo).
This commit is contained in:
Matthew Leach
2025-12-06 21:17:08 +00:00
committed by Matthew Leach
parent 76624b8be0
commit abd5ef39c2
2 changed files with 11 additions and 22 deletions

View File

@@ -66,10 +66,11 @@ x86) before running on bare metal.
## Building and Running
### Prerequisites
You will need QEMU for aarch64 emulation and dosfstools to create the virtual file system.
You will need QEMU for aarch64 emulation, dosfstools and mtools to create the
virtual file system.
```bash
sudo apt install qemu-system-aarch64 dosfstools
sudo apt install qemu-system-aarch64 dosfstools mtools
```
Additionally you will need a version of the [aarch64-none-elf](https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain) toolchain installed.
@@ -104,14 +105,12 @@ into the `build` directory.
Once that is done, you can create the image using the following command:
```bash
sudo ./scripts/create-image.sh
./scripts/create-image.sh
```
This will create an image file named `moss.img` in the root directory of the project,
format it as VFAT 32 and create the necessary files and directories for the kernel.
This script needs to run with sudo to mount the image through a loop device,
which is required to properly create the image for the kernel to work.
This will create an image file named `moss.img` in the root directory of the
project, format it as VFAT 32 and create the necessary files and directories for
the kernel.
### Running via QEMU

View File

@@ -5,23 +5,13 @@ base="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. && pwd )"
pushd "$base" &>/dev/null || exit 1
img="$base/moss.img"
mount="$base/build/mount"
mkdir -p "$mount"
dd if=/dev/zero of="$img" bs=1M count=128
mkfs.vfat -F 32 "$img"
if ! mountpoint -q "$mount"; then
mount -o loop "$img" "$mount"
fi
mmd -i "$img" ::/bin
mmd -i "$img" ::/dev
mkdir -p "$mount/bin"
mkdir -p "$mount/dev"
mcopy -i "$img" "$base/build/bin"/* "::/bin"
cp "$base/build/bin"/* "$mount/bin"
if mountpoint -q "$mount"; then
umount "$mount"
fi
popd &>/dev/null || exit 1