Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 67 additions & 30 deletions .ci/boot-linux-prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

check_platform

VBLK_IMG=build/disk.img
VBLK_IMGS=(
build/disk_ext4.img
)
# FIXME: mkfs.simplefs is not compilable on macOS, thus running the
# simplefs cases on Linux runner for now
Comment on lines +12 to +13
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should track this issue.

Copy link
Collaborator Author

@ChinYikMing ChinYikMing Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should track this issue.

Describe the issue in the aaa9c44 commit message and create a issue in simplefs.

if [[ "${OS_TYPE}" == "Linux" ]]; then
VBLK_IMGS+=(build/disk_simplefs.img)
fi

which dd > /dev/null 2>&1 || {
echo "Error: dd not found"
exit 1
Expand All @@ -25,48 +33,77 @@ ACTION=$1

case "$ACTION" in
setup)
# Setup a disk image
dd if=/dev/zero of=${VBLK_IMG} bs=4M count=32
# Clone simplefs to use mkfs.simplefs util and create simplefs disk image
git clone https://github.com/sysprog21/simplefs.git -b rel2025.0 --depth 1

# Setup a /dev/ block device with ${VBLK_IMG} to test guestOS access to hostOS /dev/ block device
case "${OS_TYPE}" in
Linux)
mkfs.ext4 ${VBLK_IMG}
BLK_DEV=$(losetup -f)
losetup ${BLK_DEV} ${VBLK_IMG}
;;
Darwin)
$(brew --prefix e2fsprogs)/sbin/mkfs.ext4 ${VBLK_IMG}
BLK_DEV=$(hdiutil attach -nomount ${VBLK_IMG})
;;
esac
# Setup disk images
for disk_img in "${VBLK_IMGS[@]}"; do
case "${OS_TYPE}" in
Linux)
# Setup a /dev/ block device with ext4 fs to test guestOS access to hostOS /dev/ block device
if [[ "${disk_img}" =~ ext4 ]]; then
dd if=/dev/zero of=${disk_img} bs=4M count=32
mkfs.ext4 ${disk_img}
else
mkdir -p simplefs/build
make IMAGE=${disk_img} ${disk_img} -C simplefs
mv simplefs/${disk_img} ./build
fi
BLK_DEV=$(losetup -f)
losetup ${BLK_DEV} ${disk_img}
;;
Darwin)
# Setup a /dev/ block device with ext4 fs to test guestOS access to hostOS /dev/ block device
dd if=/dev/zero of=${disk_img} bs=4M count=32
$(brew --prefix e2fsprogs)/sbin/mkfs.ext4 ${disk_img}
BLK_DEV=$(hdiutil attach -nomount ${disk_img})
;;
esac

# On Linux, ${VBLK_IMG} will be created by root and owned by root:root.
# Even if "others" have read and write (rw) permissions, accessing the file for certain operations may
# still require elevated privileges (e.g., setuid).
# To simplify this, we change the ownership to a non-root user.
# Use this with caution—changing ownership to runner:runner is specific to the GitHub CI environment.
chown runner: ${VBLK_IMG}
# Add other's rw permission to the disk image and device, so non-superuser can rw them
chmod o+r,o+w ${VBLK_IMG}
chmod o+r,o+w ${BLK_DEV}
# On Linux, ${disk_img} will be created by root and owned by root:root.
# Even if "others" have read and write (rw) permissions, accessing the file for certain operations may
# still require elevated privileges (e.g., setuid).
# To simplify this, we change the ownership to a non-root user.
# Use this with caution—changing ownership to runner:runner is specific to the GitHub CI environment.
chown runner: ${disk_img}
# Add other's rw permission to the disk image and device, so non-superuser can rw them
chmod o+r,o+w ${disk_img}
chmod o+r,o+w ${BLK_DEV}

# Export ${BLK_DEV} to a tmp file. Then, source to "$GITHUB_ENV" in job step.
echo "export BLK_DEV=${BLK_DEV}" > "${TMP_FILE}"
# Export ${BLK_DEV} to a tmp file. Then, source to "$GITHUB_ENV" in job step.
if [[ "${disk_img}" =~ ext4 ]]; then
echo "export BLK_DEV_EXT4=${BLK_DEV}" >> "${TMP_FILE}"
else
echo "export BLK_DEV_SIMPLEFS=${BLK_DEV}" >> "${TMP_FILE}"
fi
done

# Put simplefs.ko into ext4 fs
mkdir -p mnt
mount ${VBLK_IMGS[0]} mnt
cp build/linux-image/simplefs.ko mnt
umount mnt
rm -rf mnt
;;
cleanup)
# Remove simplefs repo
rm -rf simplefs

# Detach the /dev/loopx(Linux) or /dev/diskx(Darwin)
case "${OS_TYPE}" in
Linux)
losetup -d ${BLK_DEV}
losetup -d ${BLK_DEV_EXT4}
losetup -d ${BLK_DEV_SIMPLEFS}
;;
Darwin)
hdiutil detach ${BLK_DEV}
hdiutil detach ${BLK_DEV_EXT4}
;;
esac

# delete disk image
rm -f ${VBLK_IMG}
# delete disk images
for disk_img in "${VBLK_IMGS[@]}"; do
rm -f ${disk_img}
done

# delete tmp file
rm "${TMP_FILE}"
Expand Down
Loading
Loading